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:org.apache.hawq.pxf.service.io.GPDBWritableTest.java

private DataInput buildStream(int[] data, boolean throwException) throws Exception {
    inputStream = mock(DataInput.class);
    ongoing = when(inputStream.readInt());
    for (int b : data) {
        ongoing = ongoing.thenReturn(b);
    }/*from  www  . j  a v a 2 s.c om*/

    if (throwException) {
        ongoing.thenThrow(new EOFException());
    }
    return inputStream;
}

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

/**
 * {@inheritDoc}//from  w w w.j ava2  s .c  o m
 */
public char readChar() throws IOException {
    fileSize -= 1;
    if (fileSize < 0) {
        throw new EOFException();
    }
    return dataInput.readChar();
}

From source file:org.gcaldaemon.core.servlet.ServletListener.java

private final void processRequest(HttpServletRequest req, HttpServletResponse rsp, boolean getMethod)
        throws ServletException, IOException {
    try {/*from   ww w .  j  a va 2s .  com*/

        // Transform HttpServletRequest to Request
        Request request = new Request();
        request.method = getMethod ? GET_METHOD : PUT_METHOD;

        // Transform URL
        request.url = req.getPathInfo();
        int i = request.url.indexOf('@');
        if (i != -1) {
            request.url = request.url.substring(0, i) + "%40" + request.url.substring(i + 1);
        }

        // Get the properties of the request
        HashMap properties = new HashMap();
        Enumeration names = req.getHeaderNames();
        String header;
        while (names.hasMoreElements()) {
            header = (String) names.nextElement();
            properties.put(formatString(header.toCharArray()), req.getHeader(header));
        }

        // Transform username and password
        header = (String) properties.get(AUTHORIZATION);
        if (header != null && header.startsWith(BASIC)) {
            header = StringUtils.decodeBASE64(header.substring(6));
            int n = header.indexOf(COLON);
            if (n != 0) {
                request.username = header.substring(0, n);
            }
            if (n != header.length() - 1) {
                request.password = header.substring(n + 1);
            }
        }

        // Get Content-Length header
        int contentLength = 0;
        header = (String) properties.get(CONTENT_LENGTH);
        if (header != null && header.length() != 0) {
            contentLength = Integer.parseInt(header);
        }

        // Read body
        if (contentLength != 0) {
            int packet, readed = 0;
            request.body = new byte[contentLength];
            ServletInputStream in = req.getInputStream();
            while (readed != contentLength) {
                packet = in.read(request.body, readed, contentLength - readed);
                if (packet == -1) {
                    throw new EOFException();
                }
                readed += packet;
            }
        }

        // Redirect request to superclass
        Response response;
        if (getMethod) {
            response = doGet(request);
        } else {
            response = doPut(request);
        }

        // Set response status
        rsp.setStatus(response.status);

        // Add unauthorized header and realm
        if (response.status == STATUS_UNAUTHORIZED) {
            String realm = null;
            int s, e = request.url.indexOf("%40");
            if (e != -1) {
                s = request.url.lastIndexOf('/', e);
                if (s != -1) {
                    realm = request.url.substring(s + 1, e).replace('.', ' ');
                }
            }
            if (realm == null) {
                s = request.url.indexOf("private");
                if (s != -1) {
                    e = request.url.indexOf('/', s + 7);
                    if (e != -1) {
                        realm = request.url.substring(s + 8, e);
                    }
                }
            }
            if (realm == null || realm.length() == 0) {
                realm = "Google Account";
            }
            rsp.addHeader("WWW-Authenticate", "Basic realm=\"" + realm + '\"');
        }

        // Write body
        ServletOutputStream out = null;
        try {
            out = rsp.getOutputStream();
            out.write(response.body);
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (Exception ignored) {
                }
            }
        }

    } catch (Exception processingError) {
        throw new ServletException("Unable to process " + req.getMethod() + " request!", processingError);
    }
}

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

/**
 * {@inheritDoc}/*from ww  w .  j a  v  a 2s. c  o m*/
 */
public int readInt() throws IOException {

    fileSize -= 4;
    if (fileSize < 0) {
        throw new EOFException();
    }
    return dataInput.readInt();
}

From source file:com.moilioncircle.redis.replicator.io.AsyncBufferedInputStream.java

@Override
public int read() throws IOException {
    this.lock.lock();
    try {//w ww. ja  v a2  s.  c  om
        //
        while (this.ringBuffer.isEmpty()) {
            if (this.exception != null)
                throw this.exception;
            this.bufferNotEmpty.awaitUninterruptibly();
            if (this.closed.get())
                throw new EOFException();
        }

        //
        final int r = this.ringBuffer.read();
        this.bufferNotFull.signal();
        return r;
    } finally {
        this.lock.unlock();
    }
}

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

/**
 * {@inheritDoc}/*from  ww  w.ja  v a  2s  .  c om*/
 */
public long readLong() throws IOException {
    fileSize -= 8;
    if (fileSize < 0) {
        throw new EOFException();
    }
    return dataInput.readLong();
}

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

/**
 * {@inheritDoc}//from  ww w. j  ava 2 s.  com
 */
public float readFloat() throws IOException {
    fileSize -= 4;
    if (fileSize < 0) {
        throw new EOFException();
    }
    return dataInput.readFloat();
}

From source file:org.apache.tika.parser.wordperfect.WPInputStream.java

/**
 * Reads a byte/*from w w w  .j  a  v  a 2 s  .c o  m*/
 * @return byte read
 * @throws IOException if not enough bytes remain
 */
public int readWP() throws IOException {
    int i = read();
    if (i == -1) {
        throw new EOFException();
    }
    return i;
}

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

/**
 * {@inheritDoc}//from   w  ww  .  j av  a 2s.  co  m
 */
public double readDouble() throws IOException {
    fileSize -= 8;
    if (fileSize < 0) {
        throw new EOFException();
    }
    return dataInput.readDouble();
}

From source file:com.moilioncircle.redis.replicator.io.AsyncBufferedInputStream.java

@Override
public int read(byte b[], int off, int len) throws IOException {
    this.lock.lock();
    try {/*from  w w  w  . ja  v  a 2 s  .c o  m*/
        //
        while (this.ringBuffer.isEmpty()) {
            if (this.exception != null)
                throw this.exception;
            this.bufferNotEmpty.awaitUninterruptibly();
            if (this.closed.get())
                throw new EOFException();
        }

        //
        final int r = this.ringBuffer.read(b, off, len);
        this.bufferNotFull.signal();
        return r;
    } finally {
        this.lock.unlock();
    }
}