1 19 20 package jxl.read.biff; 21 22 import java.util.ArrayList ; 23 24 import common.Logger; 25 26 import jxl.biff.Type; 27 import jxl.biff.IntegerHelper; 28 29 32 public final class Record 33 { 34 37 private static final Logger logger = Logger.getLogger(Record.class); 38 39 42 private int code; 43 46 private Type type; 47 50 private int length; 51 54 private int dataPos; 55 58 private File file; 59 62 private byte[] data; 63 64 67 private ArrayList continueRecords; 68 69 76 Record(byte[] d, int offset, File f) 77 { 78 code = IntegerHelper.getInt(d[offset], d[offset + 1]); 79 length = IntegerHelper.getInt(d[offset + 2], d[offset + 3]); 80 file = f; 81 file.skip(4); 82 dataPos = f.getPos(); 83 file.skip(length); 84 type = Type.getType(code); 85 } 86 87 92 public Type getType() 93 { 94 return type; 95 } 96 97 102 public int getLength() 103 { 104 return length; 105 } 106 107 112 public byte[] getData() 113 { 114 if (data == null) 115 { 116 data = file.read(dataPos, length); 117 } 118 119 if (continueRecords != null) 121 { 122 int size = 0; 123 byte[][] contData = new byte[continueRecords.size()][]; 124 for (int i = 0; i < continueRecords.size(); i++) 125 { 126 Record r = (Record) continueRecords.get(i); 127 contData[i] = r.getData(); 128 byte[] d2 = contData[i]; 129 size += d2.length; 130 } 131 132 byte[] d3 = new byte[data.length + size]; 133 System.arraycopy(data, 0, d3, 0, data.length); 134 int pos = data.length; 135 for (int i = 0; i < contData.length; i++) 136 { 137 byte[] d2 = contData[i]; 138 System.arraycopy(d2, 0, d3, pos, d2.length); 139 pos += d2.length; 140 } 141 142 data = d3; 143 } 144 145 return data; 146 } 147 148 153 public int getCode() 154 { 155 return code; 156 } 157 158 164 void setType(Type t) 165 { 166 type = t; 167 } 168 169 174 public void addContinueRecord(Record d) 175 { 176 if (continueRecords == null) 177 { 178 continueRecords = new ArrayList (); 179 } 180 181 continueRecords.add(d); 182 } 183 } 184 | Popular Tags |