@Override public void write(byte[] buf, int off, int len) throws IOException { while (len > 0) { int n = Math.min(len, this.in.remaining()); this.in.put(buf, off, n); this.processInput(false); len -= n; off += n; } this.writeOutput(); }
@Override public void write(int b) throws IOException { this.write(new byte[] { (byte) b }, 0, 1); }
@Override public void run() throws IOException { InputStream in = new ByteArrayInputStream(buffer.toByteArray()); // Process "Content-Encoding" header. if ("gzip".equalsIgnoreCase(HttpMessage.this.getHeader("Content-Encoding"))) { LOGGER.fine(loggingPrefix + "GZIP-encoded content"); in = new GZIPInputStream(in); } if (LOGGER.isLoggable(FINE)) { LOGGER.fine(loggingPrefix + "Reading message body"); Writer lw = LogUtil.logWriter(LOGGER, FINE, loggingPrefix); in = InputStreams.wye(in, ( HttpMessage.this.contentTypeIsXmlish() ? new WriterOutputStream(new XMLFormatterWriter(lw)) : new HexOutputStream(lw) )); } HttpMessage.this.setBody(HttpMessage.body(in)); finished.run(); } };
@Override public void close() throws IOException { this.processInput(true); this.delegate.close(); }
private void processInput(boolean endOfInput) throws IOException { this.in.flip(); for (;;) { CoderResult coderResult = this.decoder.decode(this.in, this.out, endOfInput); if (coderResult.isUnderflow()) break; if (coderResult.isOverflow()) { this.writeOutput(); } else { throw new AssertionError(coderResult); } } this.in.compact(); }
/** * Writes the body of this message <em>synchronously</em> to the given {@link OutputStream}. */ private void writeBody(String prefix, OutputStream out) throws IOException { // Check "Content-Encoding: gzip" GZIPOutputStream finishable = null; if ("gzip".equalsIgnoreCase(this.getHeader("Content-Encoding"))) { LOGGER.fine(prefix + "GZIP-encoded contents"); out = (finishable = new GZIPOutputStream(out)); } final boolean isXml; { String ct = this.getHeader("Content-Type"); isXml = ct != null && ct.indexOf("text/xml") != -1; } if (LOGGER.isLoggable(FINE)) { LOGGER.fine(prefix + "Writing message body:"); Writer lw = LogUtil.logWriter(LOGGER, FINE, prefix); out = IoUtil.tee(out, ( isXml ? new WriterOutputStream(new XMLFormatterWriter(lw)) : new HexOutputStream(lw) )); } this.body.write(out); if (finishable != null) finishable.finish(); out.flush(); }
/** * 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(); }
@Override public void run() throws IOException { InputStream in = new ByteArrayInputStream(buffer.toByteArray()); // Process "Content-Encoding" header. if ("gzip".equalsIgnoreCase(HttpMessage.this.getHeader("Content-Encoding"))) { LOGGER.fine("GZIP-encoded content"); in = new GZIPInputStream(in); } if (LOGGER.isLoggable(FINE)) { boolean isXml = false; LOGGER.fine("Reading message body"); String contentType = HttpMessage.this.getHeader("Content-Type"); if (contentType != null) { ParametrizedHeaderValue phv = new ParametrizedHeaderValue(contentType); if ("text/xml".equalsIgnoreCase(phv.getToken())) isXml = true; } Writer logWriter = LogUtil.logWriter(LOGGER, FINE, ">>> "); in = IoUtil.wye(in, ( isXml ? new WriterOutputStream(new XMLFormatterWriter(logWriter)) : new HexOutputStream(logWriter) )); } HttpMessage.this.setBody(HttpMessage.body(in)); finished.run(); } };
in = InputStreams.wye(in, ( this.contentTypeIsXmlish() ? new WriterOutputStream(new XMLFormatterWriter(lw)) : new HexOutputStream(lw) ));
in = IoUtil.wye(in, ( isXml ? new WriterOutputStream(new XMLFormatterWriter(logWriter)) : new HexOutputStream(logWriter) ));