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