Skip to content

Commit 73dbbbe

Browse files
committed
switch to bunzip2
1 parent de3b140 commit 73dbbbe

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/main/java/opendota/Main.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -102,32 +102,32 @@ public void handle(HttpExchange t) throws IOException {
102102
tStart = System.currentTimeMillis();
103103
// Write byte[] to bunzip, get back decompressed byte[]
104104
// The C decompressor is a bit faster than Java, 4.3 vs 4.8s
105-
BZip2CompressorInputStream bz = new BZip2CompressorInputStream(new ByteArrayInputStream(bzIn));
106-
bzOut = bz.readAllBytes();
107-
bz.close();
108-
109-
// Process bz = new ProcessBuilder(new String[] { "bunzip2" }).start();
110-
// // Start separate thread so we can consume output while sending input
111-
// new Thread(() -> {
112-
// try {
113-
// bz.getOutputStream().write(bzIn);
114-
// bz.getOutputStream().close();
115-
// } catch (IOException ex) {
116-
// ex.printStackTrace();
117-
// }
118-
// }).start();
119-
120-
// bzOut = bz.getInputStream().readAllBytes();
121-
// bz.getInputStream().close();
122-
// String bzError = new String(bz.getErrorStream().readAllBytes());
123-
// bz.getErrorStream().close();
124-
// System.err.println(bzError);
125-
// if (bzError.toString().contains("bunzip2: Data integrity error when decompressing") || bzError.contains("bunzip2: Compressed file ends unexpectedly")) {
126-
// // Corrupted replay, don't retry
127-
// t.sendResponseHeaders(204, 0);
128-
// t.getResponseBody().close();
129-
// return;
130-
// }
105+
// BZip2CompressorInputStream bz = new BZip2CompressorInputStream(new ByteArrayInputStream(bzIn));
106+
// bzOut = bz.readAllBytes();
107+
// bz.close();
108+
109+
Process bz = new ProcessBuilder(new String[] { "bunzip2" }).start();
110+
// Start separate thread so we can consume output while sending input
111+
new Thread(() -> {
112+
try {
113+
bz.getOutputStream().write(bzIn);
114+
bz.getOutputStream().close();
115+
} catch (IOException ex) {
116+
ex.printStackTrace();
117+
}
118+
}).start();
119+
120+
bzOut = bz.getInputStream().readAllBytes();
121+
bz.getInputStream().close();
122+
String bzError = new String(bz.getErrorStream().readAllBytes());
123+
bz.getErrorStream().close();
124+
System.err.println(bzError);
125+
if (bzError.toString().contains("bunzip2: Data integrity error when decompressing") || bzError.contains("bunzip2: Compressed file ends unexpectedly")) {
126+
// Corrupted replay, don't retry
127+
t.sendResponseHeaders(204, 0);
128+
t.getResponseBody().close();
129+
return;
130+
}
131131
tEnd = System.currentTimeMillis();
132132
System.err.format("bunzip2: %dms\n", tEnd - tStart);
133133
}

0 commit comments

Comments
 (0)