public IRandomAccessSource createRanged(IRandomAccessSource source, long[] ranges) throws java.io.IOException { IRandomAccessSource[] sources = new IRandomAccessSource[ranges.length/2]; for(int i = 0; i < ranges.length; i+=2){ sources[i/2] = new WindowRandomAccessSource(source, ranges[i], ranges[i+1]); } return new GroupedRandomAccessSource(sources); }
public IRandomAccessSource createRanged(IRandomAccessSource source, long[] ranges) throws java.io.IOException { IRandomAccessSource[] sources = new IRandomAccessSource[ranges.length/2]; for(int i = 0; i < ranges.length; i+=2){ sources[i/2] = new WindowRandomAccessSource(source, ranges[i], ranges[i+1]); } return new GroupedRandomAccessSource(sources); }
/** * Extracts a revision from the document. * * @param field the signature field name * @return an InputStream covering the revision. Returns null if it's not a signature field * @throws IOException */ public InputStream extractRevision(String field) throws IOException { getSignatureNames(); if (!sigNames.containsKey(field)) return null; int length = sigNames.get(field)[0]; RandomAccessFileOrArray raf = document.getReader().getSafeFile(); return new RASInputStream(new WindowRandomAccessSource(raf.createSourceView(), 0, length)); }
/** * Extracts a revision from the document. * * @param field the signature field name * @return an InputStream covering the revision. Returns null if it's not a signature field * @throws IOException */ public InputStream extractRevision(String field) throws IOException { getSignatureNames(); if (!sigNames.containsKey(field)) return null; int length = sigNames.get(field)[0]; RandomAccessFileOrArray raf = document.getReader().getSafeFile(); return new RASInputStream(new WindowRandomAccessSource(raf.createSourceView(), 0, length)); }
/** * Utility method that checks the provided byte source to see if it has junk bytes at the beginning. If junk bytes * are found, construct a tokeniser that ignores the junk. Otherwise, construct a tokeniser for the byte source as it is * * @param byteSource the source to check * @return a tokeniser that is guaranteed to start at the PDF header * @throws IOException if there is a problem reading the byte source */ private static PdfTokenizer getOffsetTokeniser(IRandomAccessSource byteSource) throws IOException { PdfTokenizer tok = new PdfTokenizer(new RandomAccessFileOrArray(byteSource)); int offset = tok.getHeaderOffset(); if (offset != 0) { IRandomAccessSource offsetSource = new WindowRandomAccessSource(byteSource, offset); tok = new PdfTokenizer(new RandomAccessFileOrArray(offsetSource)); } return tok; }