/** * Escapes a {@code byte} array according to the PDF conventions. * * @param bytes the {@code byte} array to escape * @return an escaped {@code byte} array */ public static byte[] createEscapedString(byte[] bytes) { return createBufferedEscapedString(bytes).toByteArray(); }
/** * Escapes a {@code byte} array according to the PDF conventions. * * @param bytes the {@code byte} array to escape * @return an escaped {@code byte} array */ public static byte[] createEscapedString(byte[] bytes) { return createBufferedEscapedString(bytes).toByteArray(); }
/** * Escapes a {@code byte} array according to the PDF conventions. * * @param outputStream the {@code OutputStream} an escaped {@code byte} array write to. * @param bytes the {@code byte} array to escape. */ public static void writeEscapedString(OutputStream outputStream, byte[] bytes) { ByteBuffer buf = createBufferedEscapedString(bytes); try { outputStream.write(buf.getInternalBuffer(), 0, buf.size()); } catch (java.io.IOException e) { throw new com.itextpdf.io.IOException(com.itextpdf.io.IOException.CannotWriteBytes, e); } }
/** * Escapes a {@code byte} array according to the PDF conventions. * * @param outputStream the {@code OutputStream} an escaped {@code byte} array write to. * @param bytes the {@code byte} array to escape. */ public static void writeEscapedString(OutputStream outputStream, byte[] bytes) { ByteBuffer buf = createBufferedEscapedString(bytes); try { outputStream.write(buf.getInternalBuffer(), 0, buf.size()); } catch (java.io.IOException e) { throw new com.itextpdf.io.IOException(com.itextpdf.io.IOException.CannotWriteBytes, e); } }
/** * Escape special symbols or convert to hexadecimal string. * This method don't change either {@code value} or {@code content} ot the {@code PdfString}. * * @param bytes byte array to manipulate with. * @return Hexadecimal string or string with escaped symbols in byte array view. */ protected byte[] encodeBytes(byte[] bytes) { if (hexWriting) { ByteBuffer buf = new ByteBuffer(bytes.length * 2); for (byte b : bytes) { buf.appendHex(b); } return buf.getInternalBuffer(); } else { ByteBuffer buf = StreamUtil.createBufferedEscapedString(bytes); return buf.toByteArray(1, buf.size() - 2); } }