private void sendFile(InputStream in, URLConnection conn) throws IOException { conn.connect(); OutputStream out = conn.getOutputStream(); try { StreamUtils.copyStream(in, out, IO_BUFFER_SIZE); } finally { out.close(); } }
private URLConnection prepareConnection(String fileUploadUrl, long fileSize) throws RemoteException, InvalidPropertyFaultMsg, RuntimeFaultFaultMsg, FileFaultFaultMsg, GuestOperationsFaultFaultMsg, InvalidStateFaultMsg, TaskInProgressFaultMsg, MalformedURLException, IOException, ProtocolException { // http://stackoverflow.com/questions/3386832/upload-a-file-using-http-put-in-java URL url = new URL(fileUploadUrl); URLConnection conn = url.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); if (conn instanceof HttpURLConnection) { ((HttpURLConnection) conn).setRequestMethod("PUT"); } else { throw new IllegalStateException("Unknown connection type"); } conn.setRequestProperty("Content-type", "application/octet-stream"); conn.setRequestProperty("Content-length", "" + fileSize); return conn; }