View | Details | Raw Unified | Return to bug 44494
Collapse All | Expand All

(-)java/org/apache/catalina/connector/CoyoteReader.java (-1 / +1 lines)
Lines 119-125 Link Here
119
119
120
120
121
    public boolean markSupported() {
121
    public boolean markSupported() {
122
        return true;
122
        return ib.markSupported();
123
    }
123
    }
124
124
125
125
(-)java/org/apache/catalina/connector/InputBuffer.java (-10 / +18 lines)
Lines 342-363 Link Here
342
        if (!gotEnc)
342
        if (!gotEnc)
343
            setConverter();
343
            setConverter();
344
344
345
        int nRead = 0;
345
        if (bb.getLength() <= 0) {
346
        if (bb.getLength() <= 0) {
346
            int nRead = realReadBytes(bb.getBytes(), 0, bb.getBytes().length);
347
            nRead = realReadBytes(bb.getBytes(), 0, bb.getBytes().length);
347
            if (nRead < 0) {
348
            // Data may be remaining in the buffer of ReadConverter('s super).
348
                return -1;
349
            // So we must try to convert whether nRead is positive or not.
349
            }
350
        }
350
        }
351
352
        if (markPos == -1) {
351
        if (markPos == -1) {
353
            cb.setOffset(0);
352
            cb.setOffset(0);
354
            cb.setEnd(0);
353
            cb.setEnd(0);
355
        }
354
        }
356
355
357
        conv.convert(bb, cb);
356
        if((markPos >= 0) && (cb.getLimit()-cb.getEnd()) <= 0){
358
        bb.setOffset(bb.getEnd());
357
            // markPos will be reset and the status of cb will be modified
358
            // via cb.flushBuffer(), only if more chars exists.
359
            conv.convert(bb, cb, cb.getLimit());
360
        }else{
361
        conv.convert(bb, cb, cb.getLimit()-cb.getEnd());
362
        }
359
        state = CHAR_STATE;
363
        state = CHAR_STATE;
360
364
365
        if((nRead < 0) && (cb.getLength()==0)){
366
            return -1;
367
        }
361
        return cb.getLength();
368
        return cb.getLength();
362
369
363
    }
370
    }
Lines 426-431 Link Here
426
433
427
    public void mark(int readAheadLimit)
434
    public void mark(int readAheadLimit)
428
        throws IOException {
435
        throws IOException {
436
        if (readAheadLimit < 0){ // See BufferedReader#mark(int) JavaDoc
437
            throw new IllegalArgumentException("readAheadLimit value is negative");
438
        }
429
        if (cb.getLength() <= 0) {
439
        if (cb.getLength() <= 0) {
430
            cb.setOffset(0);
440
            cb.setOffset(0);
431
            cb.setEnd(0);
441
            cb.setEnd(0);
Lines 451-459 Link Here
451
        throws IOException {
461
        throws IOException {
452
        if (state == CHAR_STATE) {
462
        if (state == CHAR_STATE) {
453
            if (markPos < 0) {
463
            if (markPos < 0) {
454
                cb.recycle();
464
                throw new IOException("The mark is not effective");
455
                markPos = -1;
456
                throw new IOException();
457
            } else {
465
            } else {
458
                cb.setOffset(markPos);
466
                cb.setOffset(markPos);
459
            }
467
            }
(-)java/org/apache/tomcat/util/buf/B2CConverter.java (-66 / +48 lines)
Lines 68-89 Link Here
68
    char result[]=new char[BUFFER_SIZE];
68
    char result[]=new char[BUFFER_SIZE];
69
69
70
    /** Convert a buffer of bytes into a chars
70
    /** Convert a buffer of bytes into a chars
71
     * @deprecated
71
     */
72
     */
72
    public  void convert( ByteChunk bb, CharChunk cb )
73
    public  void convert( ByteChunk bb, CharChunk cb )
73
	throws IOException
74
	throws IOException
74
    {
75
    {
75
	// Set the ByteChunk as input to the Intermediate reader
76
        convert(bb, cb, cb.getLimit() - cb.getEnd());
76
	iis.setByteChunk( bb );
77
	convert(cb);
78
    }
77
    }
79
78
80
    private void convert(CharChunk cb)
79
    /** Convert a buffer of bytes into a chars
80
     */
81
    public void convert( ByteChunk bb, CharChunk cb, int limit)
82
    throws IOException
83
    {
84
        // Set the ByteChunk as input to the Intermediate reader
85
        iis.setByteChunk( bb );
86
        convert(cb, limit);
87
    }
88
89
    private void convert(CharChunk cb, int limit)
81
	throws IOException
90
	throws IOException
82
    {
91
    {
83
	try {
92
	try {
84
	    // read from the reader
93
	    // read from the reader
85
	    while( iis.available()>0 ) { // conv.ready() ) {
94
        while( limit > 0 ) { 
86
		int cnt=conv.read( result, 0, BUFFER_SIZE );
95
        int size = limit < BUFFER_SIZE ? limit : BUFFER_SIZE;
96
        int cnt=conv.read( result, 0, size );
87
		if( cnt <= 0 ) {
97
		if( cnt <= 0 ) {
88
		    // End of stream ! - we may be in a bad state
98
		    // End of stream ! - we may be in a bad state
89
		    if( debug>0)
99
		    if( debug>0)
Lines 96-101 Link Here
96
106
97
		// XXX go directly
107
		// XXX go directly
98
		cb.append( result, 0, cnt );
108
		cb.append( result, 0, cnt );
109
        limit -= cnt;
99
	    }
110
	    }
100
	} catch( IOException ex) {
111
	} catch( IOException ex) {
101
	    if( debug>0)
112
	    if( debug>0)
Lines 183-200 Link Here
183
 * 
194
 * 
184
 */
195
 */
185
final class  ReadConvertor extends InputStreamReader {
196
final class  ReadConvertor extends InputStreamReader {
186
    // stream with flush() and close(). overriden.
187
    private IntermediateInputStream iis;
188
    
197
    
189
    // Has a private, internal byte[8192]
198
    private IntermediateInputStream iis;
190
    
199
191
    /** Create a converter.
200
    /** Create a converter.
192
     */
201
     */
193
    public ReadConvertor( IntermediateInputStream in, String enc )
202
    public ReadConvertor( IntermediateInputStream in, String enc )
194
	throws UnsupportedEncodingException
203
	throws UnsupportedEncodingException
195
    {
204
    {
196
	super( in, enc );
205
	super( in, enc );
197
	iis=in;
206
    iis=in;
198
    }
207
    }
199
    
208
    
200
    /** Overriden - will do nothing but reset internal state.
209
    /** Overriden - will do nothing but reset internal state.
Lines 211-223 Link Here
211
	return super.read( cbuf, off, len );
220
	return super.read( cbuf, off, len );
212
    }
221
    }
213
    
222
    
214
    public final int read() throws IOException {
223
    /*
215
        return super.read();
224
     * Reset the buffer
216
    }
217
    
218
    /** Reset the buffer
219
     */
225
     */
220
    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){}
221
    }
235
    }
222
}
236
}
223
237
Lines 229-238 Link Here
229
    not be called if recycling the converter and if data was not flushed.
243
    not be called if recycling the converter and if data was not flushed.
230
*/
244
*/
231
final class IntermediateInputStream extends InputStream {
245
final class IntermediateInputStream extends InputStream {
232
    byte buf[];
246
    ByteChunk bc = null;
233
    int pos;
234
    int len;
235
    int end;
236
    
247
    
237
    public IntermediateInputStream() {
248
    public IntermediateInputStream() {
238
    }
249
    }
Lines 243-306 Link Here
243
    }
254
    }
244
    
255
    
245
    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 {
246
	if( pos >= end ) return -1;
257
        if(bc == null){
247
	if (pos + len > end) {
258
            return -1;
248
	    len = end - pos;
259
        }
249
	}
260
        return bc.substract(cbuf, off, len);
250
	if (len <= 0) {
251
	    return 0;
252
	}
253
	System.arraycopy(buf, pos, cbuf, off, len);
254
	pos += len;
255
	return len;
256
    }
261
    }
257
    
262
    
258
    public  final int read() throws IOException {
263
    public  final int read() throws IOException {
259
	return (pos < end ) ? (buf[pos++] & 0xff) : -1;
264
        if(bc == null){
265
            return -1;
266
        }
267
        return bc.substract();
260
    }
268
    }
261
    
269
    
262
    // -------------------- Internal methods --------------------
263
264
    void setBuffer( byte b[], int p, int l ) {
265
	buf=b;
266
	pos=p;
267
	len=l;
268
	end=pos+len;
269
    }
270
271
    void setByteChunk( ByteChunk mb ) {
272
	buf=mb.getBytes();
273
	pos=mb.getStart();
274
	len=mb.getLength();
275
	end=pos+len;
276
    }
277
278
    public int available() throws IOException {
270
    public int available() throws IOException {
279
        return end-pos;
271
        if(bc == null){
272
            return 0;
273
        }
274
        return bc.getLength();
280
    }
275
    }
281
276
282
    public boolean markSupported() {
283
        return false;
284
    }
285
277
286
    public int read(byte[] b) throws IOException {
278
    // -------------------- Internal methods --------------------
287
        return read(b,0,b.length);
288
    }
289
279
290
    /**
280
    void recycle(){
291
     * Repositions this stream to the position at the time the <code>mark</code> method was last called on this input
281
        bc = null;
292
     * stream.
293
     *
294
     * @throws IOException if this stream has not been marked or if the mark has been invalidated.
295
     * @todo Implement this java.io.InputStream method
296
     */
297
    public synchronized void reset() throws IOException {
298
        //not implemented
299
    }
282
    }
300
283
301
    public long skip(long n) throws IOException {
284
    void setByteChunk( ByteChunk mb ) {
302
        //not implemented
285
        bc = mb;
303
        return 0L;
304
    }
286
    }
305
287
306
}
288
}

Return to bug 44494