-
Notifications
You must be signed in to change notification settings - Fork 282
read concated stream #76
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ public final class LZ4BlockInputStream extends FilterInputStream { | |
| private int originalLen; | ||
| private int o; | ||
| private boolean finished; | ||
| private boolean stopOnEmptyBlock; | ||
|
|
||
| /** | ||
| * Create a new {@link InputStream}. | ||
|
|
@@ -68,6 +69,11 @@ public LZ4BlockInputStream(InputStream in, LZ4FastDecompressor decompressor, Che | |
| this.compressedBuffer = new byte[HEADER_LENGTH]; | ||
| o = originalLen = 0; | ||
| finished = false; | ||
| stopOnEmptyBlock = true; | ||
| } | ||
|
|
||
| void setStopOnEmptyBlock(boolean stop) { | ||
| stopOnEmptyBlock = stop; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -90,6 +96,9 @@ public LZ4BlockInputStream(InputStream in) { | |
|
|
||
| @Override | ||
| public int available() throws IOException { | ||
| if (o == originalLen) { | ||
| refill(); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think typically available() just returns the remaining bytes in the buffer, and it should not call a blocking method like refill(), though it is not strictly prohibited. Do you have any reason you want to call refill() in available()?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not remember the the reason, maybe it's OK to not call refill() here. |
||
| return originalLen - o; | ||
| } | ||
|
|
||
|
|
@@ -147,7 +156,12 @@ public long skip(long n) throws IOException { | |
| } | ||
|
|
||
| private void refill() throws IOException { | ||
| readFully(compressedBuffer, HEADER_LENGTH); | ||
| try { | ||
| readFully(compressedBuffer, HEADER_LENGTH); | ||
| } catch (EOFException e) { | ||
| finished = true; | ||
| return; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should re-throw EOFException if stopOnEmptyBlock is true.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes |
||
| for (int i = 0; i < MAGIC_LENGTH; ++i) { | ||
| if (compressedBuffer[i] != MAGIC[i]) { | ||
| throw new IOException("Stream is corrupted"); | ||
|
|
@@ -175,7 +189,11 @@ private void refill() throws IOException { | |
| if (check != 0) { | ||
| throw new IOException("Stream is corrupted"); | ||
| } | ||
| finished = true; | ||
| if (!stopOnEmptyBlock) { | ||
| refill(); | ||
| } else { | ||
| finished = true; | ||
| } | ||
| return; | ||
| } | ||
| if (buffer.length < originalLen) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be a public method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.