Methods Summary |
---|
public int | available()
if (closed) {
return 0;
}
int rc = (int) Math.min(chunkSize, Integer.MAX_VALUE);
return Math.min(rc, in.available());
|
public void | close()
synchronized (this) {
if (closed) {
return;
}
closed = true;
}
byte[] b = new byte[1024];
int bread = -1;
do {
bread = read(b, 0, b.length);
}
while (bread != -1);
|
protected long | getChunked()
int bufsz = 0;
chunkSize = -1L;
int c = -1;
do {
c = in.read();
if (c > -1) {
if (c != '\r" && c != '\n" && c != ' " && c != '\t") {
buf[bufsz++] = ((byte) c);
}
}
}
while (c > -1 && (c != '\n" || bufsz == 0) && bufsz < buf.length);
if (c < 0) {
closed = true;
}
String sbuf = new String(buf, 0, bufsz);
if (bufsz > maxCharLong) {
closed = true;
throw new IOException("Chunked input stream failed to receive valid chunk size:" + sbuf);
}
try {
chunkSize = Long.parseLong(sbuf, 16);
} catch (NumberFormatException ne) {
closed = true;
throw new IOException("'" + sbuf + "' " + ne.getMessage());
}
if (chunkSize < 0L) {
closed = true;
} if (chunkSize == 0) {
closed = true;
// consume last \r\n tokens of 0\r\n\r\n chunk
if (in.read() != -1) {
in.read();
}
}
if (chunkSize != 0L && c < 0) {
//If chunk size is zero try and be tolerant that there maybe no cr or lf at the end.
throw new IOException("HTTP Chunked stream closed in middle of chunk.");
}
if (chunkSize < 0L) {
throw new IOException("HTTP Chunk size received " +
chunkSize + " is less than zero.");
}
return chunkSize;
|
public boolean | markSupported()
return false;
|
public synchronized int | read()
if (closed) {
return -1;
}
try {
if (chunkSize < 1L) {
if (0l == getChunked()) {
return -1;
}
}
int rc = in.read();
if (rc > 0) {
chunkSize--;
}
return rc;
} catch (IOException e) {
closed = true;
throw e;
}
|
public int | read(byte[] b)
return read(b, 0, b.length);
|
public synchronized int | read(byte[] b, int off, int len)
if (closed) {
return -1;
}
int totalread = 0;
int bytesread = 0;
try {
do {
if (chunkSize < 1L) {
if (0l == getChunked()) {
if (totalread == 0) return -1;
else return totalread;
}
}
bytesread = in.read(b, off + totalread, Math.min(len - totalread,
(int) Math.min(chunkSize, Integer.MAX_VALUE)));
if (bytesread > 0) {
totalread += bytesread;
chunkSize -= bytesread;
}
}
while (len - totalread > 0 && bytesread > -1);
} catch (IOException e) {
closed = true;
throw e;
}
return totalread;
|
public void | reset()
throw new IOException("Don't support marked streams");
|
public long | skip(long n)
if (closed) {
return 0;
}
long skipped = 0l;
byte[] b = new byte[1024];
int bread = -1;
do {
bread = read(b, 0, b.length);
if (bread > 0) skipped += bread;
}
while (bread != -1 && skipped < n);
return skipped;
|