public abstract class InputStream extends AutoCloseable
read()
method needs to be overridden. Overriding some of the non-abstract methods is also often advised, since it
might result in higher efficiency.OutputStream
Constructor and Description |
---|
InputStream() |
Modifier and Type | Method and Description |
---|---|
abstract void |
close()
Closes this stream.
|
void |
copyTo(OutputStream outputStream)
Write the remaining contents of this stream to the specified output stream, closing this input stream when done.
|
ByteArrayRange |
copyToByteArray()
Write the remaining contents of this stream to a byte array, closing this input stream when done.
|
protected void |
finalize() |
abstract int |
read()
Reads a single byte from this stream and returns it as an integer in the range from 0 to 255.
|
int |
read(byte[] buffer)
Reads bytes from this stream and stores them in the byte array
b . |
abstract int |
read(byte[] buffer,
int offset,
int length)
Reads at most
length bytes from this stream and stores them in the byte array b starting at
offset . |
int |
readFully(byte[] buffer)
This method is the same as read except that it's guaranteed to read as much as possible, blocking until it's read
length bytes or the end of stream is reached.
|
int |
readFully(byte[] buffer,
int offset,
int length)
This method is the same as read except that it's guaranteed to read as much as possible, blocking until it's read
length bytes or the end of stream is reached.
|
public abstract void close()
close
in interface java.lang.AutoCloseable
close
in class AutoCloseable
IOException
- if an error occurs while closing this streamprotected void finalize()
finalize
in class java.lang.Object
public abstract int read()
IOException
- if an error occurs while readingpublic int read(byte[] buffer)
b
.buffer
- the byte array in which to store the bytes readIOException
- if an error occurs while readingpublic int readFully(byte[] buffer)
buffer
- the byte array in which to store the bytes readIOException
- if an error occurs while readingpublic abstract int read(byte[] buffer, int offset, int length)
length
bytes from this stream and stores them in the byte array b
starting at
offset
.buffer
- the byte array in which to store the bytes readoffset
- the initial position in buffer
to store the bytes read from this streamlength
- the maximum number of bytes to store in b
IOException
- if an error occurs while readingpublic int readFully(byte[] buffer, int offset, int length)
buffer
- the byte array in which to store the bytes readoffset
- the initial position in buffer
to store the bytes read from this streamlength
- the maximum number of bytes to store in b
public void copyTo(OutputStream outputStream)
outputStream
- output stream to copy topublic ByteArrayRange copyToByteArray()