aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2013-04-17 13:22:35 +0300
committerLasse Collin <lasse.collin@tukaani.org>2013-04-17 13:22:35 +0300
commit98e36373ebf1a304c62adccee8aeda044efb2bfa (patch)
tree50a98308809051d11d750b669246d25e5fda6586 /src
parent1ea440146d98f164339f89b44a069b8af3323191 (diff)
downloadxz-java-98e36373ebf1a304c62adccee8aeda044efb2bfa.tar.gz
Add seekToBlock to SeekableXZInputStream.
Diffstat (limited to 'src')
-rw-r--r--src/org/tukaani/xz/SeekableXZInputStream.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/org/tukaani/xz/SeekableXZInputStream.java b/src/org/tukaani/xz/SeekableXZInputStream.java
index 45106e4..b54936d 100644
--- a/src/org/tukaani/xz/SeekableXZInputStream.java
+++ b/src/org/tukaani/xz/SeekableXZInputStream.java
@@ -722,6 +722,30 @@ public class SeekableXZInputStream extends SeekableInputStream {
}
/**
+ * Seeks to the beginning of the given XZ Block.
+ *
+ * @throws XZIOException
+ * if <code>blockNumber&nbsp;&lt;&nbsp;0</code> or
+ * <code>blockNumber&nbsp;&gt;=&nbsp;getBlockCount()</code>,
+ * or if stream has been closed
+ *
+ * @since 1.3
+ */
+ public void seekToBlock(int blockNumber) throws IOException {
+ if (in == null)
+ throw new XZIOException("Stream closed");
+
+ if (blockNumber < 0 || blockNumber >= blockCount)
+ throw new XZIOException("Invalid XZ Block number: " + blockNumber);
+
+ // This is a bit silly implementation. Here we locate the uncompressed
+ // offset of the specified Block, then when doing the actual seek in
+ // seek(), we need to find the Block number based on seekPos.
+ seekPos = getBlockPos(blockNumber);
+ seekNeeded = true;
+ }
+
+ /**
* Does the actual seeking. This is also called when <code>read</code>
* needs a new Block to decode.
*/