-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Compression] Wrap output stream with decompression
- Loading branch information
1 parent
a9c8861
commit 3d6339e
Showing
2 changed files
with
50 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/google/devtools/build/lib/remote/ZstdDecompressingOutputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.google.devtools.build.lib.remote; | ||
|
||
import com.github.luben.zstd.ZstdInputStream; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
public class ZstdDecompressingOutputStream extends OutputStream { | ||
private final ByteArrayOutputStream baos; | ||
private final ZstdInputStream zis; | ||
private final OutputStream out; | ||
private int lastByte; | ||
|
||
ZstdDecompressingOutputStream(OutputStream out) throws IOException { | ||
this.out = out; | ||
baos = new ByteArrayOutputStream(); | ||
zis = | ||
new ZstdInputStream( | ||
new InputStream() { | ||
@Override | ||
public int read() throws IOException { | ||
int value = lastByte; | ||
lastByte = -1; | ||
return value; | ||
} | ||
}); | ||
zis.setContinuous(true); | ||
} | ||
|
||
@Override | ||
public void write(int b) throws IOException { | ||
lastByte = b; | ||
int c; | ||
while ((c = zis.read()) != -1) { | ||
out.write(c); | ||
} | ||
} | ||
} |