/** * Appends the specified character sequence. * The default implementation delegates to {@link #append(CharSequence, int, int)}. * * @param sequence the character sequence to append, or {@code null}. * @return a reference to this {@code Appendable}. * @throws IOException if an I/O error occurred. */ @Override public Appendable append(CharSequence sequence) throws IOException { if (sequence == null) { sequence = "null"; } return append(sequence, 0, sequence.length()); }
/** * Finds the line separator used in the given character sequence portion, or returns * {@code null} if unknown. This method is designed for invocation at the beginning * of {@code append(CharSequence, ...)}, before the characters are effectively read. */ final String lineSeparator(final CharSequence sequence, int start, final int end) { if (isHighSurrogate()) { start++; // Skip invalid character. } while (start < end) { final int c = Character.codePointAt(sequence, start); final int b = start; start += Character.charCount(c); if (isLineOrParagraphSeparator(c)) { if (c == '\r' && (start < end) && sequence.charAt(start) == '\n') { start++; } return sequence.subSequence(b, start).toString(); } } return null; }
/** * Returns the content of this {@code TableAppender} as a string if possible. * * <ul> * <li>If this {@code TableAppender} has been created without explicit {@link Appendable}, * then this method always returns the current table content formatted as a string.</li> * <li>Otherwise, if {@link #out} implements {@link CharSequence} or is directly or * indirectly a wrapper around a {@code CharSequence}, returns its {@code toString()} * representation. The string will contain this table content only if {@link #flush()} * has been invoked prior this {@code toString()} method.</li> * <li>Otherwise returns the localized <cite>"Unavailable content"</cite> string.</li> * </ul> */ @Override public String toString() { if (ownOut) { ((StringBuilder) out).setLength(0); try { writeTable(); } catch (IOException e) { // Should never happen because we are writing in a StringBuilder. throw new AssertionError(e); } } return super.toString(); }
/** * Finds the line separator used in the given character sequence portion, or returns * {@code null} if unknown. This method is designed for invocation at the beginning * of {@code append(CharSequence, ...)}, before the characters are effectively read. */ final String lineSeparator(final CharSequence sequence, int start, final int end) { if (isHighSurrogate()) { start++; // Skip invalid character. } while (start < end) { final int c = Character.codePointAt(sequence, start); final int b = start; start += Character.charCount(c); if (isLineOrParagraphSeparator(c)) { if (c == '\r' && (start < end) && sequence.charAt(start) == '\n') { start++; } return sequence.subSequence(b, start).toString(); } } return null; }
/** * Returns the content of this {@code TableAppender} as a string if possible. * * <ul> * <li>If this {@code TableAppender} has been created without explicit {@link Appendable}, * then this method always returns the current table content formatted as a string.</li> * <li>Otherwise, if {@link #out} implements {@link CharSequence} or is directly or * indirectly a wrapper around a {@code CharSequence}, returns its {@code toString()} * representation. The string will contain this table content only if {@link #flush()} * has been invoked prior this {@code toString()} method.</li> * <li>Otherwise returns the localized <cite>"Unavailable content"</cite> string.</li> * </ul> */ @Override public String toString() { if (ownOut) { ((StringBuilder) out).setLength(0); try { writeTable(); } catch (IOException e) { // Should never happen because we are writing in a StringBuilder. throw new UncheckedIOException(e); } } return super.toString(); }
/** * Appends the specified character sequence. * The default implementation delegates to {@link #append(CharSequence, int, int)}. * * @param sequence the character sequence to append, or {@code null}. * @return a reference to this {@code Appendable}. * @throws IOException if an I/O error occurred. */ @Override public Appendable append(CharSequence sequence) throws IOException { if (sequence == null) { sequence = "null"; } return append(sequence, 0, sequence.length()); }
/** * If the given sequence begins with a low surrogate completing a previous high surrogate, * delegates to {@link #append(char)} and returns {@code start+1}. The intent is to avoid * processing a character sequence which starts by an invalid code point. * * @param sequence the character sequence to write. * @param start index of the first character to write by this method or by the caller. * @param end index after the last character to be written by the caller. * @return index of the first character which need to be written by the caller. */ final int appendSurrogate(final CharSequence sequence, int start, final int end) throws IOException { if (start != end && highSurrogate != 0) { final char c = sequence.charAt(start); if (Character.isLowSurrogate(c)) { append(c); start++; } else { throw new CharConversionException(); } } return start; }
/** * If the given sequence begins with a low surrogate completing a previous high surrogate, * delegates to {@link #append(char)} and returns {@code start+1}. The intend is to avoid * processing a character sequence which starts by an invalid code point. * * @param sequence the character sequence to write. * @param start index of the first character to write by this method or by the caller. * @param end index after the last character to be written by the caller. * @return index of the first character which need to be written by the caller. */ final int appendSurrogate(final CharSequence sequence, int start, final int end) throws IOException { if (start != end && highSurrogate != 0) { final char c = sequence.charAt(start); if (Character.isLowSurrogate(c)) { append(c); start++; } else { throw new CharConversionException(); } } return start; }