use of java.io.EOFException in project okhttp by square.
the class DiskLruCache method readJournal.
private void readJournal() throws IOException {
BufferedSource source = Okio.buffer(fileSystem.source(journalFile));
try {
String magic = source.readUtf8LineStrict();
String version = source.readUtf8LineStrict();
String appVersionString = source.readUtf8LineStrict();
String valueCountString = source.readUtf8LineStrict();
String blank = source.readUtf8LineStrict();
if (!MAGIC.equals(magic) || !VERSION_1.equals(version) || !Integer.toString(appVersion).equals(appVersionString) || !Integer.toString(valueCount).equals(valueCountString) || !"".equals(blank)) {
throw new IOException("unexpected journal header: [" + magic + ", " + version + ", " + valueCountString + ", " + blank + "]");
}
int lineCount = 0;
while (true) {
try {
readJournalLine(source.readUtf8LineStrict());
lineCount++;
} catch (EOFException endOfJournal) {
break;
}
}
redundantOpCount = lineCount - lruEntries.size();
// If we ended on a truncated line, rebuild the journal before appending to it.
if (!source.exhausted()) {
rebuildJournal();
} else {
journalWriter = newJournalWriter();
}
} finally {
Util.closeQuietly(source);
}
}
use of java.io.EOFException in project okhttp by square.
the class FileOperator method read.
/**
* Copy {@code byteCount} bytes from the file at {@code pos} into to {@code source}. It is the
* caller's responsibility to make sure there are sufficient bytes to read: if there aren't this
* method throws an {@link EOFException}.
*/
public void read(long pos, Buffer sink, long byteCount) throws IOException {
if (byteCount < 0)
throw new IndexOutOfBoundsException();
while (byteCount > 0L) {
try {
// Read up to byteCount bytes.
byteBuffer.limit((int) Math.min(BUFFER_SIZE, byteCount));
if (fileChannel.read(byteBuffer, pos) == -1)
throw new EOFException();
int bytesRead = byteBuffer.position();
// Write those bytes to sink.
sink.write(byteArray, 0, bytesRead);
pos += bytesRead;
byteCount -= bytesRead;
} finally {
byteBuffer.clear();
}
}
}
use of java.io.EOFException in project retrofit by square.
the class WireConverterFactoryTest method deserializeWrongValue.
@Test
public void deserializeWrongValue() throws IOException {
ByteString encoded = ByteString.decodeBase64("////");
server.enqueue(new MockResponse().setBody(new Buffer().write(encoded)));
Call<?> call = service.get();
try {
call.execute();
fail();
} catch (EOFException ignored) {
}
}
use of java.io.EOFException in project okio by square.
the class InflaterSource method read.
@Override
public long read(Buffer sink, long byteCount) throws IOException {
if (byteCount < 0)
throw new IllegalArgumentException("byteCount < 0: " + byteCount);
if (closed)
throw new IllegalStateException("closed");
if (byteCount == 0)
return 0;
while (true) {
boolean sourceExhausted = refill();
// Decompress the inflater's compressed data into the sink.
try {
Segment tail = sink.writableSegment(1);
int bytesInflated = inflater.inflate(tail.data, tail.limit, Segment.SIZE - tail.limit);
if (bytesInflated > 0) {
tail.limit += bytesInflated;
sink.size += bytesInflated;
return bytesInflated;
}
if (inflater.finished() || inflater.needsDictionary()) {
releaseInflatedBytes();
if (tail.pos == tail.limit) {
// We allocated a tail segment, but didn't end up needing it. Recycle!
sink.head = tail.pop();
SegmentPool.recycle(tail);
}
return -1;
}
if (sourceExhausted)
throw new EOFException("source exhausted prematurely");
} catch (DataFormatException e) {
throw new IOException(e);
}
}
}
use of java.io.EOFException in project okio by square.
the class RealBufferedSink method write.
@Override
public BufferedSink write(Source source, long byteCount) throws IOException {
while (byteCount > 0) {
long read = source.read(buffer, byteCount);
if (read == -1)
throw new EOFException();
byteCount -= read;
emitCompleteSegments();
}
return this;
}
Aggregations