@Override public String doWrite(List<? extends T> items) { StringBuilder lines = new StringBuilder(); Iterator<? extends T> iterator = items.iterator(); if (!items.isEmpty() && state.getLinesWritten() > 0) { lines.append(JSON_OBJECT_SEPARATOR).append(this.lineSeparator); } while (iterator.hasNext()) { T item = iterator.next(); lines.append(' ').append(this.jsonObjectMarshaller.marshal(item)); if (iterator.hasNext()) { lines.append(JSON_OBJECT_SEPARATOR).append(this.lineSeparator); } } return lines.toString(); }
/** * Writes out a string followed by a "new line", where the format of the new * line separator is determined by the underlying operating system. * * @param items list of items to be written to output stream * @throws Exception if an error occurs while writing items to the output stream */ @Override public void write(List<? extends T> items) throws Exception { if (!getOutputState().isInitialized()) { throw new WriterNotOpenException("Writer must be open before it can be written to"); } if (logger.isDebugEnabled()) { logger.debug("Writing to file with " + items.size() + " items."); } OutputState state = getOutputState(); String lines = doWrite(items); try { state.write(lines); } catch (IOException e) { throw new WriteFailedException("Could not write data. The file may be corrupt.", e); } state.setLinesWritten(state.getLinesWritten() + items.size()); }
@Override public String doWrite(List<? extends T> items) { StringBuilder lines = new StringBuilder(); Iterator<? extends T> iterator = items.iterator(); if (!items.isEmpty() && state.getLinesWritten() > 0) { lines.append(JSON_OBJECT_SEPARATOR).append(this.lineSeparator); } while (iterator.hasNext()) { T item = iterator.next(); lines.append(' ').append(this.jsonObjectMarshaller.marshal(item)); if (iterator.hasNext()) { lines.append(JSON_OBJECT_SEPARATOR).append(this.lineSeparator); } } return lines.toString(); }
/** * Writes out a string followed by a "new line", where the format of the new * line separator is determined by the underlying operating system. * * @param items list of items to be written to output stream * @throws Exception if an error occurs while writing items to the output stream */ @Override public void write(List<? extends T> items) throws Exception { if (!getOutputState().isInitialized()) { throw new WriterNotOpenException("Writer must be open before it can be written to"); } if (logger.isDebugEnabled()) { logger.debug("Writing to file with " + items.size() + " items."); } OutputState state = getOutputState(); String lines = doWrite(items); try { state.write(lines); } catch (IOException e) { throw new WriteFailedException("Could not write data. The file may be corrupt.", e); } state.setLinesWritten(state.getLinesWritten() + items.size()); }