write start array only after opening output and

write end array only after closing process

Original commit: elastic/x-pack-elasticsearch@b549ec3552
This commit is contained in:
Martijn van Groningen 2016-11-23 08:23:57 +01:00
parent f8569ca353
commit 423a9cf7b2
1 changed files with 2 additions and 2 deletions

View File

@ -45,6 +45,7 @@ public class BlackHoleAutodetectProcess implements AutodetectProcess, Closeable
persistStream = new PipedInputStream();
try {
pipedProcessOutStream = new PipedOutputStream(processOutStream);
pipedProcessOutStream.write('[');
pipedPersistStream = new PipedOutputStream(persistStream);
} catch (IOException e) {
LOGGER.error("Error connecting PipedOutputStream", e);
@ -74,9 +75,7 @@ public class BlackHoleAutodetectProcess implements AutodetectProcess, Closeable
FlushAcknowledgement flushAcknowledgement = new FlushAcknowledgement(FLUSH_ID);
AutodetectResult result = new AutodetectResult(null, null, null, null, null, null, flushAcknowledgement);
XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent());
builder.startArray();
builder.value(result);
builder.endArray();
pipedProcessOutStream.write(builder.string().getBytes(StandardCharsets.UTF_8));
pipedProcessOutStream.flush();
return FLUSH_ID;
@ -88,6 +87,7 @@ public class BlackHoleAutodetectProcess implements AutodetectProcess, Closeable
@Override
public void close() throws IOException {
pipedProcessOutStream.write(']');
pipedProcessOutStream.close();
pipedPersistStream.close();
}