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.

DrawingRecord.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.LittleEndianOutput;
  20. public final class DrawingRecord extends StandardRecord {
  21. public static final short sid = 0x00EC;
  22. private static final byte[] EMPTY_BYTE_ARRAY = {};
  23. private byte[] recordData;
  24. private byte[] contd;
  25. public DrawingRecord() {
  26. recordData = EMPTY_BYTE_ARRAY;
  27. }
  28. public DrawingRecord(DrawingRecord other) {
  29. super(other);
  30. recordData = (other.recordData == null) ? null : other.recordData.clone();
  31. // TODO - this code probably never copies a contd array ...
  32. contd = (other.contd == null) ? null : other.contd.clone();
  33. }
  34. public DrawingRecord(RecordInputStream in) {
  35. recordData = in.readRemainder();
  36. }
  37. public DrawingRecord(byte[] data) {
  38. recordData = data.clone();
  39. }
  40. /**
  41. * @deprecated POI 3.9
  42. */
  43. @Deprecated
  44. void processContinueRecord(byte[] record) {
  45. //don't merge continue record with the drawing record, it must be serialized separately
  46. contd = record;
  47. }
  48. public void serialize(LittleEndianOutput out) {
  49. out.write(recordData);
  50. }
  51. protected int getDataSize() {
  52. return recordData.length;
  53. }
  54. public short getSid() {
  55. return sid;
  56. }
  57. public byte[] getRecordData(){
  58. return recordData;
  59. }
  60. public void setData(byte[] thedata) {
  61. if (thedata == null) {
  62. throw new IllegalArgumentException("data must not be null");
  63. }
  64. recordData = thedata;
  65. }
  66. /**
  67. * Cloning of drawing records must be executed through HSSFPatriarch, because all id's must be changed
  68. * @return cloned drawing records
  69. */
  70. @Override
  71. public DrawingRecord copy() {
  72. return new DrawingRecord(this);
  73. }
  74. @Override
  75. public HSSFRecordTypes getGenericRecordType() {
  76. return HSSFRecordTypes.DRAWING;
  77. }
  78. @Override
  79. public Map<String, Supplier<?>> getGenericProperties() {
  80. return GenericRecordUtil.getGenericProperties(
  81. "recordData", this::getRecordData,
  82. "contd", () -> contd
  83. );
  84. }
  85. }