List of usage examples for java.io EOFException EOFException
public EOFException()
EOFException
with null
as its error detail message. From source file:com.android.volley.toolbox.DiskBasedCache.java
/** * Simple wrapper around {@link InputStream#read()} that throws EOFException * instead of returning -1./* w ww .j av a 2 s . c o m*/ */ private static int read(InputStream is) throws IOException { int b = is.read(); if (b == -1) { throw new EOFException(); } return b; }
From source file:org.wso2.carbon.analytics.datasource.core.util.GenericUtils.java
public static Object deserializeObject(InputStream in) throws IOException { if (in == null) { return null; }//from w ww. j a v a 2s . c o m if (in.available() == 0) { throw new EOFException(); } DataInputStream dataIn = new DataInputStream(in); int size = dataIn.readInt(); byte[] buff = new byte[size]; dataIn.readFully(buff); Kryo kryo = kryoTL.get(); try (Input input = new Input(buff)) { return kryo.readClassAndObject(input); } }
From source file:com.bstek.dorado.view.config.attachment.JavaScriptParser.java
public char read() throws EOFException { if (cursor > buf.length() - 1) { throw new EOFException(); } else {/*from ww w. ja va2 s .c om*/ return buf.charAt(cursor++); } }
From source file:org.commoncrawl.hadoop.io.deprecated.ArcFileReader.java
private void skipBytes(InputStream in, int n) throws IOException { while (n > 0) { int len = in.read(tmpbuf, 0, n < tmpbuf.length ? n : tmpbuf.length); if (len == -1) { throw new EOFException(); }//from w w w . j a v a 2 s . co m n -= len; } }
From source file:org.commoncrawl.util.StreamingArcFileReader.java
private int readInflatedBytes(byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > b.length - off) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; }//from www . jav a2 s .c o m try { //try to output some bytes from the inflater int n; while ((n = _inflater.inflate(b, off, len)) == 0) { if (_inflater.finished() || _inflater.needsDictionary()) { // these are EOS conditions //first reclaim any remaining data from the inflater ... if (_inflater.getRemaining() != 0) { if (_activeInputBuffer == null) { throw new RuntimeException("Bad State"); } else { // increment bytes available ... synchronized (this) { _bytesAvailable += _inflater.getRemaining(); _streamPos -= _inflater.getRemaining(); } // and reposition cursor ... _activeInputBuffer.position(_activeInputBuffer.position() - _inflater.getRemaining()); } } // b return -1; } // we produced no output .. check to see if have more input to add if (_inflater.needsInput()) { if (_activeInputBuffer == null || _activeInputBuffer.remaining() == 0) { _activeInputBuffer = null; if (_consumerQueue.size() != 0) { BufferItem nextItem = null; try { nextItem = _consumerQueue.take(); } catch (InterruptedException e) { LOG.error(StringUtils.stringifyException(e)); } if (nextItem._buffer == null) { throw new EOFException(); } else { _activeInputBuffer = nextItem._buffer; } } } if (_activeInputBuffer == null) { return 0; } else { // feed the buffer to the inflater ... _inflater.setInput(_activeInputBuffer.array(), _activeInputBuffer.position(), _activeInputBuffer.remaining()); // decrement bytes available ... synchronized (this) { _bytesAvailable -= _activeInputBuffer.remaining(); _streamPos += _activeInputBuffer.remaining(); } // and advance its position so _activeInputBuffer.position(_activeInputBuffer.position() + _activeInputBuffer.remaining()); } } } return n; } catch (DataFormatException e) { String s = e.getMessage(); throw new ZipException(s != null ? s : "Invalid ZLIB data format"); } }
From source file:com.digitalpebble.storm.crawler.protocol.http.HttpResponse.java
private static int readLine(PushbackInputStream in, StringBuffer line, boolean allowContinuedLine) throws IOException { line.setLength(0);/*from w w w. ja v a 2s . c o m*/ 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:org.gcaldaemon.core.http.HTTPListener.java
private final Request readRequest(Socket socket) throws Exception { // Open stream InputStream is = socket.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is, BUFFER_SIZE); Request request = new Request(); // Start processing - skip whitespaces char[] chars = new char[BUFFER_SIZE]; char c;//from ww w. j a v a 2 s . c om int n = 0; for (;;) { c = (char) bis.read(); if (c != CARRIAGE_RETURN && c != LINE_FEED) { chars[n++] = c; break; } } // Read HTTP-method (GET, POST, PUT, etc) for (;;) { c = (char) bis.read(); if (c == SPACE) { request.method = new String(chars, 0, n); break; } chars[n++] = c; } // Read URL and optional query-string n = 0; boolean flag = false; for (;;) { c = (char) bis.read(); if (c == CARRIAGE_RETURN || c == LINE_FEED || c == SPACE) { // End of URL flag = c == SPACE; break; } chars[n++] = c; } int contentLength = 0; // URL always encoded in US-ASCII request.url = new String(chars, 0, n); // Read optional protocol n = 0; if (flag) { for (;;) { c = (char) bis.read(); if (c == CARRIAGE_RETURN || c == LINE_FEED) { // End of protocol bis.read(); break; } chars[n++] = c; } // Read headers String headerName; byte caseMode; for (;;) { for (;;) { c = (char) bis.read(); if ((c == CARRIAGE_RETURN)) { // Do nothing } else { if (c == LINE_FEED) { // End of headers flag = false; } break; } } if (!flag) { break; } // Read header name n = 0; headerName = null; caseMode = UPPER_CASE; for (;;) { if (c == COLON) { headerName = new String(chars, 0, n); break; } if (c == MINUS) { caseMode = 1; c = (char) bis.read(); continue; } if (caseMode != BOTH_CASE) { if (caseMode == UPPER_CASE) { if ((c >= LOWER_A) && (c <= LOWER_Z)) { chars[n++] = (char) (c + CASE_OFFSET); } else { chars[n++] = c; } caseMode = BOTH_CASE; } else { if ((c >= UPPER_A) && (c <= UPPER_Z)) { chars[n++] = (char) (c - CASE_OFFSET); } else { chars[n++] = c; } } } else { chars[n++] = c; } c = (char) bis.read(); } // Read header's value n = 0; c = (char) bis.read(); while (c == SPACE || c == TABULATOR) { c = (char) bis.read(); } for (;;) { if (c == CARRIAGE_RETURN) { } else { if (c == LINE_FEED) { break; } chars[n++] = c; } c = (char) bis.read(); } if (headerName.equals(AUTHORIZATION)) { headerName = new String(chars, 0, n); if (headerName.startsWith(BASIC)) { headerName = StringUtils.decodeBASE64(headerName.substring(6)); n = headerName.indexOf(COLON); if (n != 0) { request.username = headerName.substring(0, n); } if (n != headerName.length() - 1) { request.password = headerName.substring(n + 1); } } } else { if (headerName.equals(CONTENT_LENGTH)) { contentLength = Integer.parseInt(new String(chars, 0, n)); } } } } // Read body if (contentLength != 0) { if (contentLength > MAX_CONTENT_LENGTH) { throw new IllegalArgumentException( "Too large message body (" + contentLength + ">" + MAX_CONTENT_LENGTH + ")!"); } int packet, readed = 0; request.body = new byte[contentLength]; while (readed != contentLength) { packet = bis.read(request.body, readed, contentLength - readed); if (packet == -1) { throw new EOFException(); } readed += packet; } } // Return request return request; }
From source file:org.jahia.utils.zip.legacy.ZipInputStream.java
private void readFully(byte[] b, int off, int len) throws IOException { while (len > 0) { int n = in.read(b, off, len); if (n == -1) { throw new EOFException(); }/* w ww . j ava 2 s . co m*/ off += n; len -= n; } }
From source file:edu.uiuc.ncsa.myproxy.MyProxyLogon.java
/** * Logs on to the MyProxy server by issuing the MyProxy GET command. *///from ww w.j a va2 s . c om public void logon() throws IOException, GeneralSecurityException { String line; char response; if (this.state != State.CONNECTED) { this.connect(); } try { this.socketOut.write('0'); this.socketOut.flush(); this.socketOut.write(VERSION.getBytes()); this.socketOut.write('\n'); this.socketOut.write(GETCOMMAND.getBytes()); this.socketOut.write('\n'); this.socketOut.write(USERNAME.getBytes()); this.socketOut.write(this.username.getBytes()); this.socketOut.write('\n'); this.socketOut.write(PASSPHRASE.getBytes()); this.socketOut.write(this.passphrase.getBytes()); this.socketOut.write('\n'); this.socketOut.write(LIFETIME.getBytes()); this.socketOut.write(Integer.toString(this.lifetime).getBytes()); this.socketOut.write('\n'); if (this.credname != null) { this.socketOut.write(CREDNAME.getBytes()); this.socketOut.write(this.credname.getBytes()); this.socketOut.write('\n'); } if (this.requestTrustRoots) { this.socketOut.write(TRUSTROOTS.getBytes()); this.socketOut.write("1\n".getBytes()); } this.socketOut.flush(); line = readLine(this.socketIn); if (line == null) { throw new EOFException(); } if (!line.equals(VERSION)) { throw new ProtocolException("bad MyProxy protocol VERSION string: " + line); } line = readLine(this.socketIn); if (line == null) { throw new EOFException(); } if (!line.startsWith(RESPONSE) || line.length() != RESPONSE.length() + 1) { throw new ProtocolException("bad MyProxy protocol RESPONSE string: " + line); } response = line.charAt(RESPONSE.length()); if (response == '1') { StringBuffer errString; errString = new StringBuffer("MyProxy logon failed"); while ((line = readLine(this.socketIn)) != null) { if (line.startsWith(ERROR)) { errString.append('\n'); errString.append(line.substring(ERROR.length())); } } throw new FailedLoginException(errString.toString()); } else if (response == '2') { throw new ProtocolException("MyProxy authorization RESPONSE not implemented"); } else if (response != '0') { throw new ProtocolException("unknown MyProxy protocol RESPONSE string: " + line); } while ((line = readLine(this.socketIn)) != null) { if (line.startsWith(TRUSTROOTS)) { String filenameList = line.substring(TRUSTROOTS.length()); this.trustrootFilenames = filenameList.split(","); this.trustrootData = new String[this.trustrootFilenames.length]; for (int i = 0; i < this.trustrootFilenames.length; i++) { String lineStart = "FILEDATA_" + this.trustrootFilenames[i] + "="; line = readLine(this.socketIn); if (line == null) { throw new EOFException(); } if (!line.startsWith(lineStart)) { throw new ProtocolException("bad MyProxy protocol RESPONSE: expecting " + lineStart + " but received " + line); } this.trustrootData[i] = new String(Base64.decodeBase64(line.substring(lineStart.length()))); } } } this.state = State.LOGGEDON; } catch (Throwable t) { handleException(t, getClass().getSimpleName() + " logon failed."); } }
From source file:AddressBookMIDlet.java
/** * Create a RecordEnumeration from the network. * //from ww w. j av a2s. co m * Query a network service for addresses matching the specified criteria. * The base URL of the service has the query parameters appended. The * request is made and the contents parsed into a Vector which is used as * the basis of the RecordEnumeration. lastname the last name to search for * firstname the first name to search for sortorder the order in which to * sort 1 is by last name, 0 is by first name */ NetworkQuery(String firstname, String lastname, int sortorder) { HttpConnection c = null; int ch; InputStream is = null; InputStreamReader reader; String url; // Format the complete URL to request buffer.setLength(0); buffer.append(baseurl); buffer.append("?last="); buffer.append((lastname != null) ? lastname : empty); buffer.append("&first="); buffer.append((firstname != null) ? firstname : empty); buffer.append("&sort=" + sortorder); url = buffer.toString(); // Open the connection to the service try { c = open(url); results.removeAllElements(); /* * Open the InputStream and construct a reader to convert from bytes * to chars. */ is = c.openInputStream(); reader = new InputStreamReader(is); while (true) { int i = 0; fields[0] = empty; fields[1] = empty; fields[2] = empty; do { buffer.setLength(0); while ((ch = reader.read()) != -1 && (ch != ',') && (ch != '\n')) { if (ch == '\r') { continue; } buffer.append((char) ch); } if (ch == -1) { throw new EOFException(); } if (buffer.length() > 0) { if (i < fields.length) { fields[i++] = buffer.toString(); } } } while (ch != '\n'); if (fields[0].length() > 0) { results.addElement(SimpleRecord.createRecord(fields[0], fields[1], fields[2])); } } } catch (Exception e) { } finally { try { if (is != null) { is.close(); } if (c != null) { c.close(); } } catch (Exception e) { } } resultsEnumeration = results.elements(); }