Source Home >> Java Source 1.6.0 >> java.io.OutputStream V 0.09
  • 001/*
  • 002 * @(#)OutputStream.java 1.30 05/11/17
  • 003 *
  • 004 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
  • 005 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  • 006 */
  • 007
  • 008package java.io;
  • 009
  • 010/**
  • 011 * This abstract class is the superclass of all classes representing
  • 012 * an output stream of bytes. An output stream accepts output bytes
  • 013 * and sends them to some sink.
  • 014 * <p>
  • 015 * Applications that need to define a subclass of
  • 016 * <code>OutputStream</code> must always provide at least a method
  • 017 * that writes one byte of output.
  • 018 *
  • 019 * @author Arthur van Hoff
  • 020 * @version 1.30, 11/17/05
  • 021 * @see java.io.BufferedOutputStream
  • 022 * @see java.io.ByteArrayOutputStream
  • 023 * @see java.io.DataOutputStream
  • 024 * @see java.io.FilterOutputStream
  • 025 * @see java.io.InputStream
  • 026 * @see java.io.OutputStream#write(int)
  • 027 * @since JDK1.0
  • 028 */
  • 029public abstract class OutputStream implements Closeable, Flushable {
  • 030 /**
  • 031 * Writes the specified byte to this output stream. The general
  • 032 * contract for <code>write</code> is that one byte is written
  • 033 * to the output stream. The byte to be written is the eight
  • 034 * low-order bits of the argument <code>b</code>. The 24
  • 035 * high-order bits of <code>b</code> are ignored.
  • 036 * <p>
  • 037 * Subclasses of <code>OutputStream</code> must provide an
  • 038 * implementation for this method.
  • 039 *
  • 040 * @param b the <code>byte</code>.
  • 041 * @exception IOException if an I/O error occurs. In particular,
  • 042 * an <code>IOException</code> may be thrown if the
  • 043 * output stream has been closed.
  • 044 */
  • 045 public abstract void write(int b) throws IOException;
  • 046
  • 047 /**
  • 048 * Writes <code>b.length</code> bytes from the specified byte array
  • 049 * to this output stream. The general contract for <code>write(b)</code>
  • 050 * is that it should have exactly the same effect as the call
  • 051 * <code>write(b, 0, b.length)</code>.
  • 052 *
  • 053 * @param b the data.
  • 054 * @exception IOException if an I/O error occurs.
  • 055 * @see java.io.OutputStream#write(byte[], int, int)
  • 056 */
  • 057 public void write(byte b[]) throws IOException {
  • 058 write(b, 0, b.length);
  • 059 }
  • 060
  • 061 /**
  • 062 * Writes <code>len</code> bytes from the specified byte array
  • 063 * starting at offset <code>off</code> to this output stream.
  • 064 * The general contract for <code>write(b, off, len)</code> is that
  • 065 * some of the bytes in the array <code>b</code> are written to the
  • 066 * output stream in order; element <code>b[off]</code> is the first
  • 067 * byte written and <code>b[off+len-1]</code> is the last byte written
  • 068 * by this operation.
  • 069 * <p>
  • 070 * The <code>write</code> method of <code>OutputStream</code> calls
  • 071 * the write method of one argument on each of the bytes to be
  • 072 * written out. Subclasses are encouraged to override this method and
  • 073 * provide a more efficient implementation.
  • 074 * <p>
  • 075 * If <code>b</code> is <code>null</code>, a
  • 076 * <code>NullPointerException</code> is thrown.
  • 077 * <p>
  • 078 * If <code>off</code> is negative, or <code>len</code> is negative, or
  • 079 * <code>off+len</code> is greater than the length of the array
  • 080 * <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
  • 081 *
  • 082 * @param b the data.
  • 083 * @param off the start offset in the data.
  • 084 * @param len the number of bytes to write.
  • 085 * @exception IOException if an I/O error occurs. In particular,
  • 086 * an <code>IOException</code> is thrown if the output
  • 087 * stream is closed.
  • 088 */
  • 089 public void write(byte b[], int off, int len) throws IOException {
  • 090 if (b == null) {
  • 091 throw new NullPointerException();
  • 092 } else if ((off < 0) || (off > b.length) || (len < 0) ||
  • 093 ((off + len) > b.length) || ((off + len) < 0)) {
  • 094 throw new IndexOutOfBoundsException();
  • 095 } else if (len == 0) {
  • 096 return;
  • 097 }
  • 098 for (int i = 0 ; i < len ; i++) {
  • 099 write(b[off + i]);
  • 100 }
  • 101 }
  • 102
  • 103 /**
  • 104 * Flushes this output stream and forces any buffered output bytes
  • 105 * to be written out. The general contract of <code>flush</code> is
  • 106 * that calling it is an indication that, if any bytes previously
  • 107 * written have been buffered by the implementation of the output
  • 108 * stream, such bytes should immediately be written to their
  • 109 * intended destination.
  • 110 * <p>
  • 111 * If the intended destination of this stream is an abstraction provided by
  • 112 * the underlying operating system, for example a file, then flushing the
  • 113 * stream guarantees only that bytes previously written to the stream are
  • 114 * passed to the operating system for writing; it does not guarantee that
  • 115 * they are actually written to a physical device such as a disk drive.
  • 116 * <p>
  • 117 * The <code>flush</code> method of <code>OutputStream</code> does nothing.
  • 118 *
  • 119 * @exception IOException if an I/O error occurs.
  • 120 */
  • 121 public void flush() throws IOException {
  • 122 }
  • 123
  • 124 /**
  • 125 * Closes this output stream and releases any system resources
  • 126 * associated with this stream. The general contract of <code>close</code>
  • 127 * is that it closes the output stream. A closed stream cannot perform
  • 128 * output operations and cannot be reopened.
  • 129 * <p>
  • 130 * The <code>close</code> method of <code>OutputStream</code> does nothing.
  • 131 *
  • 132 * @exception IOException if an I/O error occurs.
  • 133 */
  • 134 public void close() throws IOException {
  • 135 }
  • 136
  • 137}

文件:OutputStream.java
包名:java.io
类名:OutputStream
继承:
接口:[Closeable][Flushable]