public static ByteBuffer readByteBuffer(InputStream is) throws IOException { BinaryRequestWriter.BAOS baos = new BinaryRequestWriter.BAOS(); org.apache.commons.io.IOUtils.copy(is, baos); return ByteBuffer.wrap(baos.getbuf(), 0, baos.size()); } }
@Override public ContentStream getContentStream(final UpdateRequest request) throws IOException { final BAOS baos = new BAOS(); new JavaBinUpdateRequestCodec().marshal(request, baos);
public ContentStream getContentStream(final UpdateRequest request) throws IOException { final BAOS baos = new BAOS(); new JavaBinUpdateRequestCodec().marshal(request, baos); return new ContentStream() { public String getName() { return null; } public String getSourceInfo() { return "javabin"; } public String getContentType() { return "application/octet-stream"; } public Long getSize() // size if we know it, otherwise null { return new Long(baos.size()); } public InputStream getStream() throws IOException { return new ByteArrayInputStream(baos.getbuf(), 0, baos.size()); } public Reader getReader() throws IOException { throw new RuntimeException("No reader available . this is a binarystream"); } }; }
public Long getSize() // size if we know it, otherwise null { return new Long(baos.size()); }
@Override public Long getSize() // size if we know it, otherwise null { return new Long(baos.size()); }
public static InputStream toJavabin(Object o) throws IOException { try (final JavaBinCodec jbc = new JavaBinCodec()) { BinaryRequestWriter.BAOS baos = new BinaryRequestWriter.BAOS(); jbc.marshal(o,baos); return new ByteBufferInputStream(ByteBuffer.wrap(baos.getbuf(),0,baos.size())); } }