001/* Appendable.java -- Something to which characters can be appended
002   Copyright (C) 2004 Free Software Foundation
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038package java.lang;
039
040import java.io.IOException;
041
042/**
043 * <p>
044 * An <code>Appendable</code> object is one to which a sequence of Unicode
045 * characters can be added.  The appended characters must be valid Unicode
046 * characters, and may include supplementary characters, composed of multiple
047 * 16-bit <code>char</code> values.
048 * </p>
049 * <p>
050 * The behaviour of the <code>Appendable</code> object is heavily dependent
051 * on the particular implementation being used.  Some implementations may be
052 * thread-safe, while others may not.  Likewise, some implementing classes
053 * may produce errors which aren't propogated to the invoking class, due
054 * to differences in the error handling used.
055 * </p>
056 * <p>
057 * <strong>Note</strong>: implementation of this interface is required for
058 * any class that wishes to receive data from a <code>Formatter</code>
059 * instance.
060 * </p>
061 *
062 * @author Tom Tromey (tromey@redhat.com)
063 * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
064 * @since 1.5
065 */
066public interface Appendable
067{
068
069  /**
070   * Appends the Unicode character, c, to this <code>Appendable</code>
071   * object.
072   *
073   * @param c the character to append.
074   * @return a reference to this object.
075   * @throws IOException if an I/O error occurs.
076   */
077  Appendable append(char c)
078    throws IOException;
079
080  /**
081   * Appends the specified sequence of Unicode characters to this
082   * <code>Appendable</code> object.  The entire sequence may not
083   * be appended, if constrained by the underlying implementation.
084   * For example, a buffer may reach its size limit before the entire
085   * sequence is appended.
086   *
087   * @param seq the character sequence to append.  If seq is null,
088   *        then the string "null" (the string representation of null)
089   *        is appended.
090   * @return a reference to this object.
091   * @throws IOException if an I/O error occurs.
092   */
093  Appendable append(CharSequence seq)
094    throws IOException;
095
096  /**
097   * Appends the specified subsequence of Unicode characters to this
098   * <code>Appendable</code> object, starting and ending at the specified
099   * positions within the sequence.  The entire sequence may not
100   * be appended, if constrained by the underlying implementation.
101   * For example, a buffer may reach its size limit before the entire
102   * sequence is appended.  The behaviour of this method matches the
103   * behaviour of <code>append(seq.subSequence(start,end))</code> when
104   * the sequence is not null.
105   *
106   * @param seq the character sequence to append.  If seq is null,
107   *        then the string "null" (the string representation of null)
108   *        is appended.
109   * @param start the index of the first Unicode character to use from
110   *        the sequence.
111   * @param end the index of the last Unicode character to use from the
112   *        sequence.
113   * @return a reference to this object.
114   * @throws IOException if an I/O error occurs.
115   * @throws IndexOutOfBoundsException if either of the indices are negative,
116   *         the start index occurs after the end index, or the end index is
117   *         beyond the end of the sequence.
118   */
119  Appendable append(CharSequence seq, int start, int end)
120    throws IOException;
121
122}