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.

NoteStructureSubRecord.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.hssf.record;
  16. import org.apache.poi.util.HexDump;
  17. import org.apache.poi.util.LittleEndianInput;
  18. import org.apache.poi.util.LittleEndianOutput;
  19. /**
  20. * ftNts (0x000D)<p/>
  21. * Represents a NoteStructure sub record.
  22. *
  23. * <p>
  24. * The docs say nothing about it. The length of this record is always 26 bytes.
  25. * </p>
  26. *
  27. * @author Yegor Kozlov
  28. */
  29. public final class NoteStructureSubRecord extends SubRecord {
  30. public final static short sid = 0x0D;
  31. private static final int ENCODED_SIZE = 22;
  32. private byte[] reserved;
  33. /**
  34. * Construct a new <code>NoteStructureSubRecord</code> and
  35. * fill its data with the default values
  36. */
  37. public NoteStructureSubRecord()
  38. {
  39. //all we know is that the the length of <code>NoteStructureSubRecord</code> is always 22 bytes
  40. reserved = new byte[ENCODED_SIZE];
  41. }
  42. /**
  43. * Read the record data from the supplied <code>RecordInputStream</code>
  44. */
  45. public NoteStructureSubRecord(LittleEndianInput in, int size) {
  46. if (size != ENCODED_SIZE) {
  47. throw new RecordFormatException("Unexpected size (" + size + ")");
  48. }
  49. //just grab the raw data
  50. byte[] buf = new byte[size];
  51. in.readFully(buf);
  52. reserved = buf;
  53. }
  54. /**
  55. * Convert this record to string.
  56. * Used by BiffViewer and other utilities.
  57. */
  58. public String toString()
  59. {
  60. StringBuffer buffer = new StringBuffer();
  61. buffer.append("[ftNts ]").append("\n");
  62. buffer.append(" size = ").append(getDataSize()).append("\n");
  63. buffer.append(" reserved = ").append(HexDump.toHex(reserved)).append("\n");
  64. buffer.append("[/ftNts ]").append("\n");
  65. return buffer.toString();
  66. }
  67. /**
  68. * Serialize the record data into the supplied array of bytes
  69. *
  70. * @param out the stream to serialize into
  71. */
  72. public void serialize(LittleEndianOutput out) {
  73. out.writeShort(sid);
  74. out.writeShort(reserved.length);
  75. out.write(reserved);
  76. }
  77. protected int getDataSize() {
  78. return reserved.length;
  79. }
  80. /**
  81. * @return id of this record.
  82. */
  83. public short getSid()
  84. {
  85. return sid;
  86. }
  87. public Object clone() {
  88. NoteStructureSubRecord rec = new NoteStructureSubRecord();
  89. byte[] recdata = new byte[reserved.length];
  90. System.arraycopy(reserved, 0, recdata, 0, recdata.length);
  91. rec.reserved = recdata;
  92. return rec;
  93. }
  94. }