You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LFOData.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * ====================================================================
  3. * Licensed to the Apache Software Foundation (ASF) under one or more
  4. * contributor license agreements. See the NOTICE file distributed with
  5. * this work for additional information regarding copyright ownership.
  6. * The ASF licenses this file to You under the Apache License, Version 2.0
  7. * (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. * ====================================================================
  18. */
  19. package org.apache.poi.hwpf.model;
  20. import java.io.ByteArrayOutputStream;
  21. import java.io.IOException;
  22. import java.util.Arrays;
  23. import org.apache.poi.util.Internal;
  24. import org.apache.poi.util.LittleEndian;
  25. import org.apache.poi.util.LittleEndianConsts;
  26. /**
  27. * The LFOData structure contains the Main Document CP of the corresponding LFO,
  28. * as well as an array of LVL override data.
  29. */
  30. @Internal
  31. public class LFOData
  32. {
  33. private int _cp;
  34. private ListFormatOverrideLevel[] _rgLfoLvl;
  35. public LFOData()
  36. {
  37. _cp = 0;
  38. _rgLfoLvl = new ListFormatOverrideLevel[0];
  39. }
  40. LFOData( byte[] buf, int startOffset, int cLfolvl ) {
  41. if (cLfolvl < 0) {
  42. throw new IllegalArgumentException("Cannot create LFOData with negative count");
  43. }
  44. int offset = startOffset;
  45. _cp = LittleEndian.getInt( buf, offset );
  46. offset += LittleEndianConsts.INT_SIZE;
  47. _rgLfoLvl = new ListFormatOverrideLevel[cLfolvl];
  48. for ( int x = 0; x < cLfolvl; x++ )
  49. {
  50. _rgLfoLvl[x] = new ListFormatOverrideLevel( buf, offset );
  51. offset += _rgLfoLvl[x].getSizeInBytes();
  52. }
  53. }
  54. public int getCp()
  55. {
  56. return _cp;
  57. }
  58. public ListFormatOverrideLevel[] getRgLfoLvl()
  59. {
  60. return _rgLfoLvl;
  61. }
  62. public int getSizeInBytes()
  63. {
  64. int result = 0;
  65. result += LittleEndianConsts.INT_SIZE;
  66. for ( ListFormatOverrideLevel lfolvl : _rgLfoLvl )
  67. result += lfolvl.getSizeInBytes();
  68. return result;
  69. }
  70. void writeTo( ByteArrayOutputStream tableStream ) throws IOException
  71. {
  72. LittleEndian.putInt( _cp, tableStream );
  73. for ( ListFormatOverrideLevel lfolvl : _rgLfoLvl )
  74. {
  75. tableStream.write( lfolvl.toByteArray() );
  76. }
  77. }
  78. @Override
  79. public boolean equals(Object o) {
  80. if (this == o) return true;
  81. if (o == null || getClass() != o.getClass()) return false;
  82. LFOData lfoData = (LFOData) o;
  83. if (_cp != lfoData._cp) return false;
  84. // Probably incorrect - comparing Object[] arrays with Arrays.equals
  85. return Arrays.equals(_rgLfoLvl, lfoData._rgLfoLvl);
  86. }
  87. @Override
  88. public int hashCode() {
  89. return Arrays.deepHashCode(_rgLfoLvl);
  90. }
  91. }