1 |
/* LineInputStream.java -- |
/* LineInputStream.java -- |
2 |
Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc. |
Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
38 |
|
|
39 |
package gnu.java.net; |
package gnu.java.net; |
40 |
|
|
41 |
|
import java.io.BufferedInputStream; |
42 |
import java.io.ByteArrayOutputStream; |
import java.io.ByteArrayOutputStream; |
43 |
import java.io.FilterInputStream; |
import java.io.FilterInputStream; |
44 |
import java.io.IOException; |
import java.io.IOException; |
92 |
buf = new ByteArrayOutputStream(); |
buf = new ByteArrayOutputStream(); |
93 |
this.encoding = encoding; |
this.encoding = encoding; |
94 |
eof = false; |
eof = false; |
95 |
blockReads = in.markSupported(); |
// If it is already buffered, additional buffering gains nothing. |
96 |
|
blockReads = !(in instanceof BufferedInputStream) && in.markSupported(); |
97 |
} |
} |
98 |
|
|
99 |
/** |
/** |
111 |
if (blockReads) |
if (blockReads) |
112 |
{ |
{ |
113 |
// Use mark and reset to read chunks of bytes |
// Use mark and reset to read chunks of bytes |
114 |
final int MIN_LENGTH = 1024; |
final int MAX_LENGTH = 1024; |
115 |
int len, pos; |
int len, pos; |
116 |
|
|
117 |
len = in.available(); |
len = in.available(); |
118 |
len = (len < MIN_LENGTH) ? MIN_LENGTH : len; |
if (len == 0 || len > MAX_LENGTH) |
119 |
|
len = MAX_LENGTH; |
120 |
byte[] b = new byte[len]; |
byte[] b = new byte[len]; |
121 |
in.mark(len); |
in.mark(len); |
122 |
// Read into buffer b |
// Read into buffer b |