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
356
        if((markPos >= 0) && (cb.getLimit()-cb.getEnd()) <= 0){
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
        }
357
        state = CHAR_STATE;
363
        state = CHAR_STATE;
358
        conv.convert(bb, cb, len);
359
        bb.setOffset(bb.getEnd());
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 (-17 / +42 lines)
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;

Return to bug 44494