public class IOUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
discardInput(java.io.InputStream is)
Read all input from the given stream without using it.
|
static byte[] |
readAllBytes(java.io.InputStream is)
Read all bytes from an input stream.
|
static java.lang.String |
readAllText(java.io.InputStream is)
Read all text from a stream, using the default charset.
|
static java.lang.String |
readAllText(java.io.InputStream is,
java.nio.charset.Charset charset)
Read all text from a stream.
|
static java.lang.String |
readAllTextUtf8(java.io.InputStream is)
Read all text from a stream, using UTF-8 encoding.
|
static void |
readFully(java.io.InputStream is,
byte[] data)
Read a number of bytes.
|
static void |
readFully(java.io.InputStream is,
byte[] data,
int length)
Read a number of bytes.
|
static void |
readFully(java.io.InputStream is,
byte[] data,
int offset,
int length)
Read a number of bytes.
|
public static void readFully(@NotNull java.io.InputStream is, @NotNull byte[] data, int offset, int length) throws java.io.IOException
is
- input stream to read fromdata
- byte array for collecting the input (must provide enough space)offset
- offset into the byte array where byte collection starts (has to be non-negative)length
- number of bytes to read (has to non-negative)java.io.IOException
- on read errorsjava.io.EOFException
- if there are not at least length
bytes in the stream availablepublic static void readFully(@NotNull java.io.InputStream is, @NotNull byte[] data, int length) throws java.io.IOException
0
.is
- input stream to read fromdata
- byte array for collecting the input (must provide enough space)length
- number of bytes to read (has to non-negative)java.io.IOException
- on read errorsjava.io.EOFException
- if there are not at least length
bytes in the stream availablepublic static void readFully(@NotNull java.io.InputStream is, @NotNull byte[] data) throws java.io.IOException
0
and reads until the byte array is filled.is
- input stream to read fromdata
- byte array for collecting the input (must provide enough space)java.io.IOException
- on read errorsjava.io.EOFException
- if there are not at least length
bytes in the stream available@NotNull public static byte[] readAllBytes(@NotNull java.io.InputStream is) throws java.io.IOException
is
- input streamjava.io.IOException
- on read errors@NotNull public static java.lang.String readAllText(@NotNull java.io.InputStream is, @NotNull java.nio.charset.Charset charset) throws java.io.IOException
is
- stream to read fromcharset
- charset to use for byte to text conversionjava.io.IOException
- on read errors@NotNull public static java.lang.String readAllText(@NotNull java.io.InputStream is) throws java.io.IOException
is
- stream to read fromjava.io.IOException
- on read errorsCharset.defaultCharset()
@NotNull public static java.lang.String readAllTextUtf8(@NotNull java.io.InputStream is) throws java.io.IOException
is
- stream to read fromjava.io.IOException
- on read errorsCharset.defaultCharset()
public static void discardInput(@NotNull java.io.InputStream is) throws java.io.IOException
is
- input streamjava.io.IOException
- if reading runs into an exception other than EOFException