protected static String decodeName(byte[] content) { StringBuilder buf = new StringBuilder(); try { for (int k = 0; k < content.length; ++k) { char c = (char) content[k]; if (c == '#') { byte c1 = content[k + 1]; byte c2 = content[k + 2]; c = (char) ((ByteBuffer.getHex(c1) << 4) + ByteBuffer.getHex(c2)); k += 2; } buf.append(c); } } catch (IndexOutOfBoundsException e) { // empty on purpose } return buf.toString(); }
protected void generateValue() { StringBuilder buf = new StringBuilder(); try { for (int k = 0; k < content.length; ++k) { char c = (char) content[k]; if (c == '#') { byte c1 = content[k + 1]; byte c2 = content[k + 2]; c = (char) ((ByteBuffer.getHex(c1) << 4) + ByteBuffer.getHex(c2)); k += 2; } buf.append(c); } } catch (IndexOutOfBoundsException e) { // empty on purpose } value = buf.toString(); }
protected static String decodeName(byte[] content) { StringBuilder buf = new StringBuilder(); try { for (int k = 0; k < content.length; ++k) { char c = (char) content[k]; if (c == '#') { byte c1 = content[k + 1]; byte c2 = content[k + 2]; c = (char) ((ByteBuffer.getHex(c1) << 4) + ByteBuffer.getHex(c2)); k += 2; } buf.append(c); } } catch (IndexOutOfBoundsException e) { // empty on purpose } return buf.toString(); }
/** * Decodes a byte[] according to ASCII Hex encoding. * * @param in byte[] to be decoded * @return decoded byte[] */ public static byte[] ASCIIHexDecode(byte[] in) { ByteArrayOutputStream out = new ByteArrayOutputStream(); boolean first = true; int n1 = 0; for (int k = 0; k < in.length; ++k) { int ch = in[k] & 0xff; if (ch == '>') break; if (PdfTokenizer.isWhitespace(ch)) continue; int n = ByteBuffer.getHex(ch); if (n == -1) throw new PdfException(PdfException.IllegalCharacterInAsciihexdecode); if (first) n1 = n; else out.write((byte)((n1 << 4) + n)); first = !first; } if (!first) out.write((byte)(n1 << 4)); return out.toByteArray(); } }