Path: blob/master/src/java.base/share/classes/java/lang/Appendable.java
41152 views
/*1* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.lang;2627import java.io.IOException;2829/**30* An object to which {@code char} sequences and values can be appended. The31* {@code Appendable} interface must be implemented by any class whose32* instances are intended to receive formatted output from a {@link33* java.util.Formatter}.34*35* <p> The characters to be appended should be valid Unicode characters as36* described in <a href="Character.html#unicode">Unicode Character37* Representation</a>. Note that supplementary characters may be composed of38* multiple 16-bit {@code char} values.39*40* <p> Appendables are not necessarily safe for multithreaded access. Thread41* safety is the responsibility of classes that extend and implement this42* interface.43*44* <p> Since this interface may be implemented by existing classes45* with different styles of error handling there is no guarantee that46* errors will be propagated to the invoker.47*48* @since 1.549*/50public interface Appendable {5152/**53* Appends the specified character sequence to this {@code Appendable}.54*55* <p> Depending on which class implements the character sequence56* {@code csq}, the entire sequence may not be appended. For57* instance, if {@code csq} is a {@link java.nio.CharBuffer} then58* the subsequence to append is defined by the buffer's position and limit.59*60* @param csq61* The character sequence to append. If {@code csq} is62* {@code null}, then the four characters {@code "null"} are63* appended to this Appendable.64*65* @return A reference to this {@code Appendable}66*67* @throws IOException68* If an I/O error occurs69*/70Appendable append(CharSequence csq) throws IOException;7172/**73* Appends a subsequence of the specified character sequence to this74* {@code Appendable}.75*76* <p> An invocation of this method of the form {@code out.append(csq, start, end)}77* when {@code csq} is not {@code null}, behaves in78* exactly the same way as the invocation79*80* <pre>81* out.append(csq.subSequence(start, end)) </pre>82*83* @param csq84* The character sequence from which a subsequence will be85* appended. If {@code csq} is {@code null}, then characters86* will be appended as if {@code csq} contained the four87* characters {@code "null"}.88*89* @param start90* The index of the first character in the subsequence91*92* @param end93* The index of the character following the last character in the94* subsequence95*96* @return A reference to this {@code Appendable}97*98* @throws IndexOutOfBoundsException99* If {@code start} or {@code end} are negative, {@code start}100* is greater than {@code end}, or {@code end} is greater than101* {@code csq.length()}102*103* @throws IOException104* If an I/O error occurs105*/106Appendable append(CharSequence csq, int start, int end) throws IOException;107108/**109* Appends the specified character to this {@code Appendable}.110*111* @param c112* The character to append113*114* @return A reference to this {@code Appendable}115*116* @throws IOException117* If an I/O error occurs118*/119Appendable append(char c) throws IOException;120}121122123