Skip to content

Commit e67636b

Browse files
committed
use static drain buffer to avoid needless garbage
1 parent 66363a6 commit e67636b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/main/java/robaho/net/httpserver/LeftOverInputStream.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,21 @@ public synchronized int read(byte[] b, int off, int len) throws IOException {
8989
return readImpl(b, off, len);
9090
}
9191

92+
// ok to concurrently share this since the data isn't used
93+
private static final byte[] drainBuffer = new byte[2048];
9294
/**
9395
* read and discard up to l bytes or "eof" occurs,
9496
* (whichever is first). Then return true if the stream
9597
* is at eof (ie. all bytes were read) or false if not
9698
* (still bytes to be read)
9799
*/
98100
public boolean drain(long l) throws IOException {
99-
int bufSize = 2048;
100-
byte[] db = new byte[bufSize];
101+
101102
while (l > 0) {
102103
if (server.isFinishing()) {
103104
break;
104105
}
105-
long len = readImpl(db, 0, bufSize);
106+
long len = readImpl(drainBuffer, 0, drainBuffer.length);
106107
if (len == -1) {
107108
eof = true;
108109
return true;

0 commit comments

Comments
 (0)