/** * Workaround for RFE #4093999 ("Relax constraint on placement of this()/super() * call in constructors") */ private IndentedLineWriter(final Formatter formatter) { super(IO.asWriter(formatter)); formatter.enclosing = this; }
/** * If {@link #out} implements {@link java.io.Flushable}, or is a {@link Appender} wrapper * around a flushable object, delegates to that object. Otherwise do nothing. */ @Override @SuppressWarnings("SynchronizeOnNonFinalField") public void flush() throws IOException { synchronized (lock) { IO.flush(out); } }
/** * If {@link #out} implements {@link java.io.Closeable}, or is a {@link Appender} wrapper * around a closeable object, delegates to that object. Otherwise just flush (if possible). */ @Override @SuppressWarnings("SynchronizeOnNonFinalField") public void close() throws IOException { synchronized (lock) { IO.close(out); } }
/** * Returns the content of the given {@code Appendable} as a string if possible, * or the localized <cite>"Unavailable content"</cite> string otherwise. */ static String toString(final Appendable out) { final CharSequence content = IO.content(out); if (content != null) { return content.toString(); } return Vocabulary.format(Vocabulary.Keys.UnavailableContent); }
/** * Returns the content of this {@code Appendable} as a string if possible, * or the localized <cite>"Unavailable content"</cite> string otherwise. * * @return the content of this {@code Appendable}, or a localized message for unavailable content. * * @see IO#content(Appendable) */ @Override public String toString() { return IO.toString(this); } }
/** * Returns the content of the given {@code Appendable} as a string if possible, * or the localized <cite>"Unavailable content"</cite> string otherwise. */ static String toString(final Appendable out) { final CharSequence content = IO.content(out); if (content != null) { return content.toString(); } return Vocabulary.format(Vocabulary.Keys.UnavailableContent); }
/** * Returns the content of this {@code Appendable} as a string if possible, * or the localized <cite>"Unavailable content"</cite> string otherwise. * * @return the content of this {@code Appendable}, or a localized message for unavailable content. * * @see IO#content(Appendable) */ @Override public String toString() { return IO.toString(this); } }
/** * Workaround for RFE #4093999 ("Relax constraint on placement of this()/super() * call in constructors") */ private LineWriter(final LineAppender formatter) { super(IO.asWriter(formatter)); this.formatter = formatter; }
/** * If {@link #out} implements {@link java.io.Flushable}, or is a {@link Appender} wrapper * around a flushable object, delegates to that object. Otherwise do nothing. */ @Override @SuppressWarnings("SynchronizeOnNonFinalField") public void flush() throws IOException { synchronized (lock) { IO.flush(out); } }
/** * Returns the content of the given writer, or {@code null} if none. */ static String content(final Writer out) { if (out instanceof StringWriter) { return out.toString(); } if (out instanceof FilterWriter) { return ((FilterWriter) out).content(); } final CharSequence cs = IO.content(out); if (cs != null) { return cs.toString(); } return null; }
/** * Returns the content of the underlying {@link Appendable} as a string if possible, * or the localized <cite>"Unavailable content"</cite> string otherwise. * * @return the content of the underlying {@code Appendable}, * or a localized message for unavailable content. * * @see IO#content(Appendable) */ @Override @SuppressWarnings("SynchronizeOnNonFinalField") public String toString() { synchronized (lock) { return IO.toString(out); } } }
/** * If {@link #out} implements {@link java.io.Closeable}, or is a {@link Appender} wrapper * around a closeable object, delegates to that object. Otherwise just flush (if possible). */ @Override @SuppressWarnings("SynchronizeOnNonFinalField") public void close() throws IOException { synchronized (lock) { IO.close(out); } }
/** * Workaround for RFE #4093999 ("Relax constraint on placement of this()/super() * call in constructors") */ private ExpandedTabWriter(final LineAppender formatter) { super(IO.asWriter(formatter)); this.formatter = formatter; formatter.setTabulationExpanded(true); }
/** * Sends all pending characters to the underlying appendable, including trailing whitespaces. * Note that this method should preferably be invoked at the end of a word, sentence or line, * since invoking this method may prevent {@code LineAppender} to properly wrap the current * line if the current position is in the middle of a word. * * <p>Invoking this method also flushes the underlying stream, if {@linkplain Flushable flushable}. * A cheaper way to send pending characters is to make sure that the last character is a * {@linkplain Characters#isLineOrParagraphSeparator(int) line or paragraph terminator}, * or to invoke {@link #clear()}.</p> * * @throws IOException if an I/O error occurs. */ @Override public void flush() throws IOException { out.append(buffer); buffer.setLength(0); printableLength = 0; IO.flush(out); }
/** * Returns the content of the underlying {@link Appendable} as a string if possible, * or the localized <cite>"Unavailable content"</cite> string otherwise. * * @return the content of the underlying {@code Appendable}, * or a localized message for unavailable content. * * @see IO#content(Appendable) */ @Override @SuppressWarnings("SynchronizeOnNonFinalField") public String toString() { synchronized (lock) { return IO.toString(out); } } }
/** * Tests a few {@link java.io.Writer#write(String)} calls, * with Unix line terminators in the sequences. * * @throws IOException should never happen since the tests will write in a buffer. */ public void testSequencesToWriter() throws IOException { appender = IO.asWriter(appender); run("\n"); } }
/** * Sends all pending characters to the underlying appendable, including trailing whitespaces. * Note that this method should preferably be invoked at the end of a word, sentence or line, * since invoking this method may prevent {@code LineAppender} to properly wrap the current * line if the current position is in the middle of a word. * * <p>Invoking this method also flushes the underlying stream, if {@linkplain Flushable flushable}. * A cheaper way to send pending characters is to make sure that the last character is a * {@linkplain Characters#isLineOrParagraphSeparator(int) line or paragraph terminator}, * or to invoke {@link #clear()}.</p> * * @throws IOException if an I/O error occurs. */ @Override public void flush() throws IOException { out.append(buffer); buffer.setLength(0); printableLength = 0; IO.flush(out); }
writer = new LineAppender(str, System.lineSeparator(), true); buffer = str.getBuffer().append(header); printer = new PrintWriter(IO.asWriter(writer)); writer.setTabulationWidth(4);
/** * Flushes the table content to the underlying stream or buffer. This method should not * be called before the table is completed (otherwise, columns may have the wrong width). * * @throws IOException if an output operation failed. */ @Override public void flush() throws IOException { if (buffer.length() != 0) { nextLine(); assert buffer.length() == 0; } if (!ownOut) { writeTable(); } cells.clear(); currentRow = 0; currentColumn = 0; if (!(out instanceof TableAppender)) { /* * Flush only if this table is not included in an outer (bigger) table. * This is because flushing the outer table would break its formatting. */ IO.flush(out); } }
writer = new LineAppender(str, System.lineSeparator(), true); buffer = str.getBuffer().append(header); printer = new PrintWriter(IO.asWriter(writer)); writer.setTabulationWidth(4);