Example usage for java.io EOFException EOFException

List of usage examples for java.io EOFException EOFException

Introduction

In this page you can find the example usage for java.io EOFException EOFException.

Prototype

public EOFException(String s) 

Source Link

Document

Constructs an EOFException with the specified detail message.

Usage

From source file:Main.java

public static void readFully(Reader input, char[] buffer, int offset, int length) throws IOException {
    int actual = read(input, buffer, offset, length);
    if (actual != length) {
        throw new EOFException("Length to read: " + length + " actual: " + actual);
    }/*from   www  .  j  av  a  2s . c o m*/
}

From source file:Main.java

public static int readFully(ReadableByteChannel paramReadableByteChannel, ByteBuffer paramByteBuffer,
        int paramInt) throws IOException {
    int i = 0;/* w  w w. j  av a2s.  co m*/
    int j;
    do {
        j = paramReadableByteChannel.read(paramByteBuffer);
        if (-1 == j)
            break;
        i += j;
    } while (i != paramInt);
    if (j == -1)
        throw new EOFException("End of file. No more boxes.");
    return i;
}

From source file:Main.java

public static void skipFully(InputStream input, long toSkip) throws IOException {
    if (toSkip < 0L) {
        throw new IllegalArgumentException("Bytes to skip must not be negative: " + toSkip);
    } else {/*from ww  w  .jav  a 2 s .  c  o m*/
        long skipped = skip(input, toSkip);
        if (skipped != toSkip) {
            throw new EOFException("Bytes to skip: " + toSkip + " actual: " + skipped);
        }
    }
}

From source file:Main.java

public static void readFully(InputStream input, byte[] buffer, int offset, int length) throws IOException {
    int actual = read(input, buffer, offset, length);
    if (actual != length) {
        throw new EOFException("Length to read: " + length + " actual: " + actual);
    }/*from  ww w .j av  a  2s  .  com*/
}

From source file:Main.java

public static void skipFully(Reader input, long toSkip) throws IOException {
    long skipped = skip(input, toSkip);
    if (skipped != toSkip) {
        throw new EOFException("Chars to skip: " + toSkip + " actual: " + skipped);
    }/* w w w  .  ja  v a  2 s . c  o m*/
}

From source file:Main.java

/**
 * Reads the next byte from the input stream.
 * @param input  the stream//from  w ww  . j  a v a 2s .  c o m
 * @return the byte
 * @throws IOException if the end of file is reached
 */
private static int read(InputStream input) throws IOException {
    int value = input.read();

    if (-1 == value) {
        throw new EOFException("Unexpected EOF reached");
    }

    return value;
}

From source file:Main.java

public static int readFully(final ReadableByteChannel channel, final ByteBuffer buf, final int length)
        throws IOException {
    int n, count = 0;
    while (-1 != (n = channel.read(buf))) {
        count += n;/*from  w ww.jav a 2s . co m*/
        if (count == length) {
            break;
        }
    }
    if (n == -1) {
        throw new EOFException("End of file. No more boxes.");
    }
    return count;
}

From source file:Main.java

/**
 * Read the requested number of characters or fail if there are not enough left.
 * <p>/*from ww  w  .  jav a 2  s. com*/
 * This allows for the possibility that {@link Reader#read(char[], int, int)} may
 * not skip as many characters as requested (most likely because of reaching EOF).
 * 
 * @param input where to read input from
 * @param buffer destination
 * @param offset inital offset into buffer
 * @param length length to read, must be >= 0
 * 
 * @throws IOException if there is a problem reading the file
 * @throws IllegalArgumentException if length is negative
 * @throws EOFException if the number of characters read was incorrect
 */
public static void readFully(Reader input, char[] buffer, int offset, int length) throws IOException {
    int actual = read(input, buffer, offset, length);
    if (actual != length) {
        throw new EOFException("Length to read: " + length + " actual: " + actual);
    }
}

From source file:BitInputStream.java

public final boolean readBit() throws IOException {
    if (--leftBits >= 0) {
        return ((byteBuf >>> leftBits) & 1) == 1;
    }/*from  w  w w .  j a v a2 s  . c  o m*/
    leftBits = 7;
    byteBuf = in.read();
    if (byteBuf == -1) {
        throw new EOFException("reached end of stream");
    }
    return ((byteBuf >>> 7) & 1) == 1;
}

From source file:Main.java

/**
 * Skip the requested number of bytes or fail if there are not enough left.
 * <p>/*ww  w . j av a2  s.  c  om*/
 * This allows for the possibility that {@link InputStream#skip(long)} may
 * not skip as many bytes as requested (most likely because of reaching EOF).
 * 
 * @param input stream to skip
 * @param toSkip the number of bytes to skip
 * @see InputStream#skip(long)
 * 
 * @throws IOException if there is a problem reading the file
 * @throws IllegalArgumentException if toSkip is negative
 * @throws EOFException if the number of bytes skipped was incorrect 
 * @since Commons IO 2.0
 */
public static void skipFully(InputStream input, long toSkip) throws IOException {
    if (toSkip < 0) {
        throw new IllegalArgumentException("Bytes to skip must not be negative: " + toSkip);
    }
    long skipped = skip(input, toSkip);
    if (skipped != toSkip) {
        throw new EOFException("Bytes to skip: " + toSkip + " actual: " + skipped);
    }
}