@@ -93,30 +93,42 @@ public void handle(HttpExchange t) throws IOException {
9393 if (replayUrl .toString ().endsWith (".bz2" )) {
9494 tStart = System .currentTimeMillis ();
9595 // Write byte[] to bunzip, get back decompressed byte[]
96+ // The C decompressor is a bit faster than Java, 4.3 vs 4.8s
97+ // BZip2CompressorInputStream bz = new BZip2CompressorInputStream(new ByteArrayInputStream(bzIn));
98+ // bzOut = bz.readAllBytes();
99+ // bz.close();
100+
96101 Process bz = new ProcessBuilder (new String [] { "bunzip2" }).start ();
97102 // Start separate thread so we can consume output while sending input
98- Thread thread = new Thread (() -> {
103+ new Thread (() -> {
99104 try {
100105 bz .getOutputStream ().write (bzIn );
101106 bz .getOutputStream ().close ();
102107 } catch (IOException ex ) {
103108 ex .printStackTrace ();
104109 }
105- });
106- thread .start ();
110+ }).start ();
107111
108112 bzOut = bz .getInputStream ().readAllBytes ();
113+ bz .getInputStream ().close ();
109114 String bzError = new String (bz .getErrorStream ().readAllBytes ());
115+ bz .getErrorStream ().close ();
110116 System .err .println (bzError );
117+ if (bzError .toString ().contains ("bunzip2: Data integrity error when decompressing" ) || bzError .contains ("bunzip2: Compressed file ends unexpectedly" )) {
118+ // Corrupted replay, don't retry
119+ t .sendResponseHeaders (200 , 0 );
120+ t .getResponseBody ().close ();
121+ return ;
122+ }
111123 tEnd = System .currentTimeMillis ();
112124 System .err .format ("bunzip2: %dms\n " , tEnd - tStart );
113125 }
114126
115127 // Start parser with input stream created from byte[]
116128 tStart = System .currentTimeMillis ();
117- ByteArrayOutputStream baos2 = new ByteArrayOutputStream ();
118- new Parse (new ByteArrayInputStream (bzOut ), baos2 , true );
119- byte [] parseOut = baos2 .toByteArray ();
129+ ByteArrayOutputStream parseOutStream = new ByteArrayOutputStream ();
130+ new Parse (new ByteArrayInputStream (bzOut ), parseOutStream , true );
131+ byte [] parseOut = parseOutStream .toByteArray ();
120132 tEnd = System .currentTimeMillis ();
121133 System .err .format ("parse: %dms\n " , tEnd - tStart );
122134
0 commit comments