InputStream和OutputStream

InputStream:

package java.io;

public abstract class InputStream implements Closeable {

    // SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
    private static final int SKIP_BUFFER_SIZE = 2048;
    // skipBuffer is initialized in skip(long), if needed.
    private static byte[] skipBuffer;

    /**
     * Reads the next byte of data from the input stream. The value byte is
     * returned as an int in the range 0 to 255. If no byte is available because the end of the stream
     * has been reached, the value -1 is returned. 
     */
    public abstract int read() throws IOException;

    /**
     * Reads some number of bytes from the input stream and stores them into
     * the buffer array b. The number of bytes actually read is returned as an integer.  This method blocks until input data is
     * available, end of file is detected, or an exception is thrown.
     * @return     the total number of bytes read into the buffer, or -1 is there is no more data because the end of
     *             the stream has been reached.*/
    public int read(byte b[]) throws IOException {
	return read(b, 0, b.length);
    }

    /**
     * Reads up to len bytes of data from the input stream into an array of bytes.  An attempt is made to read as many as
     * len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.
     * @return     the total number of bytes read into the buffer, or -1 if there is no more data because the end of
     *             the stream has been reached.*/
    public int read(byte b[], int off, int len) throws IOException {
      //....
   }

    /** Skips over and discards n bytes of data from this input stream. The skip method may, for a variety of reasons, end
     * up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file
     * before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned.  If n is
     * negative, no bytes are skipped.*/
    public long skip(long n) throws IOException {
         //...
    }

    /** Returns an estimate of the number of bytes that can be read (or  skipped over) from this input stream without blocking by the next
     * invocation of a method for this input stream. The next invocation might be the same thread or another thread.  A single read or skip of this
     * many bytes will not block, but may read or skip fewer bytes.*/
    public int available() throws IOException {
	return 0;
    }

    /**
     * Closes this input stream and releases any system resources associated with the stream.
     */
    public void close() throws IOException {}

    /** Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked
     * position so that subsequent reads re-read the same bytes.   */
    public synchronized void mark(int readlimit) {}

    /** Repositions this stream to the position at the time the mark method was last called on this input stream. */
    public synchronized void reset() throws IOException {
	throw new IOException("mark/reset not supported");
    }

    /** Tests if this input stream supports the mark and reset methods. Whether or not mark and reset are supported is an invariant property of a
     * particular input stream instance. The markSupported method of InputStream returns false     */
    public boolean markSupported() {
	return false;
    }

}

OutputStream:

package java.io;

public abstract class OutputStream implements Closeable, Flushable {
    /** Writes the specified byte to this output stream. The general  contract for write is that one byte is written 
     * to the output stream. The byte to be written is the eight  low-order bits of the argument b. The 24 
     * high-order bits of b are ignored.*/
    public abstract void write(int b) throws IOException;

    /** Writes b.length bytes from the specified byte array  to this output stream. The general contract for write(b) 
     * is that it should have exactly the same effect as the call  write(b, 0, b.length).*/
    public void write(byte b[]) throws IOException {
   	write(b, 0, b.length);
    }

    /**
     * Writes len bytes from the specified byte array  starting at offset off to this output stream. 
     * The general contract for write(b, off, len) is that  some of the bytes in the array b are written to the 
     * output stream in order; element b[off] is the first  byte written and b[off+len-1] is the last byte written  by this operation.*/
    public void write(byte b[], int off, int len) throws IOException {
	//...
    }

    /**
     * Flushes this output stream and forces any buffered output bytes  to be written out. The general contract of flush is 
     * that calling it is an indication that, if any bytes previously  written have been buffered by the implementation of the output 
     * stream, such bytes should immediately be written to their  intended destination.*/
    public void flush() throws IOException {
    }

    /**
     * Closes this output stream and releases any system resources  associated with this stream. The general contract of close 
     * is that it closes the output stream. A closed stream cannot perform  output operations and cannot be reopened.*/
    public void close() throws IOException {
    }

}
额外篇:InputStream、OutputStream的UML和使用例子,点击打开链接
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值