use of java.io.EOFException in project okio by square.
the class SocketTimeoutTest method readFully.
private static byte[] readFully(InputStream in, int byteCount) throws IOException {
int count = 0;
byte[] result = new byte[byteCount];
while (count < byteCount) {
int read = in.read(result, count, result.length - count);
if (read == -1)
throw new EOFException();
count += read;
}
return result;
}
use of java.io.EOFException in project okio by square.
the class Buffer method write.
@Override
public BufferedSink write(Source source, long byteCount) throws IOException {
while (byteCount > 0) {
long read = source.read(this, byteCount);
if (read == -1)
throw new EOFException();
byteCount -= read;
}
return this;
}
use of java.io.EOFException in project okio by square.
the class Buffer method readFully.
@Override
public void readFully(byte[] sink) throws EOFException {
int offset = 0;
while (offset < sink.length) {
int read = read(sink, offset, sink.length - offset);
if (read == -1)
throw new EOFException();
offset += read;
}
}
use of java.io.EOFException in project okio by square.
the class Buffer method skip.
/** Discards {@code byteCount} bytes from the head of this buffer. */
@Override
public void skip(long byteCount) throws EOFException {
while (byteCount > 0) {
if (head == null)
throw new EOFException();
int toSkip = (int) Math.min(byteCount, head.limit - head.pos);
size -= toSkip;
byteCount -= toSkip;
head.pos += toSkip;
if (head.pos == head.limit) {
Segment toRecycle = head;
head = toRecycle.pop();
SegmentPool.recycle(toRecycle);
}
}
}
use of java.io.EOFException in project okio by square.
the class GzipSource method consumeHeader.
private void consumeHeader() throws IOException {
// Read the 10-byte header. We peek at the flags byte first so we know if we
// need to CRC the entire header. Then we read the magic ID1ID2 sequence.
// We can skip everything else in the first 10 bytes.
// +---+---+---+---+---+---+---+---+---+---+
// |ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->)
// +---+---+---+---+---+---+---+---+---+---+
source.require(10);
byte flags = source.buffer().getByte(3);
boolean fhcrc = ((flags >> FHCRC) & 1) == 1;
if (fhcrc)
updateCrc(source.buffer(), 0, 10);
short id1id2 = source.readShort();
checkEqual("ID1ID2", (short) 0x1f8b, id1id2);
source.skip(8);
// +---+---+=================================+
if (((flags >> FEXTRA) & 1) == 1) {
source.require(2);
if (fhcrc)
updateCrc(source.buffer(), 0, 2);
int xlen = source.buffer().readShortLe();
source.require(xlen);
if (fhcrc)
updateCrc(source.buffer(), 0, xlen);
source.skip(xlen);
}
// +=========================================+
if (((flags >> FNAME) & 1) == 1) {
long index = source.indexOf((byte) 0);
if (index == -1)
throw new EOFException();
if (fhcrc)
updateCrc(source.buffer(), 0, index + 1);
source.skip(index + 1);
}
// +===================================+
if (((flags >> FCOMMENT) & 1) == 1) {
long index = source.indexOf((byte) 0);
if (index == -1)
throw new EOFException();
if (fhcrc)
updateCrc(source.buffer(), 0, index + 1);
source.skip(index + 1);
}
// +---+---+
if (fhcrc) {
checkEqual("FHCRC", source.readShortLe(), (short) crc.getValue());
crc.reset();
}
}
Aggregations