PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/openmicroscopy/bioformats
Java | 216 lines | 133 code | 27 blank | 56 comment | 8 complexity | 2b661f17b2ecd9447e362a3560874f95 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.IntList;
  39. import loci.poi.util.LittleEndian;
  40. /**
  41. * Title: Index Record<P>
  42. * Description: Occurs right after BOF, tells you where the DBCELL records are for a sheet
  43. * Important for locating cells<P>
  44. * NOT USED IN THIS RELEASE
  45. * REFERENCE: PG 323 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  46. * @author Andrew C. Oliver (acoliver at apache dot org)
  47. * @author Jason Height (jheight at chariot dot net dot au)
  48. * @version 2.0-pre
  49. */
  50. public class IndexRecord
  51. extends Record
  52. {
  53. public final static short sid = 0x20B;
  54. public final static int DBCELL_CAPACITY = 30;
  55. public int field_1_zero; // reserved must be 0
  56. public int field_2_first_row; // first row on the sheet
  57. public int field_3_last_row_add1; // last row
  58. public int field_4_zero; // reserved must be 0
  59. public IntList field_5_dbcells; // array of offsets to DBCELL records
  60. public IndexRecord()
  61. {
  62. }
  63. /**
  64. * Constructs an Index record and sets its fields appropriately.
  65. * @param in the RecordInputstream to read the record from
  66. */
  67. public IndexRecord(RecordInputStream in)
  68. {
  69. super(in);
  70. }
  71. protected void validateSid(short id)
  72. {
  73. if (id != sid)
  74. {
  75. throw new RecordFormatException("NOT An Index RECORD");
  76. }
  77. }
  78. protected void fillFields(RecordInputStream in)
  79. {
  80. field_5_dbcells =
  81. new IntList(DBCELL_CAPACITY); // initial capacity of 30
  82. field_1_zero = in.readInt();
  83. field_2_first_row = in.readInt();
  84. field_3_last_row_add1 = in.readInt();
  85. field_4_zero = in.readInt();
  86. while(in.remaining() > 0)
  87. {
  88. // System.out.println("getting " + k);
  89. field_5_dbcells.add(in.readInt());
  90. }
  91. }
  92. public void setFirstRow(int row)
  93. {
  94. field_2_first_row = row;
  95. }
  96. public void setLastRowAdd1(int row)
  97. {
  98. field_3_last_row_add1 = row;
  99. }
  100. public void addDbcell(int cell)
  101. {
  102. if (field_5_dbcells == null)
  103. {
  104. field_5_dbcells = new IntList();
  105. }
  106. field_5_dbcells.add(cell);
  107. }
  108. public void setDbcell(int cell, int value)
  109. {
  110. field_5_dbcells.set(cell, value);
  111. }
  112. public int getFirstRow()
  113. {
  114. return field_2_first_row;
  115. }
  116. public int getLastRowAdd1()
  117. {
  118. return field_3_last_row_add1;
  119. }
  120. public int getNumDbcells()
  121. {
  122. if (field_5_dbcells == null)
  123. {
  124. return 0;
  125. }
  126. return field_5_dbcells.size();
  127. }
  128. public int getDbcellAt(int cellnum)
  129. {
  130. return field_5_dbcells.get(cellnum);
  131. }
  132. public String toString()
  133. {
  134. StringBuffer buffer = new StringBuffer();
  135. buffer.append("[INDEX]\n");
  136. buffer.append(" .firstrow = ")
  137. .append(Integer.toHexString(getFirstRow())).append("\n");
  138. buffer.append(" .lastrowadd1 = ")
  139. .append(Integer.toHexString(getLastRowAdd1())).append("\n");
  140. for (int k = 0; k < getNumDbcells(); k++)
  141. {
  142. buffer.append(" .dbcell_" + k + " = ")
  143. .append(Integer.toHexString(getDbcellAt(k))).append("\n");
  144. }
  145. buffer.append("[/INDEX]\n");
  146. return buffer.toString();
  147. }
  148. public int serialize(int offset, byte [] data)
  149. {
  150. LittleEndian.putShort(data, 0 + offset, sid);
  151. LittleEndian.putShort(data, 2 + offset,
  152. ( short ) (16 + (getNumDbcells() * 4)));
  153. LittleEndian.putInt(data, 4 + offset, 0);
  154. LittleEndian.putInt(data, 8 + offset, getFirstRow());
  155. LittleEndian.putInt(data, 12 + offset, getLastRowAdd1());
  156. LittleEndian.putInt(data, 16 + offset, 0);
  157. for (int k = 0; k < getNumDbcells(); k++)
  158. {
  159. LittleEndian.putInt(data, (k * 4) + 20 + offset, getDbcellAt(k));
  160. }
  161. return getRecordSize();
  162. }
  163. public int getRecordSize()
  164. {
  165. return 20 + (getNumDbcells() * 4);
  166. }
  167. /** Returns the size of an INdexRecord when it needs to index the specified number of blocks
  168. *
  169. */
  170. public static int getRecordSizeForBlockCount(int blockCount) {
  171. return 20 + (4 * blockCount);
  172. }
  173. public short getSid()
  174. {
  175. return sid;
  176. }
  177. public Object clone() {
  178. IndexRecord rec = new IndexRecord();
  179. rec.field_1_zero = field_1_zero;
  180. rec.field_2_first_row = field_2_first_row;
  181. rec.field_3_last_row_add1 = field_3_last_row_add1;
  182. rec.field_4_zero = field_4_zero;
  183. rec.field_5_dbcells = new IntList();
  184. rec.field_5_dbcells.addAll(field_5_dbcells);
  185. return rec;
  186. }
  187. }