public SSLSocketChannelInput(final SSLSocketChannel socketChannel) { in = new SSLSocketChannelInputStream(socketChannel); countingIn = new ByteCountingInputStream(in); this.bufferedIn = new BufferedInputStream(countingIn); }
@Override public long getBytesRead() { if (countingIn != null) { return countingIn.getBytesRead(); } return 0L; }
@Override public boolean isData() { try { byteCountingIn.mark(1); int nextByte = byteCountingIn.read(); byteCountingIn.reset(); if (nextByte < 0) { try { resetStreamForNextBlock(); } catch (final EOFException eof) { return false; } byteCountingIn.mark(1); nextByte = byteCountingIn.read(); byteCountingIn.reset(); } return nextByte >= 0; } catch (final IOException ioe) { return false; } }
public long getBytesConsumed() { return getBytesRead() + getBytesSkipped(); }
while (true) { final InputStream limitedIn = new LimitedInputStream(in, dataFrameLength); final ByteCountingInputStream bcis = new ByteCountingInputStream(limitedIn); final InputStream contentIn = compressed ? new GZIPInputStream(bcis) : bcis; final int decompressedSize = StreamUtils.fillBuffer(contentIn, buffer, false); if (bcis.getBytesRead() < dataFrameLength) { throw new EOFException("Expected to receive a Data Frame of length " + dataFrameLength + " bytes but received only " + bcis.getBytesRead() + " bytes");
final ByteCountingInputStream in = new ByteCountingInputStream(bufferedIn)) { long messageStartOffset = in.getBytesConsumed(); nextByte = in.read(); final long messageEndOffset = in.getBytesConsumed(); messageStartOffset = in.getBytesConsumed();
private void resetStreamForNextBlock() throws IOException { final InputStream limitedStream; if (tocReader == null) { limitedStream = rawInputStream; } else { final long offset = tocReader.getBlockOffset(1 + getBlockIndex()); if (offset < 0) { limitedStream = rawInputStream; } else { limitedStream = new LimitingInputStream(rawInputStream, offset - rawInputStream.getBytesConsumed()); } } final InputStream readableStream; if (compressed) { readableStream = new BufferedInputStream(new GZIPInputStream(limitedStream)); } else { readableStream = new BufferedInputStream(limitedStream); } byteCountingIn = new ByteCountingInputStream(readableStream, rawInputStream.getBytesConsumed()); dis = new DataInputStream(byteCountingIn); }
final InputStream limitedIn = new LimitedInputStream(rawIn, source.getSize()); final InputStream disableOnCloseIn = new DisableOnCloseInputStream(limitedIn); final ByteCountingInputStream countingStream = new ByteCountingInputStream(disableOnCloseIn, this.bytesRead)) { currentReadClaimStream.close(); currentReadClaimStream = null; } finally { decrementReadCount(source); bytesRead += countingStream.getBytesRead();
if (currentReadClaimStream != null && currentReadClaimStream.getBytesConsumed() <= offset) { final long bytesToSkip = offset - currentReadClaimStream.getBytesConsumed(); if (bytesToSkip > 0) { StreamUtils.skip(currentReadClaimStream, bytesToSkip); currentReadClaimStream.close(); currentReadClaimStream = new ByteCountingInputStream(rawInStream); StreamUtils.skip(currentReadClaimStream, offset);
File f = new File("filename.txt"); ByteCountingInputStream bcis = new ByteCountingInputStream(new FileInputStream(f)); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(bcis)); int chars = 0; String line; while ((line = lnr.readLine()) != null) { chars += line.length() + 2; System.out.println("Chars read: " + chars); System.out.println("Bytes read: " + bcis.getPosition()); }
@Override public void consume() throws IOException { if (countingIn == null) { return; } final byte[] b = new byte[4096]; int bytesRead; do { bytesRead = countingIn.read(b); } while (bytesRead > 0); }
@Override public long getBytesConsumed() { return byteCountingIn.getBytesConsumed(); }
private void resetReadClaim() { try { if (currentReadClaimStream != null) { currentReadClaimStream.close(); } } catch (final Exception e) { } currentReadClaimStream = null; currentReadClaim = null; }
final ByteCountingInputStream countingIn = new ByteCountingInputStream(socket.getInputStream()); InputStream wrappedInStream = countingIn; if (logger.isDebugEnabled()) { final String from = nodeId == null ? hostname : nodeId.toString(); logger.info("Finished processing request {} (type={}, length={} bytes) from {} in {}", requestId, request.getType(), countingIn.getBytesRead(), from, stopWatch.getDuration()); } catch (final IOException | ProtocolException e) { logger.warn("Failed processing protocol message from " + hostname + " due to " + e, e);
public CompressableRecordReader(final InputStream in, final String filename, final TocReader tocReader, final int maxAttributeChars) throws IOException { logger.trace("Creating RecordReader for {}", filename); rawInputStream = new ByteCountingInputStream(in); this.maxAttributeChars = maxAttributeChars; limitedStream = rawInputStream; } else { limitedStream = new LimitingInputStream(rawInputStream, offset1 - rawInputStream.getBytesConsumed()); byteCountingIn = new ByteCountingInputStream(readableStream); dis = new DataInputStream(byteCountingIn);
public long getBytesConsumed() { return getBytesRead() + getBytesSkipped(); }
@Override public int read(byte[] b) throws IOException { return read(b, 0, b.length); }
@Override public int getBlockIndex() { if (tocReader == null) { throw new IllegalStateException("Cannot determine Block Index because no Table-of-Contents could be found for Provenance Log " + filename); } return tocReader.getBlockIndex(rawInputStream.getBytesConsumed()); }
@Override public void close() throws IOException { logger.trace("Closing Record Reader for {}", filename); try { dis.close(); } finally { try { rawInputStream.close(); } finally { if (tocReader != null) { tocReader.close(); } } } }
final InputStream limitedIn = new LimitedInputStream(is, source.getSize()); final InputStream disableOnCloseIn = new DisableOnCloseInputStream(limitedIn); final ByteCountingInputStream countingIn = new ByteCountingInputStream(disableOnCloseIn, bytesRead); final OutputStream os = claimCache.write(newClaim); final OutputStream disableOnCloseOut = new DisableOnCloseOutputStream(os); writtenToFlowFile = countingOut.getBytesWritten(); this.bytesWritten += writtenToFlowFile; this.bytesRead += countingIn.getBytesRead(); writeRecursionSet.remove(source);