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() 

Source Link

Document

Constructs an EOFException with null as its error detail message.

Usage

From source file:Main.java

public static void skipFully(InputStream in, long n) throws IOException {
    while (n > 0) {
        long count = in.skip(n);
        if (count <= 0)
            throw new EOFException();
        n -= count;/*  w  w w  .j  a  v  a2 s . c  o  m*/
    }
}

From source file:Main.java

public static void readFully(InputStream in, byte b[], int off, int len) throws IOException {
    if (off < 0 || len < 0 || off + len > b.length)
        throw new IndexOutOfBoundsException();
    while (len > 0) {
        int count = in.read(b, off, len);
        if (count < 0)
            throw new EOFException();
        off += count;/*ww  w. j  a  v a  2  s  .co  m*/
        len -= count;
    }
}

From source file:org.globus.ftp.InputStreamDataSink.java

public void write(Buffer buffer) throws IOException {
    if (isClosed()) {
        throw new EOFException();
    }/*from w ww. j a v a2  s. c  om*/
    try {
        if (!buffers.put(buffer)) {
            throw new EOFException();
        }
    } catch (InterruptedException e) {
        throw new InterruptedIOException();
    }
}

From source file:com.norconex.importer.parser.impl.wordperfect.WPInputStream.java

/**
 * Reads a WordPerfect "short": a 2 bytes (16-bit) unsigned value in 
 * reverse order./*w ww.  jav  a  2 s  .  co  m*/
 * @return an integer value
 * @throws IOException if not enough bytes remain
 */
public int readWPShort() throws IOException {
    int ch1 = in.read();
    int ch2 = in.read();
    if ((ch1 | ch2) < 0) {
        throw new EOFException();
    }
    return (ch2 << 8) + (ch1 << 0);
}

From source file:it.unimi.di.big.mg4j.io.IOFactories.java

public static byte[] loadBytes(final IOFactory ioFactory, final String filename) throws IOException {
    final long length = ioFactory.length(filename);
    if (length >= Integer.MAX_VALUE)
        throw new IllegalArgumentException("File is too long (" + length + " bytes).");
    final byte[] array = new byte[(int) length];
    final InputStream is = ioFactory.getInputStream(filename);
    if (read(is, array, 0, (int) length) < length)
        throw new EOFException();
    is.close();//  ww w .jav a2s  .  co  m
    return array;
}

From source file:org.taverna.server.master.utils.DerbyUtils.java

@Override
public void write(char[] cbuf, int off, int len) throws IOException {
    if (closed)/*  www.  j a  v  a 2  s.co  m*/
        throw new EOFException();
    if (!log.isInfoEnabled())
        return;
    sb.append(cbuf, off, len);
    while (!closed) {
        int idx = sb.indexOf("\n"), realIdx = idx;
        if (idx < 0)
            break;
        char ch;
        while (idx > 0 && ((ch = sb.charAt(idx - 1)) == '\r' || ch == ' ' || ch == '\t'))
            idx--;
        if (idx > 0)
            log.info(sb.substring(0, idx));
        sb.delete(0, realIdx + 1);
    }
}

From source file:com.norconex.importer.parser.impl.wordperfect.WPInputStream.java

/**
 * Reads a WordPerfect "long": a 4 bytes (32-bit) unsigned value in 
 * reverse order./*from w ww.  j a va2  s  . co m*/
 * @return a long value
 * @throws IOException if not enough bytes remain
 */
public long readWPLong() throws IOException {
    int ch1 = in.read();
    int ch2 = in.read();
    int ch3 = in.read();
    int ch4 = in.read();
    if ((ch1 | ch2 | ch3 | ch4) < 0) {
        throw new EOFException();
    }
    return ((ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0));
}

From source file:org.apache.jackrabbit.core.data.db.DbInputStream.java

/**
 * Open the stream if required.//w  ww.j a  v a 2s.c om
 *
 * @throws IOException
 */
protected void openStream() throws IOException {
    if (endOfStream) {
        throw new EOFException();
    }
    if (in == null) {
        try {
            in = store.openStream(this, identifier);
        } catch (DataStoreException e) {
            IOException e2 = new IOException(e.getMessage());
            e2.initCause(e);
            throw e2;
        }
    }
}

From source file:org.bdval.io.compound.CompoundDataInput.java

/**
 * {@inheritDoc}//from   w ww. j a  va 2  s .  c  om
 */
public void readFully(final byte[] b) throws IOException {
    fileSize -= b.length;
    if (fileSize < 0) {
        throw new EOFException();
    }
    dataInput.readFully(b);
}

From source file:org.globus.ftp.vanilla.Reply.java

/**
 * @throws EOFException on end of stream
 * @throws IOException on I/O problem/* w ww. j av a2s . com*/
 * @throws FTPReplyParseException if cannot parse
 **/
public Reply(BufferedReader input) throws FTPReplyParseException, EOFException, IOException {
    logger.debug("read 1st line");
    String line = input.readLine();
    if (logger.isDebugEnabled()) {
        logger.debug("1st line: " + line);
    }

    //end of stream
    if (line == null) {
        throw new EOFException();
    }

    //for compatibility with GT2.0 wuftp server which is incorrectly inserting \0 between lines
    line = ignoreLeading0(line);

    if (line.length() < MIN_FIRST_LEN) {
        throw new FTPReplyParseException(FTPReplyParseException.STRING_TOO_SHORT, "Minimum 1st line length = "
                + MIN_FIRST_LEN + ". Here's the incorrect 1st line ->" + line + "<-");
    }

    // code
    String codeString = line.substring(0, 3);

    try {
        code = Integer.parseInt(codeString);
    } catch (NumberFormatException e) {
        throw new FTPReplyParseException(FTPReplyParseException.FIRST_3_CHARS,
                "Here's the incorrect line ->" + line + "<-" + "and the first 3 chars ->" + codeString + "<-");
    }

    // category
    category = line.charAt(0) - '0';

    // message
    char char4 = line.charAt(3);

    //do not include 4th char in message
    message = line.substring(4, line.length());

    if (char4 == ' ') {

        //single line reply
        isMultiline = false;

    } else if (char4 == '-') {

        //multi - line reply

        isMultiline = true;

        String lastLineStarts = codeString + ' ';
        //platform dependent line separator
        String lineSeparator = System.getProperty("line.separator");
        if (logger.isDebugEnabled()) {
            logger.debug("multiline reply; last line should start with ->" + lastLineStarts + "<-");
            logger.debug("lenght of line.separator on this OS: " + lineSeparator.length());
        }
        StringBuffer buf = new StringBuffer(message);
        for (;;) {
            logger.debug("read line");
            line = input.readLine();

            //end of stream
            if (line == null) {
                throw new EOFException();
            }

            //for compatibility with GT2.0 wuftp server
            //which is incorrectly inserting \0 between lines
            line = ignoreLeading0(line);
            if (logger.isDebugEnabled()) {
                logger.debug("line : ->" + line + "<-");
            }
            buf.append(lineSeparator).append(line);

            if (line.startsWith(lastLineStarts)) {
                logger.debug("end reached");
                break;
            }
        }
        message = buf.toString();

    } else {
        throw new FTPReplyParseException(FTPReplyParseException.UNEXPECTED_4TH_CHAR,
                "Here's the incorrect line ->" + line + "<-");
    }
}