private InputStream sanitizeStream(InputStream in) throws IOException{ BufferedInputStream bis = new BufferedInputStream(in); OutputStream output = new ByteArrayOutputStream(); //Sanitize input stream int ch; while ((ch = bis.read()) != -1) { if ((ch == 0x9) || (ch == 0xA) || (ch == 0xD) || ((ch >= 0x20) && (ch = 0xE000) && (ch = 0x10000) && (ch <= 0x10FFFF))) { output.write((int) ch); } } InputStream decodedInput = new ByteArrayInputStream( ((ByteArrayOutputStream) output).toByteArray()); return decodedInput; }