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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 java.util.Map;
  17. import java.util.function.Supplier;
  18. import org.apache.poi.util.GenericRecordUtil;
  19. import org.apache.poi.util.IOUtils;
  20. import org.apache.poi.util.LittleEndianInput;
  21. import org.apache.poi.util.LittleEndianOutput;
  22. import org.apache.poi.util.RecordFormatException;
  23. /**
  24. * ftNts (0x000D)<p>
  25. * Represents a NoteStructure sub record.<p>
  26. *
  27. * The docs say nothing about it. The length of this record is always 26 bytes.
  28. */
  29. public final class NoteStructureSubRecord extends SubRecord {
  30. public static final short sid = 0x0D;
  31. private static final int ENCODED_SIZE = 22;
  32. private final byte[] reserved;
  33. /**
  34. * Construct a new <code>NoteStructureSubRecord</code> and
  35. * fill its data with the default values
  36. */
  37. public NoteStructureSubRecord() {
  38. //all we know is that the the length of <code>NoteStructureSubRecord</code> is always 22 bytes
  39. reserved = new byte[ENCODED_SIZE];
  40. }
  41. public NoteStructureSubRecord(NoteStructureSubRecord other) {
  42. super(other);
  43. reserved = other.reserved.clone();
  44. }
  45. /**
  46. * Read the record data from the supplied <code>RecordInputStream</code>
  47. *
  48. * @param in the input to read from
  49. * @param size the provided size - must be 22
  50. */
  51. public NoteStructureSubRecord(LittleEndianInput in, int size) {
  52. this(in,size,-1);
  53. }
  54. public NoteStructureSubRecord(LittleEndianInput in, int size, int cmoOt) {
  55. if (size != ENCODED_SIZE) {
  56. throw new RecordFormatException("Unexpected size (" + size + ")");
  57. }
  58. //just grab the raw data
  59. byte[] buf = IOUtils.safelyAllocate(size, ENCODED_SIZE);
  60. in.readFully(buf);
  61. reserved = buf;
  62. }
  63. /**
  64. * Serialize the record data into the supplied array of bytes
  65. *
  66. * @param out the stream to serialize into
  67. */
  68. @Override
  69. public void serialize(LittleEndianOutput out) {
  70. out.writeShort(sid);
  71. out.writeShort(reserved.length);
  72. out.write(reserved);
  73. }
  74. @Override
  75. protected int getDataSize() {
  76. return reserved.length;
  77. }
  78. /**
  79. * @return id of this record.
  80. */
  81. public short getSid()
  82. {
  83. return sid;
  84. }
  85. @Override
  86. public NoteStructureSubRecord copy() {
  87. return new NoteStructureSubRecord(this);
  88. }
  89. @Override
  90. public SubRecordTypes getGenericRecordType() {
  91. return SubRecordTypes.NOTE_STRUCTURE;
  92. }
  93. @Override
  94. public Map<String, Supplier<?>> getGenericProperties() {
  95. return GenericRecordUtil.getGenericProperties(
  96. "reserved", () -> reserved
  97. );
  98. }
  99. }