@Override public long getWrittenBytes() { return outputStream.getCount(); }
@Override public long getLength() throws IOException { assert this.mCountingStream != null; return this.mCountingStream.getCount(); }
@Override public long getLength() throws IOException { assert this.mCountingStream != null; this.mWriter.flush(); return this.mCountingStream.getCount(); }
private static int writeProtobufObject(OutputStream output, MessageLite object) throws IOException { CountingOutputStream countingOutput = new CountingOutputStream(output); object.writeTo(countingOutput); return toIntExact(countingOutput.getCount()); } }
private static int writeProtobufObject(OutputStream output, MessageLite object) throws IOException { CountingOutputStream countingOutput = new CountingOutputStream(output); object.writeTo(countingOutput); return toIntExact(countingOutput.getCount()); } }
@Override public void write(OutputStream outputStream) throws WebApplicationException { Exception e = null; CountingOutputStream os = new CountingOutputStream(outputStream); try { // json serializer will always close the yielder jsonWriter.writeValue(os, yielder); os.flush(); // Some types of OutputStream suppress flush errors in the .close() method. os.close(); } catch (Exception ex) { e = ex; log.error(ex, "Unable to send query response."); throw Throwables.propagate(ex); } finally { Thread.currentThread().setName(currThreadName); queryLifecycle.emitLogsAndMetrics(e, req.getRemoteAddr(), os.getCount()); if (e == null) { successfulQueryCount.incrementAndGet(); } else { failedQueryCount.incrementAndGet(); } } } },
@BeforeClass public static void setup() throws IOException { TEST_DIR = tempDir.newFolder(); for (int i = 0; i < 100; i++) { try ( CountingOutputStream cos = new CountingOutputStream( Files.newOutputStream(new File(TEST_DIR, "test_" + i).toPath()) ); Writer writer = new BufferedWriter(new OutputStreamWriter(cos, StandardCharsets.UTF_8)) ) { for (int j = 0; j < 100; j++) { final String a = StringUtils.format("%d,%03d,%03d\n", (20171220 + i), i, j); writer.write(a); } writer.flush(); // Every file size must be same if (FILE_SIZE == -1) { FILE_SIZE = cos.getCount(); } else { Assert.assertEquals(FILE_SIZE, cos.getCount()); } } } }
CountingOutputStream counter = new CountingOutputStream(out); assertEquals(written, out.size()); assertEquals(written, counter.getCount()); assertEquals(written, counter.getCount()); written += 10; assertEquals(written, out.size()); assertEquals(written, counter.getCount()); assertEquals(written, counter.getCount()); assertEquals(written, counter.getCount()); assertEquals(written, counter.getCount());
lifecycle.emitLogsAndMetrics(e, remoteAddr, os.getCount());
@Override public void handle(HttpExchange exchange) throws IOException { CountingInputStream input = new CountingInputStream(exchange.getRequestBody()); CountingOutputStream output = new CountingOutputStream(exchange.getResponseBody()); exchange.setStreams(input, output); Stopwatch stopwatch = latency.start(); try { handleImpl(exchange); } finally { stopwatch.stop(); bytesReceived.increment(input.getCount()); bytesSent.increment(output.getCount()); } }
/** Calculates the GZip compressed size in bytes of the target {@code stream}. */ public static long calculateGzipCompressedSize(@WillNotClose InputStream stream) throws IOException { CountingOutputStream countingOutputStream = new CountingOutputStream(ByteStreams.nullOutputStream()); try (GZIPOutputStream compressedStream = new GZIPOutputStream(countingOutputStream)) { ByteStreams.copy(stream, compressedStream); } return countingOutputStream.getCount(); }
.invoke(this, client, contentStream, counter.getCount());
/** * Record the length of a section of the FSImage in our FileSummary object. * The FileSummary appears at the end of the FSImage and acts as a table of * contents for the file. * * @param sectionNamePb The name of the section as it should appear in * the fsimage. (This is different than the XML * name.) * @throws IOException */ void recordSectionLength(String sectionNamePb) throws IOException { long curSectionStartOffset = sectionStartOffset; long curPos = out.getCount(); //if (sectionNamePb.equals(SectionName.STRING_TABLE.name())) { fileSummaryBld.addSections(FileSummary.Section.newBuilder(). setName(sectionNamePb). setLength(curPos - curSectionStartOffset). setOffset(curSectionStartOffset)); //} sectionStartOffset = curPos; }
public long getBytesWritten() { return out.getCount(); } }
public long getBytesWritten() { if (countingOutputStream == null) { return 0; } return countingOutputStream.getCount(); }
@Override public void handle(final Record record) throws Throwable { if (record == null || this.records > 0 && this.records % 1000 == 0) { LOGGER.info("{} records, {} bytes processed ({} bytes/record)", this.records, stream.getCount(), stream.getCount() / this.records); } if (record != null) { serializer.toStream(stream, record); ++this.records; } }
private OutputStream getCurrentTarget() throws IOException { if (currentTarget == null) { currentTarget = new CountingOutputStream(outputFactory.get()); } else if (currentTarget.getCount() >= byteSoftLimit) { LOGGER.info( String.format("Closing stream and opening a new one, reached %,d bytes.\n", currentTarget.getCount())); currentTarget.close(); currentTarget = new CountingOutputStream(outputFactory.get()); } return currentTarget; }
private DeflaterOutputStream getCurrentFile(ByteArrayOutputStream baos) throws IOException { if(this.currentFile == null) { openNewFile(); } else { if(bytesCounter.getCount() + baos.size() > maxFileSize) { openNewFile(); } } return currentFile; }