/** * Writes the JSON representation of this value to the given writer using the given formatting. * <p> * Writing performance can be improved by using a {@link java.io.BufferedWriter BufferedWriter}. * </p> * * @param writer * the writer to write this value to * @param config * a configuration that controls the formatting or <code>null</code> for the minimal form * @throws IOException * if an I/O error occurs in the writer */ public void writeTo(Writer writer, WriterConfig config) throws IOException { if (writer == null) { throw new NullPointerException("writer is null"); } if (config == null) { throw new NullPointerException("config is null"); } WritingBuffer buffer = new WritingBuffer(writer, 128); write(config.createWriter(buffer)); buffer.flush(); }
@Override public void write(int c) throws IOException { if (fill > buffer.length - 1) { flush(); } buffer[fill++] = (char)c; }
@Override public void write(String str, int off, int len) throws IOException { if (fill > buffer.length - len) { flush(); if (len > buffer.length) { writer.write(str, off, len); return; } } str.getChars(off, off + len, buffer, fill); fill += len; }
/** * Writes the JSON representation of this value to the given writer using the given formatting. * <p> * Writing performance can be improved by using a {@link java.io.BufferedWriter BufferedWriter}. * </p> * * @param writer * the writer to write this value to * @param config * a configuration that controls the formatting or <code>null</code> for the minimal form * @throws IOException * if an I/O error occurs in the writer */ public void writeTo(Writer writer, WriterConfig config) throws IOException { if (writer == null) { throw new NullPointerException("writer is null"); } if (config == null) { throw new NullPointerException("config is null"); } WritingBuffer buffer = new WritingBuffer(writer, 128); write(config.createWriter(buffer)); buffer.flush(); }
@Override public void write(char[] cbuf, int off, int len) throws IOException { if (fill > buffer.length - len) { flush(); if (len > buffer.length) { writer.write(cbuf, off, len); return; } } System.arraycopy(cbuf, off, buffer, fill, len); fill += len; }
/** * Writes the JSON representation of this value to the given writer using the given formatting. * <p> * Writing performance can be improved by using a {@link java.io.BufferedWriter BufferedWriter}. * </p> * * @param writer * the writer to write this value to * @param config * a configuration that controls the formatting or <code>null</code> for the minimal form * @throws IOException * if an I/O error occurs in the writer */ public void writeTo(Writer writer, WriterConfig config) throws IOException { if (writer == null) { throw new NullPointerException("writer is null"); } if (config == null) { throw new NullPointerException("config is null"); } WritingBuffer buffer = new WritingBuffer(writer, 128); write(config.createWriter(buffer)); buffer.flush(); }
@Override public void write(int c) throws IOException { if (fill > buffer.length - 1) { flush(); } buffer[fill++] = (char)c; }
@Override public void write(int c) throws IOException { if (fill > buffer.length - 1) { flush(); } buffer[fill++] = (char)c; }
@Override public void write(String str, int off, int len) throws IOException { if (fill > buffer.length - len) { flush(); if (len > buffer.length) { writer.write(str, off, len); return; } } str.getChars(off, off + len, buffer, fill); fill += len; }
@Override public void write(char[] cbuf, int off, int len) throws IOException { if (fill > buffer.length - len) { flush(); if (len > buffer.length) { writer.write(cbuf, off, len); return; } } System.arraycopy(cbuf, off, buffer, fill, len); fill += len; }
@Override public void write(String str, int off, int len) throws IOException { if (fill > buffer.length - len) { flush(); if (len > buffer.length) { writer.write(str, off, len); return; } } str.getChars(off, off + len, buffer, fill); fill += len; }
@Override public void write(char[] cbuf, int off, int len) throws IOException { if (fill > buffer.length - len) { flush(); if (len > buffer.length) { writer.write(cbuf, off, len); return; } } System.arraycopy(cbuf, off, buffer, fill, len); fill += len; }