1. /*
  2. * @(#)OutputStream.java 1.23 00/02/02
  3. *
  4. * Copyright 1994-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.io;
  11. /**
  12. * This abstract class is the superclass of all classes representing
  13. * an output stream of bytes. An output stream accepts output bytes
  14. * and sends them to some sink.
  15. * <p>
  16. * Applications that need to define a subclass of
  17. * <code>OutputStream</code> must always provide at least a method
  18. * that writes one byte of output.
  19. *
  20. * @author Arthur van Hoff
  21. * @version 1.23, 02/02/00
  22. * @see java.io.BufferedOutputStream
  23. * @see java.io.ByteArrayOutputStream
  24. * @see java.io.DataOutputStream
  25. * @see java.io.FilterOutputStream
  26. * @see java.io.InputStream
  27. * @see java.io.OutputStream#write(int)
  28. * @since JDK1.0
  29. */
  30. public abstract class OutputStream {
  31. /**
  32. * Writes the specified byte to this output stream. The general
  33. * contract for <code>write</code> is that one byte is written
  34. * to the output stream. The byte to be written is the eight
  35. * low-order bits of the argument <code>b</code>. The 24
  36. * high-order bits of <code>b</code> are ignored.
  37. * <p>
  38. * Subclasses of <code>OutputStream</code> must provide an
  39. * implementation for this method.
  40. *
  41. * @param b the <code>byte</code>.
  42. * @exception IOException if an I/O error occurs. In particular,
  43. * an <code>IOException</code> may be thrown if the
  44. * output stream has been closed.
  45. */
  46. public abstract void write(int b) throws IOException;
  47. /**
  48. * Writes <code>b.length</code> bytes from the specified byte array
  49. * to this output stream. The general contract for <code>write(b)</code>
  50. * is that it should have exactly the same effect as the call
  51. * <code>write(b, 0, b.length)</code>.
  52. *
  53. * @param b the data.
  54. * @exception IOException if an I/O error occurs.
  55. * @see java.io.OutputStream#write(byte[], int, int)
  56. */
  57. public void write(byte b[]) throws IOException {
  58. write(b, 0, b.length);
  59. }
  60. /**
  61. * Writes <code>len</code> bytes from the specified byte array
  62. * starting at offset <code>off</code> to this output stream.
  63. * The general contract for <code>write(b, off, len)</code> is that
  64. * some of the bytes in the array <code>b</code> are written to the
  65. * output stream in order; element <code>b[off]</code> is the first
  66. * byte written and <code>b[off+len-1]</code> is the last byte written
  67. * by this operation.
  68. * <p>
  69. * The <code>write</code> method of <code>OutputStream</code> calls
  70. * the write method of one argument on each of the bytes to be
  71. * written out. Subclasses are encouraged to override this method and
  72. * provide a more efficient implementation.
  73. * <p>
  74. * If <code>b</code> is <code>null</code>, a
  75. * <code>NullPointerException</code> is thrown.
  76. * <p>
  77. * If <code>off</code> is negative, or <code>len</code> is negative, or
  78. * <code>off+len</code> is greater than the length of the array
  79. * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
  80. *
  81. * @param b the data.
  82. * @param off the start offset in the data.
  83. * @param len the number of bytes to write.
  84. * @exception IOException if an I/O error occurs. In particular,
  85. * an <code>IOException</code> is thrown if the output
  86. * stream is closed.
  87. */
  88. public void write(byte b[], int off, int len) throws IOException {
  89. if (b == null) {
  90. throw new NullPointerException();
  91. } else if ((off < 0) || (off > b.length) || (len < 0) ||
  92. ((off + len) > b.length) || ((off + len) < 0)) {
  93. throw new IndexOutOfBoundsException();
  94. } else if (len == 0) {
  95. return;
  96. }
  97. for (int i = 0 ; i < len ; i++) {
  98. write(b[off + i]);
  99. }
  100. }
  101. /**
  102. * Flushes this output stream and forces any buffered output bytes
  103. * to be written out. The general contract of <code>flush</code> is
  104. * that calling it is an indication that, if any bytes previously
  105. * written have been buffered by the implementation of the output
  106. * stream, such bytes should immediately be written to their
  107. * intended destination.
  108. * <p>
  109. * The <code>flush</code> method of <code>OutputStream</code> does nothing.
  110. *
  111. * @exception IOException if an I/O error occurs.
  112. */
  113. public void flush() throws IOException {
  114. }
  115. /**
  116. * Closes this output stream and releases any system resources
  117. * associated with this stream. The general contract of <code>close</code>
  118. * is that it closes the output stream. A closed stream cannot perform
  119. * output operations and cannot be reopened.
  120. * <p>
  121. * The <code>close</code> method of <code>OutputStream</code> does nothing.
  122. *
  123. * @exception IOException if an I/O error occurs.
  124. */
  125. public void close() throws IOException {
  126. }
  127. }