본문 바로가기
IO

2. InputStream&OutputStream&Socket

by 이석준석이 2021. 3. 19.

1. InputStream

 

  • read(byte b[]) 혹은
  • read(byte b[], int off, int len) 메소드는
  • 결국 추상메소드인 read() 를 호출한다.

read() 메소드는 

  • 다음 바이트를 읽어들이며,
  • 0~255 사이의 int 값을 리턴한다.
  • 더 읽을 값이 없다면 -1을 리턴하도록 구현하면 된다.
public abstract class InputStream implements Closeable {

    private static final int MAX_SKIP_BUFFER_SIZE = 2048;

    public abstract int read() throws IOException;

    public int read(byte b[]) throws IOException {
        return read(b, 0, b.length);
    }

    public int read(byte b[], int off, int len) throws IOException {
        ...
    }

    public long skip(long n) throws IOException {
		...
    }

    public int available() throws IOException {
        return 0;
    }

    public void close() throws IOException {}

    public synchronized void mark(int readlimit) {}

    public synchronized void reset() throws IOException {
        throw new IOException("mark/reset not supported");
    }

    public boolean markSupported() {
        return false;
    }

}

2. OutputStream

 

public abstract class OutputStream implements Closeable, Flushable {

    public abstract void write(int b) throws IOException;

    public void write(byte b[]) throws IOException {
		...
    }

    public void write(byte b[], int off, int len) throws IOException {
		...
    }

    public void flush() throws IOException {
    }

    public void close() throws IOException {
    }

}

 

'IO' 카테고리의 다른 글

1. Closeable & Flushable  (0) 2021.03.18