001 /*
002 * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.lang;
027
028 import java.io.IOException;
029
030 /**
031 * An object to which <tt>char</tt> sequences and values can be appended. The
032 * <tt>Appendable</tt> interface must be implemented by any class whose
033 * instances are intended to receive formatted output from a {@link
034 * java.util.Formatter}.
035 *
036 * <p> The characters to be appended should be valid Unicode characters as
037 * described in <a href="Character.html#unicode">Unicode Character
038 * Representation</a>. Note that supplementary characters may be composed of
039 * multiple 16-bit <tt>char</tt> values.
040 *
041 * <p> Appendables are not necessarily safe for multithreaded access. Thread
042 * safety is the responsibility of classes that extend and implement this
043 * interface.
044 *
045 * <p> Since this interface may be implemented by existing classes
046 * with different styles of error handling there is no guarantee that
047 * errors will be propagated to the invoker.
048 *
049 * @version 1.10, 05/05/07
050 * @since 1.5
051 */
052 public interface Appendable {
053
054 /**
055 * Appends the specified character sequence to this <tt>Appendable</tt>.
056 *
057 * <p> Depending on which class implements the character sequence
058 * <tt>csq</tt>, the entire sequence may not be appended. For
059 * instance, if <tt>csq</tt> is a {@link java.nio.CharBuffer} then
060 * the subsequence to append is defined by the buffer's position and limit.
061 *
062 * @param csq
063 * The character sequence to append. If <tt>csq</tt> is
064 * <tt>null</tt>, then the four characters <tt>"null"</tt> are
065 * appended to this Appendable.
066 *
067 * @return A reference to this <tt>Appendable</tt>
068 *
069 * @throws IOException
070 * If an I/O error occurs
071 */
072 Appendable append(CharSequence csq) throws IOException;
073
074 /**
075 * Appends a subsequence of the specified character sequence to this
076 * <tt>Appendable</tt>.
077 *
078 * <p> An invocation of this method of the form <tt>out.append(csq, start,
079 * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
080 * exactly the same way as the invocation
081 *
082 * <pre>
083 * out.append(csq.subSequence(start, end)) </pre>
084 *
085 * @param csq
086 * The character sequence from which a subsequence will be
087 * appended. If <tt>csq</tt> is <tt>null</tt>, then characters
088 * will be appended as if <tt>csq</tt> contained the four
089 * characters <tt>"null"</tt>.
090 *
091 * @param start
092 * The index of the first character in the subsequence
093 *
094 * @param end
095 * The index of the character following the last character in the
096 * subsequence
097 *
098 * @return A reference to this <tt>Appendable</tt>
099 *
100 * @throws IndexOutOfBoundsException
101 * If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
102 * is greater than <tt>end</tt>, or <tt>end</tt> is greater than
103 * <tt>csq.length()</tt>
104 *
105 * @throws IOException
106 * If an I/O error occurs
107 */
108 Appendable append(CharSequence csq, int start, int end)
109 throws IOException;
110
111 /**
112 * Appends the specified character to this <tt>Appendable</tt>.
113 *
114 * @param c
115 * The character to append
116 *
117 * @return A reference to this <tt>Appendable</tt>
118 *
119 * @throws IOException
120 * If an I/O error occurs
121 */
122 Appendable append(char c) throws IOException;
123 }
|