public IRandomAccessSource CreateRanged(IRandomAccessSource source, IList<long> ranges) { IRandomAccessSource[] sources = new IRandomAccessSource[ranges.Count/2]; for(int i = 0; i < ranges.Count; i+=2){ sources[i/2] = new WindowRandomAccessSource(source, ranges[i], ranges[i+1]); } return new GroupedRandomAccessSource(sources); }
virtual public void TestBasics() { WindowRandomAccessSource window = new WindowRandomAccessSource(source, 7, 17); Assert.AreEqual(17, window.Length); byte[] output = new byte[45]; Assert.AreEqual(17, window.Get(0, output, 0, 17)); Assert.AreEqual(7, window.Get(0)); Assert.AreEqual(17, window.Get(10)); Assert.AreEqual(-1, window.Get(17)); Assert.AreEqual(17, window.Get(0, output, 0, 45)); for (int i = 0; i < 17; i++) { Assert.AreEqual(data[i + 7], output[i]); } }
/** * 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 PRTokeniser GetOffsetTokeniser(IRandomAccessSource byteSource) { PRTokeniser tok = new PRTokeniser(new RandomAccessFileOrArray(byteSource)); int offset = tok.GetHeaderOffset(); if (offset != 0){ IRandomAccessSource offsetSource = new WindowRandomAccessSource(byteSource, offset); tok = new PRTokeniser(new RandomAccessFileOrArray(offsetSource)); } return tok; }
public IRandomAccessSource CreateRanged(IRandomAccessSource source, IList<long> ranges) { IRandomAccessSource[] sources = new IRandomAccessSource[ranges.Count/2]; for(int i = 0; i < ranges.Count; i+=2){ sources[i/2] = new WindowRandomAccessSource(source, ranges[i], ranges[i+1]); } return new GroupedRandomAccessSource(sources); }