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.

ExObjRefAtom.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.hslf.record;
  16. import java.io.IOException;
  17. import java.io.OutputStream;
  18. import java.util.Map;
  19. import java.util.function.Supplier;
  20. import org.apache.poi.util.GenericRecordUtil;
  21. import org.apache.poi.util.LittleEndian;
  22. /**
  23. * ExObjRefAtom (3009).
  24. * <p>
  25. * An atom record that specifies a reference to an external object.
  26. * </p>
  27. */
  28. public final class ExObjRefAtom extends RecordAtom {
  29. private byte[] _header;
  30. /**
  31. * A 4-byte unsigned integer that specifies a reference to an external object.
  32. * It MUST be equal to the value of the exObjId field of an ExMediaAtom record
  33. * or the value of the exObjId field of an ExOleObjAtom record.
  34. */
  35. private int exObjIdRef;
  36. /**
  37. * Create a new instance of <code>ExObjRefAtom</code>
  38. */
  39. public ExObjRefAtom() {
  40. _header = new byte[8];
  41. LittleEndian.putUShort(_header, 0, 0);
  42. LittleEndian.putUShort(_header, 2, (int)getRecordType());
  43. LittleEndian.putInt(_header, 4, 4);
  44. exObjIdRef = 0;
  45. }
  46. /**
  47. * Build an instance of <code>ExObjRefAtom</code> from on-disk data
  48. *
  49. * @param source the source data as a byte array.
  50. * @param start the start offset into the byte array.
  51. * @param len the length of the slice in the byte array.
  52. */
  53. protected ExObjRefAtom(byte[] source, int start, int len) {
  54. _header = new byte[8];
  55. int offset = start;
  56. System.arraycopy(source,start,_header,0,8);
  57. offset += _header.length;
  58. exObjIdRef = (int)LittleEndian.getUInt(source, offset);
  59. }
  60. /**
  61. * @return type of this record {@link RecordTypes#ExObjRefAtom}.
  62. */
  63. public long getRecordType() {
  64. return RecordTypes.ExObjRefAtom.typeID;
  65. }
  66. public int getExObjIdRef(){
  67. return exObjIdRef;
  68. }
  69. public void setExObjIdRef(int id){
  70. exObjIdRef = id;
  71. }
  72. /**
  73. * Write the contents of the record back, so it can be written
  74. * to disk
  75. */
  76. public void writeOut(OutputStream out) throws IOException {
  77. out.write(_header);
  78. byte[] recdata = new byte[4];
  79. LittleEndian.putUInt(recdata, 0, exObjIdRef);
  80. out.write(recdata);
  81. }
  82. @Override
  83. public Map<String, Supplier<?>> getGenericProperties() {
  84. return GenericRecordUtil.getGenericProperties("exObjIdRef", this::getExObjIdRef);
  85. }
  86. }