public class Io extends Object
| Modifier and Type | Method and Description |
|---|---|
static void |
close(Closeable closeable)
Closes the given
Closeable, ignoring any possible I/O exception. |
static int |
copyBytes(InputStream source,
OutputStream destination)
Copies all bytes from the given source to the given destination.
|
static void |
copyBytes(InputStream source,
OutputStream destination,
int byteCount)
Copies the given number of bytes from the given source to the given destination.
|
static int |
discardBytes(InputStream source)
Discards all bytes from the given source.
|
static void |
discardBytes(InputStream source,
int byteCount)
Discards the given number of bytes from the given source.
|
static int |
getBufferSize()
Returns the size of the buffer (in bytes) used in I/O operations.
|
static byte |
readByte(InputStream source)
Reads a
byte from the given source. |
static byte[] |
readBytes(InputStream source)
Reads all bytes from the given source.
|
static byte[] |
readBytes(InputStream source,
int byteCount)
Reads the given number of bytes from the given source.
|
static char |
readChar(InputStream source)
Reads a
char from the given source using the default (big-endian) byte order. |
static char |
readChar(InputStream source,
ByteOrder byteOrder)
Reads a
char from the given source using the given byte order. |
static double |
readDouble(InputStream source)
Reads a
double from the given source using the default (big-endian) byte order. |
static double |
readDouble(InputStream source,
ByteOrder byteOrder)
Reads a
double from the given source using the given byte order. |
static float |
readFloat(InputStream source)
Reads a
float from the given source using the default (big-endian) byte order. |
static float |
readFloat(InputStream source,
ByteOrder byteOrder)
Reads a
float from the given source using the given byte order. |
static int |
readInt(InputStream source)
Reads an
int from the given source using the default (big-endian) byte order. |
static int |
readInt(InputStream source,
ByteOrder byteOrder)
Reads an
int from the given source using the given byte order. |
static long |
readLong(InputStream source)
Reads a
long from the given source using the default (big-endian) byte order. |
static long |
readLong(InputStream source,
ByteOrder byteOrder)
Reads a
long from the given source using the given byte order. |
static short |
readShort(InputStream source)
Reads a
short from the given source using the default (big-endian) byte order. |
static short |
readShort(InputStream source,
ByteOrder byteOrder)
Reads a
short from the given source using the given byte order. |
static String |
readString(InputStream source)
Reads all bytes from the given source and converts them to a string using UTF-8.
|
static String |
readString(InputStream source,
Charset charset)
Reads all bytes from the given source and converts them to a string using the given charset.
|
static String |
readString(InputStream source,
int byteCount)
Reads the given number of bytes from the given source and converts them to a string using UTF-8.
|
static String |
readString(InputStream source,
int byteCount,
Charset charset)
Reads the given number of bytes from the given source and converts them to a string using the given charset.
|
static int |
readUnsignedByte(InputStream source)
Reads an unsigned
byte from the given source. |
static UUID |
readUuid(InputStream source)
Reads a
UUID} from the given source using the default (big-endian) byte order. |
static UUID |
readUuid(InputStream source,
ByteOrder byteOrder)
Reads a
UUID} from the given source using the given byte order. |
static void |
setBufferSize(int bufferSize)
Sets the size of the buffer (in bytes) used in I/O operations.
|
static void |
writeByte(OutputStream destination,
byte value)
Writes a
byte to the given destination. |
static void |
writeBytes(OutputStream destination,
byte[] bytes)
Writes the given bytes to the given destination.
|
static void |
writeChar(OutputStream destination,
char value)
Writes a
char to the given destination using the default (big-endian) byte order. |
static void |
writeChar(OutputStream destination,
char value,
ByteOrder byteOrder)
Writes a
char to the given destination using the given byte order. |
static void |
writeDouble(OutputStream destination,
double value)
Writes a
double to the given destination using the default (big-endian) byte order. |
static void |
writeDouble(OutputStream destination,
double value,
ByteOrder byteOrder)
Writes a
double to the given destination using the given byte order. |
static void |
writeFloat(OutputStream destination,
float value)
Writes a
float to the given destination using the default (big-endian) byte order. |
static void |
writeFloat(OutputStream destination,
float value,
ByteOrder byteOrder)
Writes a
float to the given destination using the given byte order. |
static void |
writeInt(OutputStream destination,
int value)
Writes an
int to the given destination using the default (big-endian) byte order. |
static void |
writeInt(OutputStream destination,
int value,
ByteOrder byteOrder)
Writes an
int to the given destination using the given byte order. |
static void |
writeLong(OutputStream destination,
long value)
Writes a
long to the given destination using the default (big-endian) byte order. |
static void |
writeLong(OutputStream destination,
long value,
ByteOrder byteOrder)
Writes a
long to the given destination using the given byte order. |
static void |
writeShort(OutputStream destination,
short value)
Writes a
short to the given destination using the default (big-endian) byte order. |
static void |
writeShort(OutputStream destination,
short value,
ByteOrder byteOrder)
Writes a
short to the given destination using the given byte order. |
static void |
writeString(OutputStream destination,
String string)
Writes the given string to the given destination using UTF-8.
|
static void |
writeString(OutputStream destination,
String string,
Charset charset)
Writes the given string to the given destination using the given charset.
|
static void |
writeUnsignedByte(OutputStream destination,
int value)
Writes an unsigned
byte to the given destination. |
static void |
writeUuid(OutputStream destination,
UUID uuid)
Writes a
UUID to the given destination using the default (big-endian) byte order. |
static void |
writeUuid(OutputStream destination,
UUID uuid,
ByteOrder byteOrder)
Writes a
UUID to the given destination using the given byte order. |
public static void close(Closeable closeable)
Closeable, ignoring any possible I/O exception.public static int copyBytes(InputStream source, OutputStream destination) throws IOException
IllegalArgumentException - if source is nullIllegalArgumentException - if destination is nullIOException - if an I/O error occurspublic static void copyBytes(InputStream source, OutputStream destination, int byteCount) throws IOException
IllegalArgumentException - if source is nullIllegalArgumentException - if destination is nullIOException - if an I/O error occurspublic static int discardBytes(InputStream source) throws IOException
IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static void discardBytes(InputStream source, int byteCount) throws IOException
IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static int getBufferSize()
public static byte readByte(InputStream source) throws IOException
byte from the given source.IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static byte[] readBytes(InputStream source) throws IOException
IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static byte[] readBytes(InputStream source, int byteCount) throws IOException
IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static char readChar(InputStream source) throws IOException
char from the given source using the default (big-endian) byte order.IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static char readChar(InputStream source, ByteOrder byteOrder) throws IOException
char from the given source using the given byte order.IllegalArgumentException - if source is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static double readDouble(InputStream source) throws IOException
double from the given source using the default (big-endian) byte order.IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static double readDouble(InputStream source, ByteOrder byteOrder) throws IOException
double from the given source using the given byte order.IllegalArgumentException - if source is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static float readFloat(InputStream source) throws IOException
float from the given source using the default (big-endian) byte order.IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static float readFloat(InputStream source, ByteOrder byteOrder) throws IOException
float from the given source using the given byte order.IllegalArgumentException - if source is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static int readInt(InputStream source) throws IOException
int from the given source using the default (big-endian) byte order.IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static int readInt(InputStream source, ByteOrder byteOrder) throws IOException
int from the given source using the given byte order.IllegalArgumentException - if source is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static long readLong(InputStream source) throws IOException
long from the given source using the default (big-endian) byte order.IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static long readLong(InputStream source, ByteOrder byteOrder) throws IOException
long from the given source using the given byte order.IllegalArgumentException - if source is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static short readShort(InputStream source) throws IOException
short from the given source using the default (big-endian) byte order.IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static short readShort(InputStream source, ByteOrder byteOrder) throws IOException
short from the given source using the given byte order.IllegalArgumentException - if source is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static String readString(InputStream source) throws IOException
IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static String readString(InputStream source, Charset charset) throws IOException
IllegalArgumentException - if source is nullIllegalArgumentException - if charset is nullIOException - if an I/O error occurspublic static String readString(InputStream source, int byteCount) throws IOException
IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static String readString(InputStream source, int byteCount, Charset charset) throws IOException
IllegalArgumentException - if source is nullIllegalArgumentException - if charset is nullIOException - if an I/O error occurspublic static int readUnsignedByte(InputStream source) throws IOException
byte from the given source.IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static UUID readUuid(InputStream source) throws IOException
UUID} from the given source using the default (big-endian) byte order.IllegalArgumentException - if source is nullIOException - if an I/O error occurspublic static UUID readUuid(InputStream source, ByteOrder byteOrder) throws IOException
UUID} from the given source using the given byte order.IllegalArgumentException - if source is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static void setBufferSize(int bufferSize)
IllegalArgumentException - if bufferSize is not positivepublic static void writeByte(OutputStream destination, byte value) throws IOException
byte to the given destination.IllegalArgumentException - if destination is nullIOException - if an I/O error occurspublic static void writeBytes(OutputStream destination, byte[] bytes) throws IOException
IllegalArgumentException - if destination is nullIllegalArgumentException - if bytes are nullIOException - if an I/O error occurspublic static void writeChar(OutputStream destination, char value) throws IOException
char to the given destination using the default (big-endian) byte order.IllegalArgumentException - if destination is nullIOException - if an I/O error occurspublic static void writeChar(OutputStream destination, char value, ByteOrder byteOrder) throws IOException
char to the given destination using the given byte order.IllegalArgumentException - if destination is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static void writeDouble(OutputStream destination, double value) throws IOException
double to the given destination using the default (big-endian) byte order.IllegalArgumentException - if destination is nullIOException - if an I/O error occurspublic static void writeDouble(OutputStream destination, double value, ByteOrder byteOrder) throws IOException
double to the given destination using the given byte order.IllegalArgumentException - if destination is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static void writeFloat(OutputStream destination, float value) throws IOException
float to the given destination using the default (big-endian) byte order.IllegalArgumentException - if destination is nullIOException - if an I/O error occurspublic static void writeFloat(OutputStream destination, float value, ByteOrder byteOrder) throws IOException
float to the given destination using the given byte order.IllegalArgumentException - if destination is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static void writeInt(OutputStream destination, int value) throws IOException
int to the given destination using the default (big-endian) byte order.IllegalArgumentException - if destination is nullIOException - if an I/O error occurspublic static void writeInt(OutputStream destination, int value, ByteOrder byteOrder) throws IOException
int to the given destination using the given byte order.IllegalArgumentException - if destination is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static void writeLong(OutputStream destination, long value) throws IOException
long to the given destination using the default (big-endian) byte order.IllegalArgumentException - if destination is nullIOException - if an I/O error occurspublic static void writeLong(OutputStream destination, long value, ByteOrder byteOrder) throws IOException
long to the given destination using the given byte order.IllegalArgumentException - if destination is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static void writeShort(OutputStream destination, short value) throws IOException
short to the given destination using the default (big-endian) byte order.IllegalArgumentException - if destination is nullIOException - if an I/O error occurspublic static void writeShort(OutputStream destination, short value, ByteOrder byteOrder) throws IOException
short to the given destination using the given byte order.IllegalArgumentException - if destination is nullIllegalArgumentException - if byteOrder is nullIOException - if an I/O error occurspublic static void writeString(OutputStream destination, String string) throws IOException
IllegalArgumentException - if destination is nullIllegalArgumentException - if string is nullIOException - if an I/O error occurspublic static void writeString(OutputStream destination, String string, Charset charset) throws IOException
IllegalArgumentException - if destination is nullIllegalArgumentException - if string is nullIllegalArgumentException - if charset is nullIOException - if an I/O error occurspublic static void writeUnsignedByte(OutputStream destination, int value) throws IOException
byte to the given destination.IllegalArgumentException - if destination is nullIOException - if an I/O error occurspublic static void writeUuid(OutputStream destination, UUID uuid) throws IOException
UUID to the given destination using the default (big-endian) byte order.IllegalArgumentException - if destination is nullIllegalArgumentException - if uuid is nullIOException - if an I/O error occurspublic static void writeUuid(OutputStream destination, UUID uuid, ByteOrder byteOrder) throws IOException
UUID to the given destination using the given byte order.IllegalArgumentException - if destination is nullIllegalArgumentException - if uuid is nullIOException - if an I/O error occurs