@Override public void write(char[] cbuf, int off, int len) throws IOException { for (int i = off; i < off + len; i++) this.write(cbuf[i]); }
@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(); } };
/** * 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(); }
/** * 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(); }
@Override public void write(char[] cbuf, int off, int len) throws IOException { for (int i = off; i < off + len; i++) this.write(cbuf[i]); }
@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(); } };
@Override public void write(String str, int off, int len) throws IOException { for (int i = off; i < off + len; i++) this.write(str.charAt(i)); } }
in = IoUtil.wye(in, ( isXml ? new WriterOutputStream(new XMLFormatterWriter(logWriter)) : new HexOutputStream(logWriter) ));
@Override public void write(String str, int off, int len) throws IOException { for (int i = off; i < off + len; i++) this.write(str.charAt(i)); } }
in = InputStreams.wye(in, ( this.contentTypeIsXmlish() ? new WriterOutputStream(new XMLFormatterWriter(lw)) : new HexOutputStream(lw) ));