private byte[] read(Base base) { byte[] data = null; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); base.writeTo(out); data = out.toByteArray(); } catch (IOException e) { } return data; }
public StreamBuilder writeComment(String value) { current.addComment(value); return this; }
public final T complete(T t) { return (T)t.complete(); } }
type = base.getFactory().getMimeType(base); return (type != null) ? type : Constants.XML_MEDIA_TYPE;
type = base.getFactory().getMimeType(base); return (type != null) ? type : Constants.XML_MEDIA_TYPE;
private byte[] read(Base base) { byte[] data = null; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); base.writeTo(out); data = out.toByteArray(); } catch (IOException e) {} return data; }
public StreamBuilder writeComment(String value) { current.addComment(value); return this; }
public long getContentLength() { if (use_chunked) return -1; // chunk the response else { // this is ugly, but some proxies and server configurations (e.g. gdata) // require that requests contain the Content-Length header. The only // way to get that is to serialize the document into a byte array, which // we buffer into memory. if (buf == null) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); base.writeTo(out); buf = out.toByteArray(); } catch (Exception e) { } } return buf.length; } }
public void writeTo(Base base, Writer out, WriterOptions options) throws IOException { base.writeTo(out); if (options.getAutoClose()) out.close(); }
public void writeRequest(OutputStream out) throws IOException { if (use_chunked) base.writeTo(out); else { // if we're not using chunked requests, the getContentLength method // has likely already been called and we want to just go ahead and // use the buffered output rather than reserialize if (buf == null) getContentLength(); // ensures that the content is buffered out.write(buf); out.flush(); } }
@Override public InputStream getInputStream() { try { PipedOutputStream pipeout = new PipedOutputStream(); PipedInputStream pipein = new PipedInputStream(pipeout); base.writeTo(pipeout); pipeout.flush(); pipeout.close(); return pipein; } catch (IOException e) { return null; } }
@Override public InputStream getInputStream() { try { PipedOutputStream pipeout = new PipedOutputStream(); PipedInputStream pipein = new PipedInputStream(pipeout); base.writeTo(pipeout); pipeout.flush(); pipeout.close(); return pipein; } catch (IOException e) { return null; } }
public void writeTo(java.io.Writer javaWriter) throws IOException { if (hasEntity()) { if (writer == null) base.writeTo(javaWriter); else writeTo(javaWriter, writer); } }
public void writeTo(OutputStream out) throws IOException { if (hasEntity()) { if (writer == null) base.writeTo(out); else writeTo(out, writer); } }
@Override public long getContentLength() { long len = super.getContentLength(); if (hasEntity() && len == -1 && !chunked) { try { ByteArrayOutputStream out = new ByteArrayOutputStream(); base.writeTo(out); len = out.size(); super.setContentLength(len); } catch (Exception e) { } } return len; }
@SuppressWarnings("unchecked") public void writeTo(Base base, OutputStream out, WriterOptions options) throws IOException { out = getCompressedOutputStream(out, options); String charset = options.getCharset(); if (charset == null) { if (base instanceof Document) charset = ((Document)base).getCharset(); else if (base instanceof Element) { Document doc = ((Element)base).getDocument(); if (doc != null) charset = doc.getCharset(); } if (charset == null) charset = "UTF-8"; } else { Document doc = null; if (base instanceof Document) doc = (Document)base; else if (base instanceof Element) doc = ((Element)base).getDocument(); if (doc != null) doc.setCharset(charset); } base.writeTo(new OutputStreamWriter(out, charset)); finishCompressedOutputStream(out, options); if (options.getAutoClose()) out.close(); }