PageRenderTime 133ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/record/UnknownRecord.java

http://github.com/openmicroscopy/bioformats
Java | 177 lines | 76 code | 26 blank | 75 comment | 5 complexity | 119a208434da2d9a909b57a9b11d84db MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. package loci.poi.hssf.record;
  38. import loci.poi.util.LittleEndian;
  39. /**
  40. * Title: Unknown Record (for debugging)<P>
  41. * Description: Unknown record just tells you the sid so you can figure out
  42. * what records you are missing. Also helps us read/modify sheets we
  43. * don't know all the records to. (HSSF leaves these alone!) <P>
  44. * Company: SuperLink Software, Inc.<P>
  45. * @author Andrew C. Oliver (acoliver at apache dot org)
  46. * @author Jason Height (jheight at chariot dot net dot au)
  47. * @author Glen Stampoultzis (glens at apache.org)
  48. */
  49. public class UnknownRecord
  50. extends Record
  51. {
  52. private short sid = 0;
  53. private byte[] thedata = null;
  54. public UnknownRecord()
  55. {
  56. }
  57. /**
  58. * @param id id of the record -not validated, just stored for serialization
  59. * @param data the data
  60. */
  61. public UnknownRecord(short id, byte[] data)
  62. {
  63. this.sid = id;
  64. this.thedata = data;
  65. }
  66. /**
  67. * construct an unknown record. No fields are interperated and the record will
  68. * be serialized in its original form more or less
  69. * @param in the RecordInputstream to read the record from
  70. */
  71. public UnknownRecord(RecordInputStream in)
  72. {
  73. sid = in.getSid();
  74. thedata = in.readRemainder();
  75. //System.out.println("UnknownRecord: 0x"+Integer.toHexString(sid));
  76. }
  77. /**
  78. * spit the record out AS IS. no interpretation or identification
  79. */
  80. public int serialize(int offset, byte [] data)
  81. {
  82. if (thedata == null)
  83. {
  84. thedata = new byte[ 0 ];
  85. }
  86. LittleEndian.putShort(data, 0 + offset, sid);
  87. LittleEndian.putShort(data, 2 + offset, ( short ) (thedata.length));
  88. if (thedata.length > 0)
  89. {
  90. System.arraycopy(thedata, 0, data, 4 + offset, thedata.length);
  91. }
  92. return getRecordSize();
  93. }
  94. public int getRecordSize()
  95. {
  96. int retval = 4;
  97. if (thedata != null)
  98. {
  99. retval += thedata.length;
  100. }
  101. return retval;
  102. }
  103. protected void fillFields(byte [] data, short sid)
  104. {
  105. this.sid = sid;
  106. thedata = data;
  107. }
  108. /**
  109. * NO OP!
  110. */
  111. protected void validateSid(short id)
  112. {
  113. // if we had a valid sid we wouldn't be using the "Unknown Record" record now would we?
  114. }
  115. /**
  116. * print a sort of string representation ([UNKNOWN RECORD] id = x [/UNKNOWN RECORD])
  117. */
  118. public String toString()
  119. {
  120. StringBuffer buffer = new StringBuffer();
  121. buffer.append("[UNKNOWN RECORD:" + Integer.toHexString(sid) + "]\n");
  122. buffer.append(" .id = ").append(Integer.toHexString(sid))
  123. .append("\n");
  124. buffer.append("[/UNKNOWN RECORD]\n");
  125. return buffer.toString();
  126. }
  127. public short getSid()
  128. {
  129. return sid;
  130. }
  131. /**
  132. * called by the constructor, should set class level fields. Should throw
  133. * runtime exception for bad/icomplete data.
  134. *
  135. * @param in the RecordInputstream to read the record from
  136. */
  137. protected void fillFields(RecordInputStream in)
  138. {
  139. throw new RecordFormatException(
  140. "Unknown record cannot be constructed via offset -- we need a copy of the data");
  141. }
  142. /** Unlike the other Record.clone methods this is a shallow clone*/
  143. public Object clone() {
  144. UnknownRecord rec = new UnknownRecord();
  145. rec.sid = sid;
  146. rec.thedata = thedata;
  147. return rec;
  148. }
  149. }