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:com.moilioncircle.redis.replicator.io.AsyncBufferedInputStream.java

public int write(byte b[], int off, int len) throws IOException {
    this.lock.lock();
    try {//from ww  w . ja v  a2s  . c o m
        //
        while (this.ringBuffer.isFull()) {
            this.bufferNotFull.awaitUninterruptibly();
            if (this.closed.get())
                throw new EOFException();
        }

        //
        final int w = this.ringBuffer.write(b, off, len);
        this.bufferNotEmpty.signal();
        return w;
    } finally {
        this.lock.unlock();
    }
}

From source file:org.efaps.webdav4vfs.test.ramvfs.RamFileRandomAccessContent.java

/**
 * {@inheritDoc}/* ww  w .j  ava  2  s.co m*/
 * <p>Returns the next byte on the position {@link #filePointer} within
 * {@link #buf}.</p>
 */
public int readUnsignedByte() throws EOFException {
    if (this.filePointer < this.buf.length) {
        return this.buf[this.filePointer++] & 0xFF;
    } else {
        throw new EOFException();
    }
}

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

/**
 * {@inheritDoc}/*from ww  w.ja v a2  s .  c  o m*/
 */
public String readUTF() throws IOException {
    final String token;

    // peek ahead to determine the length of the String:

    final long position = dataInput.getChannel().position();
    final int stringLength = readShort();
    dataInput.seek(position);
    fileSize -= stringLength;
    if (fileSize < 0) {
        throw new EOFException();
    }

    token = dataInput.readUTF();
    return token;

}

From source file:com.novartis.pcs.ontology.service.graph.DOTProcessImpl.java

private void copy(InputStream in) throws IOException {
    int n = 0;//from w  w  w  .j a va 2 s.  c o m
    count = 0;
    while ((n = in.read(buffer, count, buffer.length - count)) != -1) {
        count += n;

        if (end()) {
            return;
        }

        if (buffer.length - count <= 4096) {
            buffer = Arrays.copyOf(buffer, buffer.length + 32768);
        }
    }

    throw new EOFException();
}

From source file:org.apache.shindig.gadgets.http.BasicHttpFetcherTest.java

@Test
public void testToByteArraySafeHandlesExceptionWithNoMessage() throws Exception {
    EOFException e = new EOFException();
    EasyMock.expect(mockInputStream.read(EasyMock.isA(byte[].class))).andThrow(e).anyTimes();

    EasyMock.replay(mockEntity, mockInputStream);

    try {/*from   w  w w .j  a v  a2s . co m*/
        fetcher.toByteArraySafe(mockEntity);
    } catch (EOFException eofe) {
        fail("Exception Should have been caught");
    }
    EasyMock.verify(mockEntity, mockInputStream);
}

From source file:com.google.code.or.io.impl.XInputStreamImpl.java

/**
 * /*  w w  w  . j a  v  a 2 s. c  o m*/
 */
private void doFill() throws IOException {
    this.head = 0;
    this.tail = this.is.read(this.buffer, 0, this.buffer.length);
    if (this.tail <= 0)
        throw new EOFException();
}

From source file:com.digitalpebble.behemoth.io.warc.HttpResponse.java

private static int readLine(PushbackInputStream in, StringBuilder line, boolean allowContinuedLine)
        throws IOException {
    line.setLength(0);//from   ww w .  ja  v  a2  s  . com
    for (int c = in.read(); c != -1; c = in.read()) {
        switch (c) {
        case '\r':
            if (peek(in) == '\n') {
                in.read();
            }
        case '\n':
            if (line.length() > 0) {
                // at EOL -- check for continued line if the current
                // (possibly continued) line wasn't blank
                if (allowContinuedLine)
                    switch (peek(in)) {
                    case ' ':
                    case '\t': // line is continued
                        in.read();
                        continue;
                    }
            }
            return line.length(); // else complete
        default:
            line.append((char) c);
        }
    }
    throw new EOFException();
}

From source file:com.zju.ccnt.or.net.impl.XInputStreamImpl.java

/**
 * /*from   w ww . j  ava 2s.c o m*/
 */
private void doFill() throws IOException {
    this.head = 0;
    this.tail = this.is.read(this.buffer, 0, this.buffer.length);
    if (this.tail < 0)
        throw new EOFException();
}

From source file:com.maverick.ssl.SSLTransportImpl.java

void processMessages() throws SSLException, EOFException {

    int type = 0;
    byte[] fragment = null;
    try {/*w ww.  j  a v a 2  s .c  om*/
        type = rawIn.read();
        int major = rawIn.read();
        int minor = rawIn.read();

        int length = rawIn.readShort();

        fragment = new byte[length];

        rawIn.readFully(fragment);

        readCipherSuite.decrypt(fragment, 0, fragment.length);

        if (readCipherSuite.getMACLength() > 0) {
            if (!readCipherSuite.verifyMAC(fragment, 0, fragment.length - readCipherSuite.getMACLength(), type,
                    incomingSequence, fragment, fragment.length - readCipherSuite.getMACLength(),
                    readCipherSuite.getMACLength())) {
                throw new SSLException(SSLException.PROTOCOL_VIOLATION,
                        Messages.getString("SSLTransport.invalidMAC")); //$NON-NLS-1$
            }

        }
    } catch (EOFException ex) {
        throw ex;
    } catch (InterruptedIOException ex) {
        throw new SSLException(SSLException.READ_TIMEOUT);
    } catch (IOException ex) {
        throw new SSLException(SSLException.UNEXPECTED_TERMINATION,
                ex.getMessage() == null ? ex.getClass().getName() : ex.getMessage());
    }

    incomingSequence++;

    // #ifdef DEBUG
    log.debug(MessageFormat.format(Messages.getString("SSLTransport.processingFragmentOfType"), //$NON-NLS-1$
            new Object[] { new Integer(type) }));
    // #endif

    switch (type) {
    case SSLHandshakeProtocol.HANDSHAKE_PROTOCOL_MSG:
        handshake.processMessage(fragment, 0, fragment.length - readCipherSuite.getMACLength());
        break;
    case CHANGE_CIPHER_SPEC_MSG:

        // #ifdef DEBUG

        log.debug(Messages.getString("SSLTransport.changingInputCipherSpec")); //$NON-NLS-1$
        // #endif

        readCipherSuite = handshake.getPendingCipherSuite();
        incomingSequence = 0;
        break;
    case ALERT_PROTOCOL:
        switch (fragment[0]) {
        case FATAL_ALERT:
            throw new SSLException(((int) (fragment[1] & 0xFF)));
        case WARNING_ALERT:
            switch (fragment[1]) {
            case SSLException.CLOSE_NOTIFY:

                // #ifdef DEBUG
                log.debug(Messages.getString("SSLTransport.remoteSideClosing")); //$NON-NLS-1$
                // #endif

                sendMessage(ALERT_PROTOCOL,
                        new byte[] { (byte) WARNING_ALERT, (byte) SSLException.CLOSE_NOTIFY });
                // close();
                // Let the InputStream know that we're at EOF
                throw new EOFException();

            default:

                // #ifdef DEBUG
                log.warn(SSLException.getDescription(fragment[1]));
                // #endif

                break;
            }

            break;
        default:

            // #ifdef DEBUG
            log.debug(MessageFormat.format(Messages.getString("SSLTransport.unexpectedAlert"), //$NON-NLS-1$
                    new Object[] { new Integer(fragment[0]), new Integer(fragment[1]) }));
            // #endif

            break;
        }
    case APPLICATION_DATA:
        sslIn.write(fragment, 0, fragment.length - readCipherSuite.getMACLength());
        break;
    default:
        throw new SSLException(SSLException.PROTOCOL_VIOLATION,
                Messages.getString("SSLTransport.unexpecedSSLProtocolType") + type); //$NON-NLS-1$

    }

}

From source file:ClassReader.java

/**
 * skip n bytes in the input stream.//from   w w w  . j a  v a 2  s  .com
 */
protected void skipFully(int n) throws IOException {
    while (n > 0) {
        int c = (int) skip(n);
        if (c <= 0) {
            throw new EOFException();
        }

        n -= c;
    }
}