Lines 18-28
Link Here
|
18 |
|
18 |
|
19 |
package org.apache.poi.hssf.record; |
19 |
package org.apache.poi.hssf.record; |
20 |
|
20 |
|
21 |
import org.apache.poi.util.LittleEndian; |
21 |
import java.io.ByteArrayOutputStream; |
22 |
|
|
|
23 |
import java.io.IOException; |
22 |
import java.io.IOException; |
24 |
import java.io.InputStream; |
23 |
import java.io.InputStream; |
25 |
import java.io.ByteArrayOutputStream; |
24 |
|
|
|
25 |
import org.apache.poi.util.LittleEndian; |
26 |
|
26 |
|
27 |
/** |
27 |
/** |
28 |
* Title: Record Input Stream<P> |
28 |
* Title: Record Input Stream<P> |
Lines 37-45
Link Here
|
37 |
public final static short MAX_RECORD_DATA_SIZE = 8224; |
37 |
public final static short MAX_RECORD_DATA_SIZE = 8224; |
38 |
|
38 |
|
39 |
private InputStream in; |
39 |
private InputStream in; |
40 |
protected short currentSid; |
40 |
protected short currentSid = -1; |
41 |
protected short currentLength = -1; |
41 |
protected short currentLength = -1; |
42 |
protected short nextSid = -1; |
42 |
protected short nextSid; |
43 |
|
43 |
|
44 |
protected byte[] data = new byte[MAX_RECORD_DATA_SIZE]; |
44 |
protected byte[] data = new byte[MAX_RECORD_DATA_SIZE]; |
45 |
protected short recordOffset; |
45 |
protected short recordOffset; |
Lines 47-56
Link Here
|
47 |
|
47 |
|
48 |
private boolean autoContinue = true; |
48 |
private boolean autoContinue = true; |
49 |
|
49 |
|
|
|
50 |
/** currentSid with this value indicates EOF. */ |
51 |
private final short eof; |
52 |
|
50 |
public RecordInputStream(InputStream in) throws RecordFormatException { |
53 |
public RecordInputStream(InputStream in) throws RecordFormatException { |
|
|
54 |
this(in, (short) 0); |
55 |
} |
56 |
|
57 |
/** |
58 |
* Constructs. |
59 |
* @param in The input stream. |
60 |
* @param eof The sid that indicates end of stream. |
61 |
*/ |
62 |
public RecordInputStream(InputStream in, short eof) throws RecordFormatException { |
51 |
this.in = in; |
63 |
this.in = in; |
|
|
64 |
this.eof = eof; |
52 |
try { |
65 |
try { |
53 |
nextSid = LittleEndian.readShort(in); |
66 |
nextSid = readLEShortOrEOF(); |
54 |
//Dont increment the pos just yet (technically we are at the start of |
67 |
//Dont increment the pos just yet (technically we are at the start of |
55 |
//the record stream until nextRecord is called). |
68 |
//the record stream until nextRecord is called). |
56 |
} catch (IOException ex) { |
69 |
} catch (IOException ex) { |
Lines 85-91
Link Here
|
85 |
} |
98 |
} |
86 |
|
99 |
|
87 |
public boolean hasNextRecord() { |
100 |
public boolean hasNextRecord() { |
88 |
return (nextSid != 0); |
101 |
return nextSid != eof; |
89 |
} |
102 |
} |
90 |
|
103 |
|
91 |
/** Moves to the next record in the stream. |
104 |
/** Moves to the next record in the stream. |
Lines 109-120
Link Here
|
109 |
in.read(data, 0, currentLength); |
122 |
in.read(data, 0, currentLength); |
110 |
|
123 |
|
111 |
//Read the Sid of the next record |
124 |
//Read the Sid of the next record |
112 |
nextSid = LittleEndian.readShort(in); |
125 |
nextSid = readLEShortOrEOF(); |
113 |
} catch (IOException ex) { |
126 |
} catch (IOException ex) { |
114 |
throw new RecordFormatException("Error reading bytes"); |
127 |
throw new RecordFormatException("Error reading bytes"); |
115 |
} |
128 |
} |
116 |
} |
129 |
} |
117 |
|
130 |
|
|
|
131 |
private short readLEShortOrEOF() throws IOException { |
132 |
int firstByte = in.read(); |
133 |
if (-1 == firstByte) { |
134 |
return eof; |
135 |
} |
136 |
int secondByte = in.read(); |
137 |
return (short) ((secondByte << 8) | firstByte); |
138 |
} |
139 |
|
118 |
public void setAutoContinue(boolean enable) { |
140 |
public void setAutoContinue(boolean enable) { |
119 |
this.autoContinue = enable; |
141 |
this.autoContinue = enable; |
120 |
} |
142 |
} |