@@ -0,0 +1,2476 @@
+package com.marklogic.client.io;%0A%0Aimport java.io.BufferedOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.OutputStream;%0Aimport java.net.MalformedURLException;%0Aimport java.net.URI;%0Aimport java.net.URISyntaxException;%0A%0Aimport com.marklogic.client.docio.BinaryReadHandle;%0Aimport com.marklogic.client.docio.BinaryWriteHandle;%0Aimport com.marklogic.client.docio.GenericReadHandle;%0Aimport com.marklogic.client.docio.GenericWriteHandle;%0Aimport com.marklogic.client.docio.JSONReadHandle;%0Aimport com.marklogic.client.docio.JSONWriteHandle;%0Aimport com.marklogic.client.docio.TextReadHandle;%0Aimport com.marklogic.client.docio.TextWriteHandle;%0Aimport com.marklogic.client.docio.XMLReadHandle;%0Aimport com.marklogic.client.docio.XMLWriteHandle;%0A%0Apublic class URIHandle%0Aimplements BinaryReadHandle%3CInputStream%3E, BinaryWriteHandle%3CInputStream%3E,%0A    GenericReadHandle%3CInputStream%3E, GenericWriteHandle%3CInputStream%3E, JSONReadHandle%3CInputStream%3E, JSONWriteHandle%3CInputStream%3E, %0A    TextReadHandle%3CInputStream%3E, TextWriteHandle%3CInputStream%3E, XMLReadHandle%3CInputStream%3E, XMLWriteHandle%3CInputStream%3E%0A%7B%0A%09private static final int BUFFER_SIZE = 1024;%0A%0A%09public URIHandle(String uri) %7B%0A%09%09set(uri);%0A%09%7D%0A%0A%09private String uri;%0A%09public String get() %7B%0A%09%09return uri;%0A%09%7D%0A%09public void set(String uri) %7B%0A%09%09this.uri = uri;%0A%09%7D%0A%09public URIHandle on(String uri) %7B%0A%09%09set(uri);%0A%09%09return this;%0A%09%7D%0A%0A%09public Class%3CInputStream%3E receiveAs() %7B%0A%09%09return InputStream.class;%0A%09%7D%0A%09public void receiveContent(InputStream content) %7B%0A%09%09try %7B%0A%09%09%09OutputStream out = new BufferedOutputStream(new URI(uri).toURL().openConnection().getOutputStream());%0A%09%09%09byte%5B%5D buf = new byte%5BBUFFER_SIZE%5D;%0A%09%09%09int len = 0;%0A%09%09%09while ((len = content.read(buf, 0, BUFFER_SIZE)) != -1) %7B%0A%09%09%09%09out.write(buf, 0, len);%0A%09%09%09%7D%0A%09%09%09content.close();%0A%09%09%09out.close();%0A%09%09%7D catch (MalformedURLException e) %7B%0A%09%09%09// TODO: log exception%0A%09%09%09throw new RuntimeException(e);%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09// TODO: log exception%0A%09%09%09throw new RuntimeException(e);%0A%09%09%7D catch (URISyntaxException e) %7B%0A%09%09%09// TODO: log exception%0A%09%09%09throw new RuntimeException(e);%0A%09%09%7D%0A%09%7D%0A%09public InputStream sendContent() %7B%0A%09%09try %7B%0A%09%09%09return new URI(uri).toURL().openStream();%0A%09%09%7D catch (MalformedURLException e) %7B%0A%09%09%09// TODO: log exception%0A%09%09%09throw new RuntimeException(e);%0A%09%09%7D catch (IOException e) %7B%0A%09%09%09// TODO: log exception%0A%09%09%09throw new RuntimeException(e);%0A%09%09%7D catch (URISyntaxException e) %7B%0A%09%09%09// TODO: log exception%0A%09%09%09throw new RuntimeException(e);%0A%09%09%7D%0A%09%7D%0A%7D%0A

handle content received from or sent to a URI