1. /*
  2. * @(#)FilterWriter.java 1.15 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.io;
  8. /**
  9. * Abstract class for writing filtered character streams.
  10. * The abstract class <code>FilterWriter</code> itself
  11. * provides default methods that pass all requests to the
  12. * contained stream. Subclasses of <code>FilterWriter</code>
  13. * should override some of these methods and may also
  14. * provide additional methods and fields.
  15. *
  16. * @version 1.15, 03/01/23
  17. * @author Mark Reinhold
  18. * @since JDK1.1
  19. */
  20. public abstract class FilterWriter extends Writer {
  21. /**
  22. * The underlying character-output stream.
  23. */
  24. protected Writer out;
  25. /**
  26. * Create a new filtered writer.
  27. *
  28. * @param out a Writer object to provide the underlying stream.
  29. * @throws NullPointerException if <code>out</code> is <code>null</code>
  30. */
  31. protected FilterWriter(Writer out) {
  32. super(out);
  33. this.out = out;
  34. }
  35. /**
  36. * Write a single character.
  37. *
  38. * @exception IOException If an I/O error occurs
  39. */
  40. public void write(int c) throws IOException {
  41. out.write(c);
  42. }
  43. /**
  44. * Write a portion of an array of characters.
  45. *
  46. * @param cbuf Buffer of characters to be written
  47. * @param off Offset from which to start reading characters
  48. * @param len Number of characters to be written
  49. *
  50. * @exception IOException If an I/O error occurs
  51. */
  52. public void write(char cbuf[], int off, int len) throws IOException {
  53. out.write(cbuf, off, len);
  54. }
  55. /**
  56. * Write a portion of a string.
  57. *
  58. * @param str String to be written
  59. * @param off Offset from which to start reading characters
  60. * @param len Number of characters to be written
  61. *
  62. * @exception IOException If an I/O error occurs
  63. */
  64. public void write(String str, int off, int len) throws IOException {
  65. out.write(str, off, len);
  66. }
  67. /**
  68. * Flush the stream.
  69. *
  70. * @exception IOException If an I/O error occurs
  71. */
  72. public void flush() throws IOException {
  73. out.flush();
  74. }
  75. /**
  76. * Close the stream.
  77. *
  78. * @exception IOException If an I/O error occurs
  79. */
  80. public void close() throws IOException {
  81. out.close();
  82. }
  83. }