add back some new code
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1887685 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/java/org/apache/poi/poifs/filesystem/POIFSStream.java b/src/java/org/apache/poi/poifs/filesystem/POIFSStream.java
index 2b1b562..f34d4da 100644
--- a/src/java/org/apache/poi/poifs/filesystem/POIFSStream.java
+++ b/src/java/org/apache/poi/poifs/filesystem/POIFSStream.java
@@ -96,6 +96,15 @@
return new StreamBlockByteBufferIterator(startBlock);
}
+ Iterator<Integer> getBlockOffsetIterator() {
+ if(startBlock == POIFSConstants.END_OF_CHAIN) {
+ throw new IllegalStateException(
+ "Can't read from a new stream before it has been written to"
+ );
+ }
+ return new StreamBlockOffsetIterator(startBlock);
+ }
+
/**
* Updates the contents of the stream to the new
* set of bytes.
@@ -140,6 +149,42 @@
/**
* Class that handles a streaming read of one stream
*/
+ private class StreamBlockOffsetIterator implements Iterator<Integer> {
+ private final ChainLoopDetector loopDetector;
+ private int nextBlock;
+
+ StreamBlockOffsetIterator(int firstBlock) {
+ this.nextBlock = firstBlock;
+ try {
+ this.loopDetector = blockStore.getChainLoopDetector();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public boolean hasNext() {
+ return nextBlock != POIFSConstants.END_OF_CHAIN;
+ }
+
+ public Integer next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException("Can't read past the end of the stream");
+ }
+
+ loopDetector.claim(nextBlock);
+ int currentBlock = nextBlock;
+ nextBlock = blockStore.getNextBlock(nextBlock);
+ return currentBlock;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ /**
+ * Class that handles a streaming read of one stream
+ */
private class StreamBlockByteBufferIterator implements Iterator<ByteBuffer> {
private final ChainLoopDetector loopDetector;
private int nextBlock;