/** * Creates a PdfTokenizer for the specified {@link RandomAccessFileOrArray}. * The beginning of the file is read to determine the location of the header, and the data source is adjusted * as necessary to account for any junk that occurs in the byte source before the header * * @param file the source */ public PdfTokenizer(RandomAccessFileOrArray file) { this.file = file; this.outBuf = new ByteBuffer(); }
/** * Creates a PdfTokenizer for the specified {@link RandomAccessFileOrArray}. * The beginning of the file is read to determine the location of the header, and the data source is adjusted * as necessary to account for any junk that occurs in the byte source before the header * * @param file the source */ public PdfTokenizer(RandomAccessFileOrArray file) { this.file = file; this.outBuf = new ByteBuffer(); }
/** * Converts an array of bytes to a String of hexadecimal values * * @param bytes a byte array * @return the same bytes expressed as hexadecimal values */ public static String convertToHex(byte[] bytes) { ByteBuffer buf = new ByteBuffer(); for (byte b : bytes) { buf.appendHex(b); } return PdfEncodings.convertToString(buf.toByteArray(), null).toUpperCase(); } }
/** * Converts an array of bytes to a String of hexadecimal values * * @param bytes a byte array * @return the same bytes expressed as hexadecimal values */ public static String convertToHex(byte[] bytes) { ByteBuffer buf = new ByteBuffer(); for (byte b : bytes) { buf.appendHex(b); } return PdfEncodings.convertToString(buf.toByteArray(), null).toUpperCase(); } }
public static ByteBuffer createBufferedHexedString(byte[] bytes) { ByteBuffer buf = new ByteBuffer(bytes.length * 2 + 2); buf.append('<'); for (byte b : bytes) { buf.appendHex(b); } buf.append('>'); return buf; }
public static ByteBuffer createBufferedHexedString(byte[] bytes) { ByteBuffer buf = new ByteBuffer(bytes.length * 2 + 2); buf.append('<'); for (byte b : bytes) { buf.appendHex(b); } buf.append('>'); return buf; }
static byte[] getIsoBytes(int n, ByteBuffer buffer) { boolean negative = false; if (n < 0) { negative = true; n = -n; } int intLen = intSize(n); ByteBuffer buf = buffer == null ? new ByteBuffer(intLen + (negative ? 1 : 0)) : buffer; for (int i = 0; i < intLen; i++) { buf.prepend(bytes[n % 10]); n /= 10; } if (negative) buf.prepend((byte) '-'); return buffer == null ? buf.getInternalBuffer() : null; }
static byte[] getIsoBytes(int n, ByteBuffer buffer) { boolean negative = false; if (n < 0) { negative = true; n = -n; } int intLen = intSize(n); ByteBuffer buf = buffer == null ? new ByteBuffer(intLen + (negative ? 1 : 0)) : buffer; for (int i = 0; i < intLen; i++) { buf.prepend(bytes[n % 10]); n /= 10; } if (negative) buf.prepend((byte) '-'); return buffer == null ? buf.getInternalBuffer() : null; }
/** * 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); } }
public SerializedObjectContent serializeObject(PdfObject obj) { if (!obj.isStream() && !obj.isDictionary()) { return null; } PdfIndirectReference indRef = obj.getIndirectReference(); assert indRef != null; Map<PdfIndirectReference, byte[]> serializedCache = indRef.getDocument().serializedObjectsCache; byte[] content = serializedCache.get(indRef); if (content == null) { ByteBuffer bb = new ByteBuffer(); int level = 100; try { serObject(obj, bb, level, serializedCache); } catch (SelfReferenceException e) { return null; } content = bb.toByteArray(); } return new SerializedObjectContent(content); }
bb = new ByteBuffer(); obj = reference.getRefersTo();
@Override public byte[] convertToBytes(String text) { int len = text.length(); ByteBuffer buffer = new ByteBuffer(); int i = 0; if (fontProgram.isFontSpecific()) {
@Override protected void generateContent() { int length = value.length(); ByteBuffer buf = new ByteBuffer(length + 20); char c; char[] chars = value.toCharArray();
/** * Creates a PdfLiteral that contains an array of two id entries. These entries are both hexadecimal * strings containing 16 hex characters. The first entry is the original id, the second entry * should be different from the first one if the document has changed. * * @param firstId the first id * @param secondId the second id * @return PdfObject containing the two entries. */ public static PdfObject createInfoId(byte[] firstId, byte[] secondId) { if ( firstId.length < 16 ) { firstId = padByteArrayTo16(firstId); } if ( secondId.length < 16 ) { secondId = padByteArrayTo16(secondId); } com.itextpdf.io.source.ByteBuffer buf = new com.itextpdf.io.source.ByteBuffer(90); buf.append('[').append('<'); for (int k = 0; k < firstId.length; ++k) buf.appendHex(firstId[k]); buf.append('>').append('<'); for (int k = 0; k < secondId.length; ++k) buf.appendHex(secondId[k]); buf.append('>').append(']'); return new PdfLiteral(buf.toByteArray()); }
ByteBuffer bb = new ByteBuffer(spaceAvailable * 2); for (byte bi : signedContent) { bb.appendHex(bi);
ByteBuffer bb = new ByteBuffer(spaceAvailable * 2); for (byte bi : signedContent) { bb.appendHex(bi);
protected void fixXref() throws IOException { fixedXref = true; PdfXrefTable xref = pdfDocument.getXref(); tokens.seek(0); ByteBuffer buffer = new ByteBuffer(24); PdfTokenizer lineTokeniser = new PdfTokenizer(new RandomAccessFileOrArray(new ReusableRandomAccessSource(buffer))); for (; ; ) { long pos = tokens.getPosition(); buffer.reset(); if (!tokens.readLineSegment(buffer, true)) // added boolean because of mailing list issue (17 Feb. 2014) break; if (buffer.get(0) >= '0' && buffer.get(0) <= '9') { int[] obj = PdfTokenizer.checkObjectStart(lineTokeniser); if (obj == null) continue; int num = obj[0]; int gen = obj[1]; PdfIndirectReference reference = xref.get(num); if (reference != null && reference.getGenNumber() == gen) { reference.fixOffset(pos); } } } }
public static ByteBuffer createBufferedEscapedString(byte[] bytes) { ByteBuffer buf = new ByteBuffer(bytes.length * 2 + 2); buf.append('('); for (byte b : bytes) {
public static ByteBuffer createBufferedEscapedString(byte[] bytes) { ByteBuffer buf = new ByteBuffer(bytes.length * 2 + 2); buf.append('('); for (byte b : bytes) {
tokens.seek(0); trailer = null; ByteBuffer buffer = new ByteBuffer(24); PdfTokenizer lineTokeniser = new PdfTokenizer(new RandomAccessFileOrArray(new ReusableRandomAccessSource(buffer))); for (; ; ) {