|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.jackrabbit.oak.commons.IOUtils
public final class IOUtils
Input/output utility methods.
| Method Summary | |
|---|---|
static void |
closeQuietly(Closeable closeable)
Unconditionally close a Closeable. |
static void |
closeQuietly(Socket sock)
Unconditionally close a Socket. |
static long |
copy(InputStream input,
OutputStream output)
Copy bytes from an InputStream to an
OutputStream. |
static String |
humanReadableByteCount(long bytes)
Returns a human-readable version of the file size, where the input represents a specific number of bytes. |
static int |
nextPowerOf2(int x)
Get the value that is equal or higher than this value, and that is a power of two. |
static byte[] |
readBytes(InputStream in)
Read a byte array. |
static int |
readFully(InputStream in,
byte[] buffer,
int off,
int max)
Try to read the given number of bytes to the buffer. |
static int |
readInt(InputStream in)
Read an integer (4 bytes). |
static long |
readLong(InputStream in)
Read a long (8 bytes). |
static String |
readString(InputStream in)
Read a String. |
static int |
readVarInt(InputStream in)
Read a variable size integer. |
static long |
readVarLong(InputStream in)
Read a variable size long. |
static void |
skipFully(InputStream in,
long skip)
Skip a number of bytes in an input stream. |
static void |
writeBytes(OutputStream out,
byte[] data)
Write a byte array. |
static void |
writeInt(OutputStream out,
int x)
Write an integer (4 bytes). |
static void |
writeLong(OutputStream out,
long x)
Write a long (8 bytes). |
static void |
writeString(OutputStream out,
String s)
Write a String. |
static void |
writeVarInt(OutputStream out,
int x)
Write a variable size integer. |
static void |
writeVarLong(OutputStream out,
long x)
Write a variable size long. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static int readFully(InputStream in,
byte[] buffer,
int off,
int max)
throws IOException
in - the input streambuffer - the output bufferoff - the offset in the buffermax - the number of bytes to read at most
IOException - If an error occurs.
public static void skipFully(InputStream in,
long skip)
throws IOException
in - the input streamskip - the number of bytes to skip
EOFException - if the end of file has been reached before all bytes
could be skipped
IOException - if an IO exception occurred while skipping
public static void writeString(OutputStream out,
String s)
throws IOException
out - the data output streams - the string (maximum length about 2 GB)
IOException - if an IO exception occurred while writing
public static String readString(InputStream in)
throws IOException
in - the data input stream
IOException - if an IO exception occurred while reading
public static void writeBytes(OutputStream out,
byte[] data)
throws IOException
out - the data output streamdata - the byte array
IOException - if an IO exception occurred while writing.
public static byte[] readBytes(InputStream in)
throws IOException
in - the data input stream
IOException - if an IO exception occurred while reading from the stream.
public static void writeVarInt(OutputStream out,
int x)
throws IOException
out - the output streamx - the value
IOException - if an IO exception occurred while writing.
public static int readVarInt(InputStream in)
throws IOException
in - the input stream
IOException - if an IO exception occurred while reading.
public static void writeVarLong(OutputStream out,
long x)
throws IOException
out - the output streamx - the value
IOException - if an IO exception occurred while writing.
public static void writeLong(OutputStream out,
long x)
throws IOException
out - the output streamx - the value
IOException - if an IO exception occurred while writing.
public static long readLong(InputStream in)
throws IOException
in - the input stream
IOException - if an IO exception occurred while reading.
public static void writeInt(OutputStream out,
int x)
throws IOException
out - the output streamx - the value
IOException - if an IO exception occurred while writing.
public static int readInt(InputStream in)
throws IOException
in - the input stream
IOException - if an IO exception occurred while reading.
public static long readVarLong(InputStream in)
throws IOException
in - the input stream
IOException - if an IO exception occurred while reading.public static int nextPowerOf2(int x)
x - the original value
public static void closeQuietly(Closeable closeable)
Closeable.
Equivalent to Closeable.close(), except any exceptions will be ignored.
This is typically used in finally blocks.
closeable - the object to close, may be null or already closedpublic static void closeQuietly(Socket sock)
Socket.
Equivalent to Socket.close(), except any exceptions will be ignored.
This is typically used in finally blocks.
sock - the Socket to close, may be null or already closed
public static long copy(InputStream input,
OutputStream output)
throws IOException
InputStream to an
OutputStream.
This method buffers the input internally, so there is no need to use a
BufferedInputStream.
input - the InputStream to read fromoutput - the OutputStream to write to
IOException - if an I/O error occurspublic static String humanReadableByteCount(long bytes)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||