Lines 73-85
Link Here
|
73 |
public void convert( ByteChunk bb, CharChunk cb ) |
73 |
public void convert( ByteChunk bb, CharChunk cb ) |
74 |
throws IOException |
74 |
throws IOException |
75 |
{ |
75 |
{ |
76 |
// Set the ByteChunk as input to the Intermediate reader |
76 |
convert(bb, cb, cb.getLimit() - cb.getEnd()); |
77 |
convert(bb, cb, cb.getBuffer().length - cb.getEnd()); |
|
|
78 |
} |
77 |
} |
79 |
|
78 |
|
80 |
public void convert( ByteChunk bb, CharChunk cb, int limit) |
79 |
/** Convert a buffer of bytes into a chars |
81 |
throws IOException |
80 |
*/ |
|
|
81 |
public void convert( ByteChunk bb, CharChunk cb, int limit) |
82 |
throws IOException |
82 |
{ |
83 |
{ |
|
|
84 |
// Set the ByteChunk as input to the Intermediate reader |
83 |
iis.setByteChunk( bb ); |
85 |
iis.setByteChunk( bb ); |
84 |
convert(cb, limit); |
86 |
convert(cb, limit); |
85 |
} |
87 |
} |
Lines 89-98
Link Here
|
89 |
{ |
91 |
{ |
90 |
try { |
92 |
try { |
91 |
// read from the reader |
93 |
// read from the reader |
92 |
int count = 0; |
94 |
while( limit > 0 ) { |
93 |
while( limit > 0 ) { // conv.ready() ) { |
95 |
int size = limit < BUFFER_SIZE ? limit : BUFFER_SIZE; |
94 |
int size = limit < BUFFER_SIZE ? limit : BUFFER_SIZE; |
96 |
int cnt=conv.read( result, 0, size ); |
95 |
int cnt=conv.read( result, 0, size ); |
|
|
96 |
if( cnt <= 0 ) { |
97 |
if( cnt <= 0 ) { |
97 |
// End of stream ! - we may be in a bad state |
98 |
// End of stream ! - we may be in a bad state |
98 |
if( debug>0) |
99 |
if( debug>0) |
Lines 105-111
Link Here
|
105 |
|
106 |
|
106 |
// XXX go directly |
107 |
// XXX go directly |
107 |
cb.append( result, 0, cnt ); |
108 |
cb.append( result, 0, cnt ); |
108 |
limit -= cnt; |
109 |
limit -= cnt; |
109 |
} |
110 |
} |
110 |
} catch( IOException ex) { |
111 |
} catch( IOException ex) { |
111 |
if( debug>0) |
112 |
if( debug>0) |
Lines 193-210
Link Here
|
193 |
* |
194 |
* |
194 |
*/ |
195 |
*/ |
195 |
final class ReadConvertor extends InputStreamReader { |
196 |
final class ReadConvertor extends InputStreamReader { |
196 |
// stream with flush() and close(). overriden. |
197 |
|
197 |
private IntermediateInputStream iis; |
198 |
private IntermediateInputStream iis; |
198 |
|
199 |
|
199 |
// Has a private, internal byte[8192] |
|
|
200 |
|
201 |
/** Create a converter. |
200 |
/** Create a converter. |
202 |
*/ |
201 |
*/ |
203 |
public ReadConvertor( IntermediateInputStream in, String enc ) |
202 |
public ReadConvertor( IntermediateInputStream in, String enc ) |
204 |
throws UnsupportedEncodingException |
203 |
throws UnsupportedEncodingException |
205 |
{ |
204 |
{ |
206 |
super( in, enc ); |
205 |
super( in, enc ); |
207 |
iis=in; |
206 |
iis=in; |
208 |
} |
207 |
} |
209 |
|
208 |
|
210 |
/** Overriden - will do nothing but reset internal state. |
209 |
/** Overriden - will do nothing but reset internal state. |
Lines 221-229
Link Here
|
221 |
return super.read( cbuf, off, len ); |
220 |
return super.read( cbuf, off, len ); |
222 |
} |
221 |
} |
223 |
|
222 |
|
224 |
/** Reset the buffer |
223 |
/* |
|
|
224 |
* Reset the buffer |
225 |
*/ |
225 |
*/ |
226 |
public final void recycle() { |
226 |
public final void recycle() { |
|
|
227 |
iis.recycle(); |
228 |
try{ |
229 |
// Must clear super's buffer. |
230 |
while(ready()){ |
231 |
// InputStreamReader#skip(long) will allocate buffer to skip. |
232 |
read(); |
233 |
} |
234 |
}catch(IOException ioe){} |
227 |
} |
235 |
} |
228 |
} |
236 |
} |
229 |
|
237 |
|
Lines 246-260
Link Here
|
246 |
} |
254 |
} |
247 |
|
255 |
|
248 |
public final int read(byte cbuf[], int off, int len) throws IOException { |
256 |
public final int read(byte cbuf[], int off, int len) throws IOException { |
249 |
return bc.substract(cbuf, off, len); |
257 |
if(bc == null){ |
|
|
258 |
return -1; |
259 |
} |
260 |
return bc.substract(cbuf, off, len); |
250 |
} |
261 |
} |
251 |
|
262 |
|
252 |
public final int read() throws IOException { |
263 |
public final int read() throws IOException { |
253 |
return bc.substract(); |
264 |
if(bc == null){ |
|
|
265 |
return -1; |
266 |
} |
267 |
return bc.substract(); |
254 |
} |
268 |
} |
|
|
269 |
|
270 |
public int available() throws IOException { |
271 |
if(bc == null){ |
272 |
return 0; |
273 |
} |
274 |
return bc.getLength(); |
275 |
} |
255 |
|
276 |
|
|
|
277 |
|
256 |
// -------------------- Internal methods -------------------- |
278 |
// -------------------- Internal methods -------------------- |
257 |
|
279 |
|
|
|
280 |
void recycle(){ |
281 |
bc = null; |
282 |
} |
258 |
|
283 |
|
259 |
void setByteChunk( ByteChunk mb ) { |
284 |
void setByteChunk( ByteChunk mb ) { |
260 |
bc = mb; |
285 |
bc = mb; |