Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit b3b7a15

Browse files
authored
Merge pull request #24 from abeaumont/fix/update-manifest
native: Use a intermediate bytestream to handle stream closing
2 parents 958accb + 367d081 commit b3b7a15

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

native/src/main/java/bblfsh/ResponseWriter.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.fasterxml.jackson.databind.module.SimpleModule;
88
import org.eclipse.jdt.core.dom.CompilationUnit;
99

10+
import java.io.ByteArrayOutputStream;
1011
import java.io.IOException;
1112
import java.io.OutputStream;
1213

@@ -28,8 +29,12 @@ public ResponseWriter(final OutputStream out) {
2829
}
2930

3031
public void write(final Response response) throws IOException {
31-
mapper.writeValue(this.out, response);
32-
this.out.write('\n');
32+
// mapper closes the output stream after write, that's why we use an
33+
// intermediate output stream
34+
ByteArrayOutputStream out = new ByteArrayOutputStream();
35+
mapper.writeValue(out, response);
36+
out.write('\n');
37+
this.out.write(out.toByteArray());
3338
}
3439

3540
}

0 commit comments

Comments
 (0)