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(); } } } },
public DelimitedTextFileWriter(LogFilePath path, CompressionCodec codec) throws IOException { Path fsPath = new Path(path.getLogFilePath()); FileSystem fs = FileUtil.getFileSystem(path.getLogFilePath()); this.mCountingStream = new CountingOutputStream(fs.create(fsPath)); this.mWriter = (codec == null) ? new BufferedOutputStream( this.mCountingStream) : new BufferedOutputStream( codec.createOutputStream(this.mCountingStream, mCompressor = CodecPool.getCompressor(codec))); }
public FlexibleDelimitedFileWriter(LogFilePath path, CompressionCodec codec) throws IOException { Path fsPath = new Path(path.getLogFilePath()); FileSystem fs = FileUtil.getFileSystem(path.getLogFilePath()); this.mCountingStream = new CountingOutputStream(fs.create(fsPath)); this.mWriter = (codec == null) ? new BufferedOutputStream( this.mCountingStream) : new BufferedOutputStream( codec.createOutputStream(this.mCountingStream, mCompressor = CodecPool.getCompressor(codec))); }
throws IOException this.outputStream = new CountingOutputStream(outputStream); rcFileWriter = new RcFileWriter( new OutputStreamSliceOutput(this.outputStream),
@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()); } } } }
(StreamingOutput) outputStream -> { Exception e = null; CountingOutputStream os = new CountingOutputStream(outputStream); Yielder<Object[]> yielder = yielder0;
public void testCount() throws Exception { int written = 0; ByteArrayOutputStream out = new ByteArrayOutputStream(); CountingOutputStream counter = new CountingOutputStream(out); assertEquals(written, out.size()); assertEquals(written, counter.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(); }
fis = new FileInputStream(inputPath); reader = new InputStreamReader(fis, Charset.forName("UTF-8")); out = new CountingOutputStream( new DigestOutputStream( new BufferedOutputStream(fout), digester));
try { CountingOutputStream counter = new CountingOutputStream(os); Writer writer = new OutputStreamWriter(counter, UTF_8); NewAppiumSessionPayload payload = NewAppiumSessionPayload.create(desired);
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed") public OutputStreamSliceOutput(OutputStream outputStream) { countingOutputStream = new CountingOutputStream(outputStream); dataOutputStream = new LittleEndianDataOutputStream(countingOutputStream); }
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 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 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()); } }
TableRowWriter(String basename) throws Exception { String uId = UUID.randomUUID().toString(); resourceId = FileSystems.matchNewResource(basename + uId, false); LOG.info("Opening TableRowWriter to {}.", resourceId); channel = FileSystems.create(resourceId, MimeTypes.TEXT); out = new CountingOutputStream(Channels.newOutputStream(channel)); }
public void open() throws IOException { headerOut = new CountingOutputStream(ioPeon.makeOutputStream(makeFilename("header"))); valuesOut = new CountingOutputStream(ioPeon.makeOutputStream(makeFilename("values"))); }