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.

SectionDescriptor.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hwpf.model;
  16. import org.apache.poi.common.Duplicatable;
  17. import org.apache.poi.util.Internal;
  18. import org.apache.poi.util.LittleEndian;
  19. import org.apache.poi.util.LittleEndianConsts;
  20. /**
  21. * Section Descriptor (SED)
  22. *
  23. * See page 186 for details.
  24. */
  25. @Internal
  26. public final class SectionDescriptor implements Duplicatable {
  27. /**
  28. * "Used internally by Word"
  29. */
  30. private short fn;
  31. /**
  32. * "File offset in main stream to beginning of SEPX stored for section. If
  33. * sed.fcSepx==0xFFFFFFFF, the section properties for the section are equal
  34. * to the standard SEP (see SEP definition)."
  35. */
  36. private int fcSepx;
  37. /**
  38. * "Used internally by Word"
  39. */
  40. private short fnMpr;
  41. /**
  42. * "Points to offset in FC space of main stream where the Macintosh Print
  43. * Record for a document created on a Macintosh will be stored"
  44. */
  45. private int fcMpr;
  46. public SectionDescriptor() {}
  47. public SectionDescriptor(SectionDescriptor other) {
  48. fn = other.fn;
  49. fcSepx = other.fcSepx;
  50. fnMpr = other.fnMpr;
  51. fcMpr = other.fcMpr;
  52. }
  53. public SectionDescriptor(byte[] buf, int offset)
  54. {
  55. fn = LittleEndian.getShort(buf, offset);
  56. offset += LittleEndianConsts.SHORT_SIZE;
  57. fcSepx = LittleEndian.getInt(buf, offset);
  58. offset += LittleEndianConsts.INT_SIZE;
  59. fnMpr = LittleEndian.getShort(buf, offset);
  60. offset += LittleEndianConsts.SHORT_SIZE;
  61. fcMpr = LittleEndian.getInt(buf, offset);
  62. }
  63. public int getFc()
  64. {
  65. return fcSepx;
  66. }
  67. public void setFc(int fc)
  68. {
  69. this.fcSepx = fc;
  70. }
  71. @Override
  72. public boolean equals(Object o)
  73. {
  74. if (!(o instanceof SectionDescriptor)) return false;
  75. SectionDescriptor sed = (SectionDescriptor)o;
  76. return sed.fn == fn && sed.fnMpr == fnMpr;
  77. }
  78. @Override
  79. public int hashCode() {
  80. assert false : "hashCode not designed";
  81. return 42; // any arbitrary constant will do
  82. }
  83. public byte[] toByteArray()
  84. {
  85. int offset = 0;
  86. byte[] buf = new byte[12];
  87. LittleEndian.putShort(buf, offset, fn);
  88. offset += LittleEndianConsts.SHORT_SIZE;
  89. LittleEndian.putInt(buf, offset, fcSepx);
  90. offset += LittleEndianConsts.INT_SIZE;
  91. LittleEndian.putShort(buf, offset, fnMpr);
  92. offset += LittleEndianConsts.SHORT_SIZE;
  93. LittleEndian.putInt(buf, offset, fcMpr);
  94. return buf;
  95. }
  96. @Override
  97. public String toString()
  98. {
  99. return "[SED] (fn: " + fn + "; fcSepx: " + fcSepx + "; fnMpr: " + fnMpr
  100. + "; fcMpr: " + fcMpr + ")";
  101. }
  102. @Override
  103. public SectionDescriptor copy() {
  104. return new SectionDescriptor(this);
  105. }
  106. }