public final class Streams extends Object
| Modifier and Type | Method and Description |
|---|---|
static int |
copy(InputStream in,
OutputStream out)
Copies all of the bytes from
in to out. |
static String |
readAsciiLine(InputStream in)
Returns the ASCII characters up to but not including the next "\r\n", or
"\n".
|
static byte[] |
readFully(InputStream in)
Returns a byte[] containing the remainder of 'in', closing it when done.
|
static void |
readFully(InputStream in,
byte[] dst)
Fills 'dst' with bytes from 'in', throwing EOFException if insufficient bytes are available.
|
static void |
readFully(InputStream in,
byte[] dst,
int offset,
int byteCount)
Reads exactly 'byteCount' bytes from 'in' (into 'dst' at offset 'offset'), and throws
EOFException if insufficient bytes are available.
|
static String |
readFully(Reader reader)
Returns the remainder of 'reader' as a string, closing it when done.
|
static byte[] |
readFullyNoClose(InputStream in)
Returns a byte[] containing the remainder of 'in'.
|
static int |
readSingleByte(InputStream in)
Implements InputStream.read(int) in terms of InputStream.read(byte[], int, int).
|
static void |
skipAll(InputStream in) |
static long |
skipByReading(InputStream in,
long byteCount)
Skip at most
byteCount bytes from in by calling read
repeatedly until either the stream is exhausted or we read fewer bytes than
we ask for. |
static void |
writeSingleByte(OutputStream out,
int b)
Implements OutputStream.write(int) in terms of OutputStream.write(byte[], int, int).
|
public static int readSingleByte(InputStream in) throws IOException
IOExceptionpublic static void writeSingleByte(OutputStream out, int b) throws IOException
IOExceptionpublic static void readFully(InputStream in, byte[] dst) throws IOException
IOExceptionpublic static void readFully(InputStream in, byte[] dst, int offset, int byteCount) throws IOException
DataInputStream.readFully(byte[], int, int).IOExceptionpublic static byte[] readFully(InputStream in) throws IOException
IOExceptionpublic static byte[] readFullyNoClose(InputStream in) throws IOException
IOExceptionpublic static String readFully(Reader reader) throws IOException
IOExceptionpublic static void skipAll(InputStream in) throws IOException
IOExceptionpublic static long skipByReading(InputStream in, long byteCount) throws IOException
byteCount bytes from in by calling read
repeatedly until either the stream is exhausted or we read fewer bytes than
we ask for.
This method reuses the skip buffer but is careful to never use it at the same time that another stream is using it. Otherwise streams that use the caller's buffer for consistency checks like CRC could be clobbered by other threads. A thread-local buffer is also insufficient because some streams may call other streams in their skip() method, also clobbering the buffer.
IOExceptionpublic static int copy(InputStream in, OutputStream out) throws IOException
in to out. Neither stream is closed.
Returns the total number of bytes transferred.IOExceptionpublic static String readAsciiLine(InputStream in) throws IOException
EOFException - if the stream is exhausted before the next newline
character.IOException