ASCIIHexDecodeFilter extends MemoryLimitsAwareFilter { public static byte[] ASCIIHexDecode(byte[] in) { return ASCIIHexDecodeInternal(in, new ByteArrayOutputStream()); }  static byte[] ASCIIHexDecode(byte[] in); @Override byte[] decode(byte[] b, PdfName filterName, PdfObject decodeParams, PdfDictionary streamDictionary);  }
@Test public void decodingTest() throws IOException { File file = new File(SOURCE_FILE); byte[] bytes = Files.readAllBytes(file.toPath()); String expectedResult = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " + "Donec ac malesuada tellus. " + "Quisque a arcu semper, tristique nibh eu, convallis lacus. " + "Donec neque justo, condimentum sed molestie ac, mollis eu nibh. " + "Vivamus pellentesque condimentum fringilla. " + "Nullam euismod ac risus a semper. " + "Etiam hendrerit scelerisque sapien tristique varius."; String decoded = new String(ASCIIHexDecodeFilter.ASCIIHexDecode(bytes)); Assert.assertEquals(expectedResult, decoded); }
@Test public void decodingIllegalaCharacterTest() { byte[] bytes = "4c6f72656d20697073756d2eg>".getBytes(); junitExpectedException.expect(PdfException.class); junitExpectedException.expectMessage(PdfException.IllegalCharacterInAsciihexdecode); ASCIIHexDecodeFilter.ASCIIHexDecode(bytes); }
@Test public void decodingSkipWhitespacesTest() { byte[] bytes = "4c 6f 72 65 6d 20 69 70 73 75 6d 2e>".getBytes(); String expectedResult = "Lorem ipsum."; String decoded = new String(ASCIIHexDecodeFilter.ASCIIHexDecode(bytes)); Assert.assertEquals(expectedResult, decoded); }