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.

FtCblsSubRecord.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. * This structure appears as part of an Obj record that represents a checkbox or radio button.
  25. */
  26. public final class FtCblsSubRecord extends SubRecord {
  27. public static final short sid = 0x0C;
  28. private static final int ENCODED_SIZE = 20;
  29. private final byte[] reserved;
  30. /**
  31. * Construct a new <code>FtCblsSubRecord</code> and
  32. * fill its data with the default values
  33. */
  34. public FtCblsSubRecord() {
  35. reserved = new byte[ENCODED_SIZE];
  36. }
  37. public FtCblsSubRecord(FtCblsSubRecord other) {
  38. super(other);
  39. reserved = other.reserved.clone();
  40. }
  41. public FtCblsSubRecord(LittleEndianInput in, int size) {
  42. this(in,size,-1);
  43. }
  44. FtCblsSubRecord(LittleEndianInput in, int size, int cmoOt) {
  45. if (size != ENCODED_SIZE) {
  46. throw new RecordFormatException("Unexpected size (" + size + ")");
  47. }
  48. //just grab the raw data
  49. byte[] buf = IOUtils.safelyAllocate(size, ENCODED_SIZE);
  50. in.readFully(buf);
  51. reserved = buf;
  52. }
  53. /**
  54. * Serialize the record data into the supplied array of bytes
  55. *
  56. * @param out the stream to serialize into
  57. */
  58. public void serialize(LittleEndianOutput out) {
  59. out.writeShort(sid);
  60. out.writeShort(reserved.length);
  61. out.write(reserved);
  62. }
  63. protected int getDataSize() {
  64. return reserved.length;
  65. }
  66. /**
  67. * @return id of this record.
  68. */
  69. public short getSid()
  70. {
  71. return sid;
  72. }
  73. @Override
  74. public FtCblsSubRecord copy() {
  75. return new FtCblsSubRecord(this);
  76. }
  77. @Override
  78. public SubRecordTypes getGenericRecordType() {
  79. return SubRecordTypes.FT_CBLS;
  80. }
  81. @Override
  82. public Map<String, Supplier<?>> getGenericProperties() {
  83. return GenericRecordUtil.getGenericProperties("reserved", () -> reserved);
  84. }
  85. }