use of java.io.EOFException in project iosched by google.
the class StrictLineReaderTest method lineReaderConsistencyWithReadAsciiLine.
@Test
public void lineReaderConsistencyWithReadAsciiLine() {
try {
// Testing with LineReader buffer capacity 32 to check some corner cases.
StrictLineReader lineReader = new StrictLineReader(createTestInputStream(), 32, Util.US_ASCII);
InputStream refStream = createTestInputStream();
while (true) {
try {
String refLine = readAsciiLine(refStream);
try {
String line = lineReader.readLine();
if (!refLine.equals(line)) {
fail("line (\"" + line + "\") differs from expected (\"" + refLine + "\").");
}
} catch (EOFException eof) {
fail("line reader threw EOFException too early.");
}
} catch (EOFException refEof) {
try {
lineReader.readLine();
fail("line reader didn't throw the expected EOFException.");
} catch (EOFException expected) {
break;
}
}
}
refStream.close();
lineReader.close();
} catch (IOException ioe) {
fail("Unexpected IOException " + ioe.toString());
}
}
use of java.io.EOFException in project j2objc by google.
the class GZIPInputStream method maybeReadNextMember.
private boolean maybeReadNextMember() throws IOException {
// If we have any unconsumed data in the inflater buffer, we have to
// scan that first. The fact that we've reached here implies we've
// successfully consumed the GZIP trailer.
final int remaining = inf.getRemaining() - GZIP_TRAILER_SIZE;
if (remaining > 0) {
// remaining when it is first created.
if (!(in instanceof PushbackInputStream)) {
in = new PushbackInputStream(in, buf.length);
}
((PushbackInputStream) in).unread(buf, inf.getCurrentOffset() + GZIP_TRAILER_SIZE, remaining);
}
final byte[] buffer;
try {
buffer = readHeader(in);
} catch (EOFException eof) {
// gzip record.
return true;
}
final short magic = Memory.peekShort(buffer, 0, ByteOrder.LITTLE_ENDIAN);
if (magic != (short) GZIP_MAGIC) {
// from this stream.
return true;
}
// We've encountered the gzip magic number, so we assume there's another
// member in the stream.
parseGzipHeader(in, buffer, crc, buf);
return false;
}
use of java.io.EOFException in project j2objc by google.
the class InflaterInputStream method fill.
/**
* Fills the input buffer with data to be decompressed.
*
* @throws IOException
* if an {@code IOException} occurs.
*/
protected void fill() throws IOException {
checkClosed();
if (nativeEndBufSize > 0) {
ZipFile.RAFStream is = (ZipFile.RAFStream) in;
len = is.fill(inf, nativeEndBufSize);
} else {
if ((len = in.read(buf)) > 0) {
inf.setInput(buf, 0, len);
} else if (len == -1) {
throw new EOFException("Unexpected end of stream.");
}
}
}
use of java.io.EOFException in project j2objc by google.
the class InflaterInputStream method read.
/**
* Reads up to {@code byteCount} bytes of decompressed data and stores it in
* {@code buffer} starting at {@code byteOffset}. Returns the number of uncompressed bytes read,
* or -1.
*/
@Override
public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
checkClosed();
Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount);
if (byteCount == 0) {
return 0;
}
if (eof) {
return -1;
}
do {
if (inf.needsInput()) {
fill();
}
// It may also be true if the next read() should return -1.
try {
int result = inf.inflate(buffer, byteOffset, byteCount);
eof = inf.finished();
if (result > 0) {
return result;
} else if (eof) {
return -1;
} else if (inf.needsDictionary()) {
eof = true;
return -1;
} else if (len == -1) {
eof = true;
throw new EOFException();
// If result == 0, fill() and try again
}
} catch (DataFormatException e) {
eof = true;
if (len == -1) {
throw new EOFException();
}
throw (IOException) (new IOException().initCause(e));
}
} while (true);
}
use of java.io.EOFException in project okhttp by square.
the class Http1Codec method readResponseHeaders.
@Override
public Response.Builder readResponseHeaders(boolean expectContinue) throws IOException {
if (state != STATE_OPEN_REQUEST_BODY && state != STATE_READ_RESPONSE_HEADERS) {
throw new IllegalStateException("state: " + state);
}
try {
StatusLine statusLine = StatusLine.parse(source.readUtf8LineStrict());
Response.Builder responseBuilder = new Response.Builder().protocol(statusLine.protocol).code(statusLine.code).message(statusLine.message).headers(readHeaders());
if (expectContinue && statusLine.code == HTTP_CONTINUE) {
return null;
}
state = STATE_OPEN_RESPONSE_BODY;
return responseBuilder;
} catch (EOFException e) {
// Provide more context if the server ends the stream before sending a response.
IOException exception = new IOException("unexpected end of stream on " + streamAllocation);
exception.initCause(e);
throw exception;
}
}
Aggregations