import java.io.*; import org.apache.commons.codec.binary.Base64; int i = -1; byte[] b = new byte[4096]; ByteArrayOutputStream baos = new ByteArrayOutputStream(); while ((i = inputStream.read(b)) != -1) { baos.write(b, 0, i); } byte[] encoded = Base64.encodeBase64(baos.toByteArray()); service.getOutputStream().write(new String(encoded).getBytes());