writer.flush(); } finally { writer.close();
@SuppressWarnings("unchecked") @Override public void write(Gson gson, Type type, Object object, OutputStream stream) throws IOException { @Nullable JsonWriter writer = null; boolean wasOriginalException = false; try { writer = new JsonWriter(new BufferedWriter(new OutputStreamWriter(stream, CHARSET_NAME))); options.setWriterOptions(writer); gson.getAdapter((TypeToken<Object>) TypeToken.get(type)).write(writer, object); } catch (IOException ex) { wasOriginalException = true; throw ex; } catch (Exception ex) { wasOriginalException = true; throw new IOException(ex); } finally { if (writer != null) { try { // underlying stream should not be closed, just flushing writer.flush(); } catch (IOException ex) { if (!wasOriginalException) { throw ex; } } } } }
@Override public void flush() throws IOException { writer.flush(); }
@Override public JsonLikeWriter flush() throws IOException { if (blockType != BlockType.NONE) { log.error("JsonLikeStreamWriter.flush() called but JSON document is not finished"); } eventWriter.flush(); getWriter().flush(); return this; }
@Override public void close() throws IOException { jsonWriter.endArray(); jsonWriter.flush(); jsonWriter.close(); } }
/** * Flushes the writer. * * @throws IOException Something went wrong writing */ public void flush() throws IOException { writer.flush(); }
public void flush() throws CityJSONWriteException { try { writer.flush(); } catch (IOException e) { throw new CityJSONWriteException("Caused by: ", e); } }
@Override public <T> void writeValue(OutputStream ostream, T instance) throws Exception { JsonWriter writer = new JsonWriter(new OutputStreamWriter(ostream, "UTF-8")); mGson.toJson(instance, instance.getClass(), writer); writer.flush(); writer.close(); }
ContentProducer cp = new ContentProducer() { public void writeTo(OutputStream outstream) throws IOException { JsonWriter writer = new JsonWriter(new OutputStreamWriter(outstream, "UTF-8")); // write code here writer.flush(); } }; HttpEntity entity = new EntityTemplate(cp); HttpPost httppost = new HttpPost("http://server.address"); httppost.setEntity(entity);
@Override public void close() throws IOException { jsonWriter.endArray(); jsonWriter.flush(); jsonWriter.close(); } }
@Override public void write(JsonWriter writer, SpeechWordConfidence speechWordConfidence) throws IOException { writer.beginArray(); writer.value(speechWordConfidence.getWord()); writer.value(speechWordConfidence.getConfidence()); writer.endArray(); writer.flush(); } }
@Override public void write(JsonWriter out, MarkTiming markTiming) throws IOException { out.beginArray(); out.value(markTiming.getMark()); out.value(markTiming.getTime()); out.endArray(); out.flush(); } }
@Override public void write(JsonWriter out, WordTiming wordTiming) throws IOException { out.beginArray(); out.value(wordTiming.getWord()); out.value(wordTiming.getStartTime()); out.value(wordTiming.getEndTime()); out.endArray(); out.flush(); } }
@Override public void write(JsonWriter out, MarkTiming markTiming) throws IOException { out.beginArray(); out.value(markTiming.getMark()); out.value(markTiming.getTime()); out.endArray(); out.flush(); } }
@Override public void write(JsonWriter writer, SpeechTimestamp speechTimestamp) throws IOException { writer.beginArray(); writer.value(speechTimestamp.getWord()); writer.value(speechTimestamp.getStartTime()); writer.value(speechTimestamp.getEndTime()); writer.endArray(); writer.flush(); } }
@Override protected ByteBuf writeLogEvents(CloseableIterator<LogEvent> logEventIter) throws IOException { channelBuffer.clear(); while (logEventIter.hasNext() && channelBuffer.readableBytes() < BUFFER_BYTES) { Object encodedObject = encodeSend(logEventIter.next()); GSON.toJson(encodedObject, encodedObject.getClass(), jsonWriter); jsonWriter.flush(); } return channelBuffer.copy(); }
@Override protected ByteBuf writeLogEvents(CloseableIterator<LogEvent> logEventIter) throws IOException { channelBuffer.clear(); while (logEventIter.hasNext() && channelBuffer.readableBytes() < BUFFER_BYTES) { Object encodedObject = encodeSend(logEventIter.next()); GSON.toJson(encodedObject, encodedObject.getClass(), jsonWriter); jsonWriter.flush(); } return channelBuffer.copy(); }
@Override public void write(JsonWriter writer, SpeechTimestamp speechTimestamp) throws IOException { writer.beginArray(); writer.value(speechTimestamp.getWord()); writer.value(speechTimestamp.getStartTime()); writer.value(speechTimestamp.getEndTime()); writer.endArray(); writer.flush(); } }
@Override protected ByteBuf onWriteStart() throws IOException { channelBuffer.clear(); jsonWriter.beginArray(); jsonWriter.flush(); return channelBuffer.copy(); }
@Override protected ByteBuf onWriteFinish() throws IOException { channelBuffer.clear(); jsonWriter.endArray(); jsonWriter.flush(); return channelBuffer.copy(); }