Search in sources :

Example 36 with EOFException

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;
}
Also used : EOFException(java.io.EOFException)

Example 37 with EOFException

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;
}
Also used : EOFException(java.io.EOFException)

Example 38 with EOFException

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;
    }
}
Also used : EOFException(java.io.EOFException)

Example 39 with EOFException

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);
        }
    }
}
Also used : EOFException(java.io.EOFException)

Example 40 with EOFException

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();
    }
}
Also used : EOFException(java.io.EOFException)

Aggregations

EOFException (java.io.EOFException)624 IOException (java.io.IOException)275 FileInputStream (java.io.FileInputStream)81 DataInputStream (java.io.DataInputStream)79 Test (org.junit.Test)59 ByteArrayInputStream (java.io.ByteArrayInputStream)53 InputStream (java.io.InputStream)43 RandomAccessFile (java.io.RandomAccessFile)42 ArrayList (java.util.ArrayList)42 File (java.io.File)41 FileNotFoundException (java.io.FileNotFoundException)41 ByteBuffer (java.nio.ByteBuffer)40 BufferedInputStream (java.io.BufferedInputStream)31 Path (org.apache.hadoop.fs.Path)21 InterruptedIOException (java.io.InterruptedIOException)20 ObjectInputStream (java.io.ObjectInputStream)20 ByteArrayOutputStream (java.io.ByteArrayOutputStream)19 SocketTimeoutException (java.net.SocketTimeoutException)19 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)17 SocketException (java.net.SocketException)16