summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/LayeredBlockReader.java
diff options
context:
space:
mode:
authorBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-08 22:39:59 -0300
committerBenjamin J. Culkin <bjculkin@mix.wvu.edu>2017-10-08 22:39:59 -0300
commitc82e3b3b2de0633317ec8fc85925e91422820597 (patch)
tree96567416ce23c5ce85601f9cedc3a94bb1c55cba /BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/LayeredBlockReader.java
parentb3ac1c8690c3e14c879913e5dcc03a5f5e14876e (diff)
Start splitting into maven modules
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/LayeredBlockReader.java')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/LayeredBlockReader.java81
1 files changed, 0 insertions, 81 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/LayeredBlockReader.java b/BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/LayeredBlockReader.java
deleted file mode 100644
index 967a1f2..0000000
--- a/BJC-Utils2/src/main/java/bjc/utils/ioutils/blocks/LayeredBlockReader.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package bjc.utils.ioutils.blocks;
-
-import java.io.IOException;
-
-/**
- * A block reader that supports draining all the blocks from one reading before
- * swapping to another.
- *
- * This is more a 'prioritize blocks from one over the other', than a 'read all
- * the blocks from one, then all the blocks from the other'. If you need that,
- * look at {@link SerialBlockReader}.
- *
- * @author bjculkin
- *
- */
-public class LayeredBlockReader implements BlockReader {
- /*
- * The readers to drain from.
- */
- private final BlockReader first;
- private final BlockReader second;
-
- /*
- * The current block number.
- */
- private int blockNo;
-
- /**
- * Create a new layered block reader.
- *
- * @param primary
- * The first source to read blocks from.
- *
- * @param secondary
- * The second source to read blocks from.
- */
- public LayeredBlockReader(final BlockReader primary, final BlockReader secondary) {
- first = primary;
- second = secondary;
- }
-
- @Override
- public boolean hasNextBlock() {
- return first.hasNextBlock() || second.hasNextBlock();
- }
-
- @Override
- public Block getBlock() {
- final Block firstBlock = first.getBlock();
-
- /*
- * Only drain a block from the second reader if none are
- * available in the first reader.
- */
- return firstBlock == null ? second.getBlock() : firstBlock;
- }
-
- @Override
- public boolean nextBlock() {
- final boolean gotFirst = first.nextBlock();
- final boolean succ = gotFirst ? gotFirst : second.nextBlock();
-
- if (succ) {
- blockNo += 1;
- }
-
- return succ;
- }
-
- @Override
- public int getBlockCount() {
- return blockNo;
- }
-
- @Override
- public void close() throws IOException {
- second.close();
-
- first.close();
- }
-}