private void openCurrentFile() throws IOException { this.setOutputStream(OutputStreams.tee( new FileOutputStream(this.currentFile, true), OutputStreams.lengthWritten((this.byteCount = ConsumerUtil.cumulate(0))) )); }
/** * @return An {@link OutputStream} which ignores all invocations of {@link OutputStream#close()} * @deprecated Use {@link #unclosable(OutputStream)} instead */ @Deprecated public static OutputStream unclosableOutputStream(OutputStream delegate) { return OutputStreams.unclosable(delegate); }
/** @deprecated Use {@link OutputStreams#compareOutput(int, Runnable, Runnable)} instead */ @Deprecated public static OutputStream[] compareOutput(final int n, final Runnable whenIdentical, final Runnable whenNotIdentical) { return OutputStreams.compareOutput(n, whenIdentical, whenNotIdentical); }
/** @deprecated Use {@link OutputStreams#lengthWritten(Consumer)} instead */ @Deprecated public static OutputStream lengthWritten(final Consumer<? super Integer> delegate) { return OutputStreams.lengthWritten(delegate); }
/** @deprecated Use {@link OutputStreams#tee(OutputStream...)} instead */ @Deprecated @NotNullByDefault(false) public static OutputStream tee(final OutputStream... delegates) { return OutputStreams.tee(delegates); }
@Override public void fill(OutputStream os) throws IOException { this.count = OutputStreams.writeAndCount(writeContents, os); }
/** @deprecated Use {@link OutputStreams#fill(OutputStream, byte, long)} instead */ @Deprecated public static void fill(OutputStream outputStream, byte b, long count) throws IOException { OutputStreams.fill(outputStream, b, count); }
/** @deprecated Use {@link OutputStreams#byteConsumerOutputStream(ConsumerWhichThrows)} instead */ @Deprecated public static OutputStream byteConsumerOutputStream(final ConsumerWhichThrows<? super Byte, ? extends IOException> delegate) { return OutputStreams.byteConsumerOutputStream(delegate); }
return is; } else { return InputStreams.wye(is, OutputStreams.lengthWritten(new Consumer<Integer>() {
/** * Connects to the given <var>address</var> and <var>port</var>. Data can be sent to the remote server through the * {@link OutputStream} returned by {@link #getOutputStream()}, and data can be read from the remote server * through the {@link InputStream} returned by {@link #getInputStream()}. */ public TcpClient(InetAddress address, int port) throws IOException { this.socket = new Socket(address, port); LOGGER.fine("Connected to " + this.socket.getRemoteSocketAddress()); InputStream in = this.socket.getInputStream(); OutputStream out = this.socket.getOutputStream(); boolean logData = LOGGER.isLoggable(FINEST); this.fromServer = ( logData ? InputStreams.wye(in, new HexOutputStream(LogUtil.logWriter(LOGGER, FINEST, "<From Server< "))) : in ); this.toServer = ( logData ? OutputStreams.tee(out, new HexOutputStream(LogUtil.logWriter(LOGGER, FINEST, ">To Server> "))) : out ); }
@Override public void fill(OutputStream os) throws IOException { this.count = OutputStreams.writeAndCount(writeContents, os); }
/** * Invokes <var>writeContents</var>{@code .consume()} with an output stream subject that writes the data through to * the given <var>outputStream</var>. * * @return The number of bytes that were written through */ public static long writeAndCount( ConsumerWhichThrows<? super OutputStream, ? extends IOException> writeContents, OutputStream outputStream ) throws IOException { Produmer<Long, Long> count = ConsumerUtil.store(); writeContents.consume( OutputStreams.tee( outputStream, OutputStreams.lengthWritten(ConsumerUtil.cumulate(count, 0L)) ) ); Long result = count.produce(); return result == null ? 0L : result; }
in = InputStreams.wye(in, OutputStreams.lengthWritten(ConsumerUtil.cumulate(rawByteCount, 0))); in = InputStreams.wye(in, OutputStreams.lengthWritten(ConsumerUtil.cumulate(decodedByteCount, 0)));
/** * Writes the body of this message <em>synchronously</em> to the given {@link OutputStream}. * * @param loggingPrefix E.g. {@code "<<< "} */ private void writeBody(String loggingPrefix, OutputStream out) throws IOException { // Check "Content-Encoding: gzip" GZIPOutputStream finishable = null; if ("gzip".equalsIgnoreCase(this.getHeader("Content-Encoding"))) { LOGGER.fine(loggingPrefix + "GZIP-encoded contents"); out = (finishable = new GZIPOutputStream(out)); } if (LOGGER.isLoggable(FINE)) { LOGGER.fine(loggingPrefix + "Writing message body:"); Writer lw = LogUtil.logWriter(LOGGER, FINE, loggingPrefix); out = OutputStreams.tee(out, ( this.contentTypeIsXmlish() ? new WriterOutputStream(new XMLFormatterWriter(lw)) : new HexOutputStream(lw) )); } this.body.write(out); if (finishable != null) finishable.finish(); out.flush(); }
/** @deprecated Use {@link OutputStreams#unclosable(OutputStream)} instead */ @Deprecated public static OutputStream unclosableOutputStream(OutputStream delegate) { return OutputStreams.unclosable(delegate); }
/** @deprecated Use {@link OutputStreams#writeAndCount(ConsumerWhichThrows, OutputStream)} instead */ @Deprecated public static long writeAndCount( ConsumerWhichThrows<? super OutputStream, ? extends IOException> writeContents, OutputStream outputStream ) throws IOException { return OutputStreams.writeAndCount(writeContents, outputStream); }
/** * Consumes the <var>inputStream</var>, feeds it through the <var>contentsTransformer</var>, and checks whether * the output is identical with the input. * * @throws RuntimeException {@link FileTransformer#NOT_IDENTICAL} iff the transformer contents differs from the * original contents */ public static void checkIdentity( String path, InputStream inputStream, ContentsTransformer contentsTransformer, boolean closeInputStream ) throws IOException { try { OutputStream[] oss = OutputStreams.compareOutput(2, RunnableUtil.NOP, FileTransformer.THROW_NOT_IDENTICAL); contentsTransformer.transform(path, InputStreams.wye(inputStream, oss[0]), oss[1]); oss[0].close(); oss[1].close(); if (closeInputStream) inputStream.close(); } finally { if (closeInputStream) try { inputStream.close(); } catch (Exception e) {} } } }
responseSize = ConsumerUtil.store(); out = OutputStreams.tee(out, OutputStreams.lengthWritten(ConsumerUtil.cumulate(responseSize, 0))); in = InputStreams.wye(in, OutputStreams.lengthWritten(ConsumerUtil.cumulate(requestSize, 0)));
out = OutputStreams.tee( out, new HexOutputStream(LogUtil.logWriter(LOGGER, FINEST, ">To Client> "))
@Nullable @Override public Void call() throws Exception { // Run the task. try { task.consume(OutputStreams.unclosable(previousTarget)); } catch (Exception ex) { throw ex; } catch (Error er) { // SUPPRESS CHECKSTYLE IllegalCatch throw er; } catch (Throwable th) { // SUPPRESS CHECKSTYLE IllegalCatch throw new Exception(th); } synchronized (pos) { // Copy the buffered products of the FOLLOWING tasks to the output. IoUtil.copyAvailable(ios.getInputStream(), previousTarget); // Redirect FUTURE output of the FOLLOWING tasks directly to MY output. pos.setDelegate(previousTarget); buffer.close(); } return null; } });