@Deprecated public static String base64Encode(String s) { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); Base64OutputStream out = new Base64OutputStream(bOut); try { out.write(s.getBytes()); out.flush(); } catch (IOException exception) { } return bOut.toString(); }
@Override public void handle(HttpExchange arg0) throws IOException { try { JSONObject json = (JSONObject) JSONSerializer.toJSON(IOUtils.toString(arg0.getRequestBody())); String contents = json.getString("names"); byte[] fileContents = contents.getBytes("UTF-8"); ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); GZIPOutputStream gzipStr = new GZIPOutputStream(byteArray); gzipStr.write(fileContents); gzipStr.close(); ByteArrayOutputStream byteArray2 = new ByteArrayOutputStream(); Base64OutputStream base64 = new Base64OutputStream(byteArray2); base64.write(byteArray.toByteArray()); base64.close(); String value = new String(byteArray2.toByteArray()); json.remove("names"); json.put("upload", value); HttpClient client = new HttpClient(); PostMethod post = new PostMethod( "http://" + properties.getProperty("org.iplantc.tnrs.servicesHost") + "/tnrs-svc/upload"); post.setRequestEntity(new StringRequestEntity(json.toString(), "text/plain", "UTF-8")); client.executeMethod(post); HandlerHelper.writeResponseRequest(arg0, 200, "", "text/plain"); } catch (Exception ex) { log.error(ExceptionUtils.getFullStackTrace(ex)); ex.printStackTrace(); throw new IOException(ex); } }
@Override public void close() throws IOException { output.close(); }
@Override public void write(byte b[], int off, int len) throws IOException { output.write(b, off, len); }
@Override public void write(int b) throws IOException { output.write(b); }
@Override public void flush() throws IOException { output.flush(); }