|
1 /* |
|
2 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package java.lang; |
|
27 |
|
28 import java.io.IOException; |
|
29 |
|
30 /** |
|
31 * An object to which <tt>char</tt> sequences and values can be appended. The |
|
32 * <tt>Appendable</tt> interface must be implemented by any class whose |
|
33 * instances are intended to receive formatted output from a {@link |
|
34 * java.util.Formatter}. |
|
35 * |
|
36 * <p> The characters to be appended should be valid Unicode characters as |
|
37 * described in <a href="Character.html#unicode">Unicode Character |
|
38 * Representation</a>. Note that supplementary characters may be composed of |
|
39 * multiple 16-bit <tt>char</tt> values. |
|
40 * |
|
41 * <p> Appendables are not necessarily safe for multithreaded access. Thread |
|
42 * safety is the responsibility of classes that extend and implement this |
|
43 * interface. |
|
44 * |
|
45 * <p> Since this interface may be implemented by existing classes |
|
46 * with different styles of error handling there is no guarantee that |
|
47 * errors will be propagated to the invoker. |
|
48 * |
|
49 * @since 1.5 |
|
50 */ |
|
51 public interface Appendable { |
|
52 |
|
53 /** |
|
54 * Appends the specified character sequence to this <tt>Appendable</tt>. |
|
55 * |
|
56 * <p> Depending on which class implements the character sequence |
|
57 * <tt>csq</tt>, the entire sequence may not be appended. For |
|
58 * instance, if <tt>csq</tt> is a {@link java.nio.CharBuffer} then |
|
59 * the subsequence to append is defined by the buffer's position and limit. |
|
60 * |
|
61 * @param csq |
|
62 * The character sequence to append. If <tt>csq</tt> is |
|
63 * <tt>null</tt>, then the four characters <tt>"null"</tt> are |
|
64 * appended to this Appendable. |
|
65 * |
|
66 * @return A reference to this <tt>Appendable</tt> |
|
67 * |
|
68 * @throws IOException |
|
69 * If an I/O error occurs |
|
70 */ |
|
71 Appendable append(CharSequence csq) throws IOException; |
|
72 |
|
73 /** |
|
74 * Appends a subsequence of the specified character sequence to this |
|
75 * <tt>Appendable</tt>. |
|
76 * |
|
77 * <p> An invocation of this method of the form <tt>out.append(csq, start, |
|
78 * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in |
|
79 * exactly the same way as the invocation |
|
80 * |
|
81 * <pre> |
|
82 * out.append(csq.subSequence(start, end)) </pre> |
|
83 * |
|
84 * @param csq |
|
85 * The character sequence from which a subsequence will be |
|
86 * appended. If <tt>csq</tt> is <tt>null</tt>, then characters |
|
87 * will be appended as if <tt>csq</tt> contained the four |
|
88 * characters <tt>"null"</tt>. |
|
89 * |
|
90 * @param start |
|
91 * The index of the first character in the subsequence |
|
92 * |
|
93 * @param end |
|
94 * The index of the character following the last character in the |
|
95 * subsequence |
|
96 * |
|
97 * @return A reference to this <tt>Appendable</tt> |
|
98 * |
|
99 * @throws IndexOutOfBoundsException |
|
100 * If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt> |
|
101 * is greater than <tt>end</tt>, or <tt>end</tt> is greater than |
|
102 * <tt>csq.length()</tt> |
|
103 * |
|
104 * @throws IOException |
|
105 * If an I/O error occurs |
|
106 */ |
|
107 Appendable append(CharSequence csq, int start, int end) throws IOException; |
|
108 |
|
109 /** |
|
110 * Appends the specified character to this <tt>Appendable</tt>. |
|
111 * |
|
112 * @param c |
|
113 * The character to append |
|
114 * |
|
115 * @return A reference to this <tt>Appendable</tt> |
|
116 * |
|
117 * @throws IOException |
|
118 * If an I/O error occurs |
|
119 */ |
|
120 Appendable append(char c) throws IOException; |
|
121 } |