improved performances of net.woggioni.jzstd.ZstdInputStream
This commit is contained in:
@@ -15,6 +15,7 @@ public class ZstdInputStream extends InputStream {
|
||||
|
||||
private final ZSTD_inBuffer input;
|
||||
private final ZSTD_outBuffer output;
|
||||
private final byte[] buffer;
|
||||
|
||||
private enum State {
|
||||
AVAILABLE_INPUT, SOURCE_DEPLETED, CTX_FLUSHED
|
||||
@@ -33,6 +34,7 @@ public class ZstdInputStream extends InputStream {
|
||||
this.ctx_owner = ctx_owner;
|
||||
this.input = new ZSTD_inBuffer(inputBufferSize);
|
||||
this.output = new ZSTD_outBuffer(outputBufferSize);
|
||||
this.buffer = new byte[inputBufferSize];
|
||||
}
|
||||
|
||||
public static ZstdInputStream from(InputStream source) {
|
||||
@@ -55,13 +57,14 @@ public class ZstdInputStream extends InputStream {
|
||||
} else if(input.src.position() == input.src.capacity()) {
|
||||
input.src.position(0);
|
||||
}
|
||||
while (input.src.position() < input.src.capacity()) {
|
||||
int b = source.read();
|
||||
if (b < 0) {
|
||||
int toRead = input.src.capacity() - input.src.position();
|
||||
if(toRead > 0) {
|
||||
int read = source.read(buffer, 0, toRead);
|
||||
if(read < 0) {
|
||||
state = State.SOURCE_DEPLETED;
|
||||
break;
|
||||
}
|
||||
input.src.put((byte) b);
|
||||
input.src.put(buffer, 0, toRead);
|
||||
}
|
||||
input.pos = zero;
|
||||
input.size = new size_t(input.src.position());
|
||||
|
Reference in New Issue
Block a user