public class IOUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
copy(java.io.InputStream in,
java.io.OutputStream out)
Copies all the bytes from a given input stream to a given output stream.
|
static byte[] |
getLineSeparatorBytes()
Returns the platform's line separator as a byte array given the
platform's default encoding.
|
static java.lang.String |
getResourceContents(java.lang.Class<?> clazz,
java.lang.String name,
java.util.logging.Level level)
Reads a static resource and returns the contents as a string.
|
static void |
println(java.io.OutputStream out,
java.lang.String line)
Writes a string to an output stream followed by a new line.
|
static byte[] |
readBytes(java.io.InputStream in,
int maxLeng)
Reads a number of bytes from a stream.
|
static void |
skip(java.io.InputStream strm,
long nskip)
Skips over a number of bytes in an
InputStream
This is implemented using InputStream.skip(long)
but differs from it in that it guarantees to skip the bytes
as specified, or to throw an exception. |
static void |
skipBytes(java.io.DataInput strm,
long nskip)
Skips over a number of bytes in a
DataInput . |
public static void skipBytes(java.io.DataInput strm, long nskip) throws java.io.IOException
DataInput
.
This is implemented using DataInput.skipBytes(int)
but differs from it in that it guarantees to skip the bytes
as specified, or to throw an exception.strm
- the stream to skip throughnskip
- the number of bytes to skipjava.io.EOFException
- if the end of file is reachedjava.io.IOException
- if an I/O error occursjava.lang.IllegalArgumentException
- if nskip<0
public static void skip(java.io.InputStream strm, long nskip) throws java.io.IOException
InputStream
This is implemented using InputStream.skip(long)
but differs from it in that it guarantees to skip the bytes
as specified, or to throw an exception.strm
- the stream to skip throughnskip
- the number of bytes to skipjava.io.EOFException
- if the end of file is reachedjava.io.IOException
- if an I/O error occursjava.lang.IllegalArgumentException
- if nskip<0
public static java.lang.String getResourceContents(java.lang.Class<?> clazz, java.lang.String name, java.util.logging.Level level)
clazz.getResourceAsStream(name)
and is assumed to have ASCII content. The result is cached so that
subsequent calls will return the same value.
If it can't be read, "?" is returned, and a message is written
through the logging system at the requested level.
This is intended for short files such as version strings.clazz
- class defining relative location of resourcename
- resource name relative to clazz
level
- logging level for failure; if null a default value
is used (currently WARNING)Class.getResourceAsStream(java.lang.String)
public static void println(java.io.OutputStream out, java.lang.String line) throws java.io.IOException
PrintStream.println()
, an IOException may
be thrown.out
- destination streamline
- line to writejava.io.IOException
public static byte[] getLineSeparatorBytes()
public static void copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
in
- sourceout
- destinationjava.io.IOException
public static byte[] readBytes(java.io.InputStream in, int maxLeng) throws java.io.IOException
in
- input streammaxLeng
- maximum number of bytes to readmaxLeng
bytes
read from in
, or fewer if the stream ended earlyjava.io.IOException