java.io.EOFException Java Examples
The following examples show how to use
java.io.EOFException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndexConfiguration.java From localization_nifi with Apache License 2.0 | 6 votes |
private Long getFirstEntryTime(final File provenanceLogFile) { if (provenanceLogFile == null) { return null; } try (final RecordReader reader = RecordReaders.newRecordReader(provenanceLogFile, null, Integer.MAX_VALUE)) { final StandardProvenanceEventRecord firstRecord = reader.nextRecord(); if (firstRecord == null) { return provenanceLogFile.lastModified(); } return firstRecord.getEventTime(); } catch (final FileNotFoundException | EOFException fnf) { return null; // file no longer exists or there's no record in this file } catch (final IOException ioe) { logger.warn("Failed to read first entry in file {} due to {}", provenanceLogFile, ioe.toString()); logger.warn("", ioe); return null; } }
Example #2
Source File: DiskLruCache.java From zone-sdk with MIT License | 6 votes |
/** * Returns the ASCII characters up to but not including the next "\r\n", or * "\n". * * @throws java.io.EOFException if the stream is exhausted before the next newline * character. */ public static String readAsciiLine(InputStream in) throws IOException { // TODO: support UTF-8 here instead StringBuilder result = new StringBuilder(80); while (true) { int c = in.read(); if (c == -1) { throw new EOFException(); } else if (c == '\n') { break; } result.append((char) c); } int length = result.length(); if (length > 0 && result.charAt(length - 1) == '\r') { result.setLength(length - 1); } return result.toString(); }
Example #3
Source File: SSLSocketChannel2.java From RipplePower with Apache License 2.0 | 6 votes |
public int write( ByteBuffer src ) throws IOException { if( !isHandShakeComplete() ) { processHandshake(); return 0; } // assert ( bufferallocations > 1 ); //see #190 //if( bufferallocations <= 1 ) { // createBuffers( sslEngine.getSession() ); //} int num = socketChannel.write( wrap( src ) ); if (writeEngineResult.getStatus() == SSLEngineResult.Status.CLOSED) { throw new EOFException("Connection is closed"); } return num; }
Example #4
Source File: SawReader.java From tablesaw with Apache License 2.0 | 6 votes |
private static DateColumn readLocalDateColumn(String fileName, ColumnMetadata metadata) throws IOException { DateColumn dates = DateColumn.create(metadata.getName()); try (FileInputStream fis = new FileInputStream(fileName); SnappyFramedInputStream sis = new SnappyFramedInputStream(fis, true); DataInputStream dis = new DataInputStream(sis)) { boolean EOF = false; while (!EOF) { try { int cell = dis.readInt(); dates.appendInternal(cell); } catch (EOFException e) { EOF = true; } } } return dates; }
Example #5
Source File: WindowedSeekableByteChannel.java From emissary with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} * * @see java.nio.channels.SeekableByteChannel#position(long) */ @Override public SeekableByteChannel position(final long newPosition) throws IOException { // if data hasn't been read in, we'll have to do it below and see if it's available if (this.endofchannel && (newPosition > this.estimatedLength)) { throw new EOFException("Position is beyond EOF"); } long tgtPosition = newPosition - this.minposition; // see if we can move there if (tgtPosition < 0) { throw new IllegalStateException("Cannot move to " + newPosition + " in the stream. Minimum position is " + this.minposition); } while (!setOffset(tgtPosition) && !this.endofchannel) { realignBuffers(); tgtPosition = newPosition - this.minposition; } if (newPosition > this.estimatedLength) { throw new EOFException("Position is beyond EOF"); } return this; }
Example #6
Source File: MixedEndianDataInputStream.java From PyramidShader with GNU General Public License v3.0 | 6 votes |
/** * Reads an eight byte signed <code>int</code> from the underlying input * stream in little endian order, low byte first. * * @return the <code>int</code> read. * @exception EOFException if the end of the underlying input stream has * been reached * @exception IOException if the underlying stream throws an IOException. */ public long readLittleEndianLong() throws IOException { long byte1 = in.read(); long byte2 = in.read(); long byte3 = in.read(); long byte4 = in.read(); long byte5 = in.read(); long byte6 = in.read(); long byte7 = in.read(); long byte8 = in.read(); if (byte8 == -1) { throw new EOFException(); } return (byte8 << 56) + (byte7 << 48) + (byte6 << 40) + (byte5 << 32) + (byte4 << 24) + (byte3 << 16) + (byte2 << 8) + byte1; }
Example #7
Source File: IFileInputStream.java From incubator-tez with Apache License 2.0 | 6 votes |
/** * Close the input stream. Note that we need to read to the end of the * stream to validate the checksum. */ @Override public void close() throws IOException { if (curReadahead != null) { curReadahead.cancel(); } if (currentOffset < dataLength) { byte[] t = new byte[Math.min((int) (Integer.MAX_VALUE & (dataLength - currentOffset)), 32 * 1024)]; while (currentOffset < dataLength) { int n = read(t, 0, t.length); if (0 == n) { throw new EOFException("Could not validate checksum"); } } } in.close(); }
Example #8
Source File: ApkLibraryInstallerWithSplitsTest.java From ReLinker with Apache License 2.0 | 6 votes |
private String fileToString(final File file) throws IOException { final long size = file.length(); if (size > Integer.MAX_VALUE) { throw new IOException("Can't read a file larger than Integer.MAX_VALUE"); } final byte[] data = new byte[(int) size]; final FileInputStream in = new FileInputStream(file); try { int bytesRead = 0; while (bytesRead < size) { int read = in.read(data, bytesRead, (int) size - bytesRead); if (read == -1) { throw new EOFException(); } bytesRead += read; } return new String(data); } finally { in.close(); } }
Example #9
Source File: StreamUtils.java From nifi with Apache License 2.0 | 6 votes |
/** * Reads <code>byteCount</code> bytes of data from the given InputStream, writing to the provided byte array. * * @param source the InputStream to read from * @param destination the destination for the data * @param byteCount the number of bytes to copy * * @throws IllegalArgumentException if the given byte array is smaller than <code>byteCount</code> elements. * @throws EOFException if the InputStream does not have <code>byteCount</code> bytes in the InputStream * @throws IOException if unable to read from the InputStream */ public static void read(final InputStream source, final byte[] destination, final int byteCount) throws IOException { if (destination.length < byteCount) { throw new IllegalArgumentException(); } int bytesRead = 0; int len; while (bytesRead < byteCount) { len = source.read(destination, bytesRead, byteCount - bytesRead); if (len < 0) { throw new EOFException("Expected to consume " + byteCount + " bytes but consumed only " + bytesRead); } bytesRead += len; } }
Example #10
Source File: ImageInputStreamImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void readFully(byte[] b, int off, int len) throws IOException { // Fix 4430357 - if off + len < 0, overflow occurred if (off < 0 || len < 0 || off + len > b.length || off + len < 0) { throw new IndexOutOfBoundsException ("off < 0 || len < 0 || off + len > b.length!"); } while (len > 0) { int nbytes = read(b, off, len); if (nbytes == -1) { throw new EOFException(); } off += nbytes; len -= nbytes; } }
Example #11
Source File: DexBackedDexFile.java From ZjDroid with Apache License 2.0 | 6 votes |
public static DexBackedDexFile fromInputStream(@Nonnull Opcodes opcodes, @Nonnull InputStream is) throws IOException { if (!is.markSupported()) { throw new IllegalArgumentException("InputStream must support mark"); } is.mark(44); byte[] partialHeader = new byte[44]; try { ByteStreams.readFully(is, partialHeader); } catch (EOFException ex) { throw new NotADexFile("File is too short"); } finally { is.reset(); } verifyMagicAndByteOrder(partialHeader, 0); byte[] buf = ByteStreams.toByteArray(is); return new DexBackedDexFile(opcodes, buf, 0, false); }
Example #12
Source File: Decoder.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
protected final int peek(OctetBufferListener octetBufferListener) throws IOException { if (_octetBufferOffset < _octetBufferEnd) { return _octetBuffer[_octetBufferOffset] & 0xFF; } else { if (octetBufferListener != null) { octetBufferListener.onBeforeOctetBufferOverwrite(); } _octetBufferEnd = _s.read(_octetBuffer); if (_octetBufferEnd < 0) { throw new EOFException(CommonResourceBundle.getInstance().getString("message.EOF")); } _octetBufferOffset = 0; return _octetBuffer[0] & 0xFF; } }
Example #13
Source File: TFile.java From hadoop-gpu with Apache License 2.0 | 6 votes |
/** * check whether we have already successfully obtained the key. It also * initializes the valueInputStream. */ void checkKey() throws IOException { if (klen >= 0) return; if (atEnd()) { throw new EOFException("No key-value to read"); } klen = -1; vlen = -1; valueChecked = false; klen = Utils.readVInt(blkReader); blkReader.readFully(keyBuffer, 0, klen); valueBufferInputStream.reset(blkReader); if (valueBufferInputStream.isLastChunk()) { vlen = valueBufferInputStream.getRemain(); } }
Example #14
Source File: SerialFilterTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Read objects from the serialized stream, validated with the filter. * * @param bytes a byte array to read objects from * @param filter the ObjectInputFilter * @return the object deserialized if any * @throws IOException can be thrown */ static Object validate(byte[] bytes, ObjectInputFilter filter) throws IOException { try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais)) { ObjectInputFilter.Config.setObjectInputFilter(ois, filter); Object o = ois.readObject(); return o; } catch (EOFException eof) { // normal completion } catch (ClassNotFoundException cnf) { Assert.fail("Deserializing", cnf); } return null; }
Example #15
Source File: ByteBufJsonParser.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
/** * Reads the next character into {@link #currentChar}. * * @param level the current level of nesting. * @throws EOFException if more input is needed. */ private void readNextChar(final JsonLevel level) throws EOFException { int readerIndex = content.readerIndex(); int lastWsIndex = content.forEachByte(wsProcessor); if (lastWsIndex == -1 && level != null) { throw NEED_MORE_DATA; } if (lastWsIndex > readerIndex) { this.content.skipBytes(lastWsIndex - readerIndex); this.content.discardReadBytes(); } this.currentChar = this.content.readByte(); }
Example #16
Source File: ReplaySyncReplicationWALCallable.java From hbase with Apache License 2.0 | 5 votes |
private Reader getReader(String wal) throws IOException { Path path = new Path(rs.getWALRootDir(), wal); long length = rs.getWALFileSystem().getFileStatus(path).getLen(); try { RecoverLeaseFSUtils.recoverFileLease(fs, path, conf); return WALFactory.createReader(rs.getWALFileSystem(), path, rs.getConfiguration()); } catch (EOFException e) { if (length <= 0) { LOG.warn("File is empty. Could not open {} for reading because {}", path, e); return null; } throw e; } }
Example #17
Source File: ImageInputStreamImpl.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public int readUnsignedByte() throws IOException { int ch = this.read(); if (ch < 0) { throw new EOFException(); } return ch; }
Example #18
Source File: MDNSDiscover.java From tinydnssd with MIT License | 5 votes |
private static TXT decodeTXT(byte[] data) throws IOException { TXT txt = new TXT(); txt.dict = new HashMap<>(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); while (true) { int length; try { length = dis.readUnsignedByte(); } catch (EOFException e) { return txt; } byte[] segmentBytes = new byte[length]; dis.readFully(segmentBytes); String segment = new String(segmentBytes); int pos = segment.indexOf('='); String key, value = null; if (pos != -1) { key = segment.substring(0, pos); value = segment.substring(pos + 1); } else { key = segment; } if (DEBUG) System.out.println(key + "=" + value); if (!txt.dict.containsKey(key)) { // from RFC6763 // If a client receives a TXT record containing the same key more than once, then // the client MUST silently ignore all but the first occurrence of that attribute." txt.dict.put(key, value); } } }
Example #19
Source File: Scanner.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Extract a block comment from the input buffer. **/ private String getBlockComment () throws IOException { StringBuffer sb = new StringBuffer ("/*"); try { boolean done = false; readChar (); sb.append (data.ch); while (!done) { while (data.ch != '*') { readChar (); sb.append (data.ch); } readChar (); sb.append (data.ch); if (data.ch == '/') done = true; } } catch (EOFException e) { ParseException.unclosedComment (data.filename); throw e; } return sb.toString (); }
Example #20
Source File: StandardLoadBalanceProtocol.java From nifi with Apache License 2.0 | 5 votes |
private void completeTransaction(final InputStream in, final OutputStream out, final String peerDescription, final List<RemoteFlowFileRecord> flowFilesReceived, final String connectionId, final long startTimestamp, final LoadBalancedFlowFileQueue flowFileQueue) throws IOException { final int completionIndicator = in.read(); if (completionIndicator < 0) { throw new EOFException("Expected to receive a Transaction Completion Indicator from Peer " + peerDescription + " but encountered EOF"); } if (completionIndicator == ABORT_TRANSACTION) { throw new TransactionAbortedException("Peer " + peerDescription + " chose to Abort Load Balance Transaction"); } if (completionIndicator != COMPLETE_TRANSACTION) { logger.debug("Expected to receive Transaction Completion Indicator from Peer " + peerDescription + " but instead received a value of " + completionIndicator + ". Sending back an Abort " + "Transaction Flag."); out.write(ABORT_TRANSACTION); out.flush(); throw new IOException("Expected to receive Transaction Completion Indicator from Peer " + peerDescription + " but instead received a value of " + completionIndicator); } logger.debug("Received Complete Transaction indicator from Peer {}", peerDescription); registerReceiveProvenanceEvents(flowFilesReceived, peerDescription, connectionId, startTimestamp); updateFlowFileRepository(flowFilesReceived, flowFileQueue); transferFlowFilesToQueue(flowFilesReceived, flowFileQueue); out.write(CONFIRM_COMPLETE_TRANSACTION); out.flush(); }
Example #21
Source File: InputStreamStreamInput.java From crate with Apache License 2.0 | 5 votes |
@Override public void readBytes(byte[] b, int offset, int len) throws IOException { if (len < 0) throw new IndexOutOfBoundsException(); final int read = Streams.readFully(is, b, offset, len); if (read != len) { throw new EOFException(); } }
Example #22
Source File: AbstractDataStream.java From jpexs-decompiler with GNU General Public License v3.0 | 5 votes |
@Override public int readUI16() throws IOException { try { return (readUI8() | (readUI8() << 8)) & 0xffff; } catch (EOFException ex) { return -1; } }
Example #23
Source File: Decoder.java From hottub with GNU General Public License v2.0 | 5 votes |
protected final int read() throws IOException { if (_octetBufferOffset < _octetBufferEnd) { return _octetBuffer[_octetBufferOffset++] & 0xFF; } else { _octetBufferEnd = _s.read(_octetBuffer); if (_octetBufferEnd < 0) { throw new EOFException(CommonResourceBundle.getInstance().getString("message.EOF")); } _octetBufferOffset = 1; return _octetBuffer[0] & 0xFF; } }
Example #24
Source File: MemoryTTFDataStream.java From gcs with Mozilla Public License 2.0 | 5 votes |
/** * Read an unsigned short. * * @return An unsigned short. * @throws IOException If there is an error reading the data. */ @Override public int readUnsignedShort() throws IOException { int ch1 = this.read(); int ch2 = this.read(); if ((ch1 | ch2) < 0) { throw new EOFException(); } return (ch1 << 8) + (ch2 << 0); }
Example #25
Source File: OLParser.java From jolie with GNU Lesser General Public License v2.1 | 5 votes |
private OLSyntaxNode parseInVariablePathProcess( boolean withConstruct ) throws IOException, ParserException { OLSyntaxNode ret; LinkedList< Scanner.Token > tokens = new LinkedList<>(); try { if( withConstruct ) { eat( Scanner.TokenType.LPAREN, "expected (" ); while( token.isNot( Scanner.TokenType.LCURLY ) ) { tokens.add( token ); nextTokenNotEOF(); } // TODO transfer this whole buggy thing to the OOIT tokens.removeLast(); // nextToken(); } else { while( token.isNot( Scanner.TokenType.LCURLY ) ) { tokens.add( token ); nextTokenNotEOF(); } } } catch( EOFException eof ) { throwException( "with clause requires a { at the beginning of its body" ); } inVariablePaths.add( tokens ); eat( Scanner.TokenType.LCURLY, "expected {" ); ret = parseProcess(); eat( Scanner.TokenType.RCURLY, "expected }" ); inVariablePaths.remove( inVariablePaths.size() - 1 ); return ret; }
Example #26
Source File: BlobUtils.java From flink with Apache License 2.0 | 5 votes |
/** * Auxiliary method to read a particular number of bytes from an input stream. This method blocks until the * requested number of bytes have been read from the stream. If the stream cannot offer enough data, an * {@link EOFException} is thrown. * * @param inputStream The input stream to read the data from. * @param buf The buffer to store the read data. * @param off The offset inside the buffer. * @param len The number of bytes to read from the stream. * @param type The name of the type, to throw a good error message in case of not enough data. * @throws IOException * Thrown if I/O error occurs while reading from the stream or the stream cannot offer enough data. */ static void readFully(InputStream inputStream, byte[] buf, int off, int len, String type) throws IOException { int bytesRead = 0; while (bytesRead < len) { final int read = inputStream.read(buf, off + bytesRead, len - bytesRead); if (read < 0) { throw new EOFException("Received an incomplete " + type); } bytesRead += read; } }
Example #27
Source File: NioTcpClient.java From dnsjava with BSD 2-Clause "Simplified" License | 5 votes |
void send() throws IOException { if (sendDone) { return; } verboseLog( "TCP write", channel.socket().getLocalSocketAddress(), channel.socket().getRemoteSocketAddress(), queryData); // combine length+message to avoid multiple TCP packets // https://tools.ietf.org/html/rfc7766#section-8 ByteBuffer buffer = ByteBuffer.allocate(queryData.length + 2); buffer.put((byte) (queryData.length >>> 8)); buffer.put((byte) (queryData.length & 0xFF)); buffer.put(queryData); buffer.flip(); while (buffer.hasRemaining()) { long n = channel.write(buffer); if (n < 0) { throw new EOFException(); } } sendDone = true; }
Example #28
Source File: VarInt.java From RipplePower with Apache License 2.0 | 5 votes |
/** * Creates a new VarInt from a byte array in little-endian format * * @param buf * Byte array * @param offset * Starting offset into the array * @throws EOFException * Buffer is too small */ public VarInt(byte[] buf, int offset) throws EOFException { if (offset > buf.length) throw new EOFException("End-of-data while processing VarInt"); int first = 0x00FF & (int) buf[offset]; if (first < 253) { // 8 bits. value = first; encodedSize = 1; } else if (first == 253) { // 16 bits. if (offset + 2 > buf.length) throw new EOFException("End-of-data while processing VarInt"); value = (0x00FF & (int) buf[offset + 1]) | ((0x00FF & (int) buf[offset + 2]) << 8); encodedSize = 3; } else if (first == 254) { // 32 bits. if (offset + 5 > buf.length) throw new EOFException("End-of-data while processing VarInt"); value = Helper.readUint32LE(buf, offset + 1); encodedSize = 5; } else { // 64 bits. if (offset + 9 > buf.length) throw new EOFException("End-of-data while processing VarInt"); value = Helper.readUint64LE(buf, offset + 1); encodedSize = 9; } }
Example #29
Source File: ValueServerTest.java From astor with GNU General Public License v2.0 | 5 votes |
public void testEmptyReplayFile() { try { URL url = getClass().getResource("emptyFile.txt"); vs.setMode(ValueServer.REPLAY_MODE); vs.setValuesFileURL(url); vs.getNext(); fail("an exception should have been thrown"); } catch (EOFException eof) { // expected behavior } catch (Exception e) { fail("wrong exception caught"); } }
Example #30
Source File: RIFFReader.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public final void readFully(byte b[], int off, int len) throws IOException { if (len < 0) throw new IndexOutOfBoundsException(); while (len > 0) { int s = read(b, off, len); if (s < 0) throw new EOFException(); if (s == 0) Thread.yield(); off += s; len -= s; } }