1. /*
  2. * @(#)Appendable.java 1.3 04/07/16
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.lang;
  8. import java.io.IOException;
  9. /**
  10. * An object to which <tt>char</tt> sequences and values can be appended. The
  11. * <tt>Appendable</tt> interface must be implemented by any class whose
  12. * instances are intended to receive formatted output from a {@link
  13. * java.util.Formatter}.
  14. *
  15. * <p> The characters to be appended should be valid Unicode characters as
  16. * described in <a href="Character.html#unicode">Unicode Character
  17. * Representation</a>. Note that supplementary characters may be composed of
  18. * multiple 16-bit <tt>char</tt> values.
  19. *
  20. * <p> Appendables are not necessarily safe for multithreaded access. Thread
  21. * safety is the responsibility of classes that extend and implement this
  22. * interface.
  23. *
  24. * <p> Since this interface may be implemented by existing classes
  25. * with different styles of error handling there is no guarantee that
  26. * errors will be propagated to the invoker.
  27. *
  28. * @version 1.3, 07/16/04
  29. * @since 1.5
  30. */
  31. public interface Appendable {
  32. /**
  33. * Appends the specified character sequence to this <tt>Appendable</tt>.
  34. *
  35. * <p> Depending on which class implements the character sequence
  36. * <tt>csq</tt>, the entire sequence may not be appended. For
  37. * instance, if <tt>csq</tt> is a {@link java.nio.CharBuffer} then
  38. * the subsequence to append is defined by the buffer's position and limit.
  39. *
  40. * @param csq
  41. * The character sequence to append. If <tt>csq</tt> is
  42. * <tt>null</tt>, then the four characters <tt>"null"</tt> are
  43. * appended to this Appendable.
  44. *
  45. * @return A reference to this <tt>Appendable</tt>
  46. *
  47. * @throws IOException
  48. * If an I/O error occurs
  49. */
  50. Appendable append(CharSequence csq) throws IOException;
  51. /**
  52. * Appends a subsequence of the specified character sequence to this
  53. * <tt>Appendable</tt>.
  54. *
  55. * <p> An invocation of this method of the form <tt>out.append(csq, start,
  56. * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
  57. * exactly the same way as the invocation
  58. *
  59. * <pre>
  60. * out.append(csq.subSequence(start, end)) </pre>
  61. *
  62. * @param csq
  63. * The character sequence from which a subsequence will be
  64. * appended. If <tt>csq</tt> is <tt>null</tt>, then characters
  65. * will be appended as if <tt>csq</tt> contained the four
  66. * characters <tt>"null"</tt>.
  67. *
  68. * @param start
  69. * The index of the first character in the subsequence
  70. *
  71. * @param end
  72. * The index of the character following the last character in the
  73. * subsequence
  74. *
  75. * @return A reference to this <tt>Appendable</tt>
  76. *
  77. * @throws IndexOutOfBoundsException
  78. * If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
  79. * is greater than <tt>end</tt>, or <tt>end</tt> is greater than
  80. * <tt>csq.length()</tt>
  81. *
  82. * @throws IOException
  83. * If an I/O error occurs
  84. */
  85. Appendable append(CharSequence csq, int start, int end) throws IOException;
  86. /**
  87. * Appends the specified character to this <tt>Appendable</tt>.
  88. *
  89. * @param c
  90. * The character to append
  91. *
  92. * @return A reference to this <tt>Appendable</tt>
  93. *
  94. * @throws IOException
  95. * If an I/O error occurs
  96. */
  97. Appendable append(char c) throws IOException;
  98. }