public class IOUtils extends Object
限定符和类型 | 类和说明 |
---|---|
static class |
IOUtils.NullOutputStream
/dev/null of OutputStreams.
|
构造器和说明 |
---|
IOUtils() |
限定符和类型 | 方法和说明 |
---|---|
static void |
cleanup(org.apache.commons.logging.Log log,
Closeable... closeables)
Close the Closeable objects and ignore any
IOException or
null pointers. |
static void |
closeSocket(Socket sock)
Closes the socket ignoring
IOException |
static void |
closeStream(Closeable stream)
Closes the stream ignoring
IOException . |
static void |
copyBytes(InputStream in,
OutputStream out,
Configuration conf)
Copies from one stream to another.
|
static void |
copyBytes(InputStream in,
OutputStream out,
Configuration conf,
boolean close)
Copies from one stream to another.
|
static void |
copyBytes(InputStream in,
OutputStream out,
int buffSize)
Copies from one stream to another.
|
static void |
copyBytes(InputStream in,
OutputStream out,
int buffSize,
boolean close)
Copies from one stream to another.
|
static void |
copyBytes(InputStream in,
OutputStream out,
long length,
int bufferSize,
boolean close)
Copies the specified length of bytes from in to out.
|
static void |
readFileChannelFully(FileChannel fileChannel,
byte[] buf,
int off,
int len)
Reads len bytes in a loop using the channel of the stream
|
static void |
readFully(InputStream in,
byte[] buf,
int off,
int len)
Reads len bytes in a loop.
|
static void |
skipFully(InputStream in,
long len)
Similar to readFully().
|
static int |
wrappedReadForCompressedData(InputStream is,
byte[] buf,
int off,
int len)
Utility wrapper for reading from
InputStream . |
public static void copyBytes(InputStream in, OutputStream out, int buffSize, boolean close) throws IOException
in
- InputStrem to read fromout
- OutputStream to write tobuffSize
- the size of the bufferclose
- whether or not close the InputStream and
OutputStream at the end. The streams are closed in the finally clause.IOException
public static void copyBytes(InputStream in, OutputStream out, int buffSize) throws IOException
in
- InputStrem to read fromout
- OutputStream to write tobuffSize
- the size of the bufferIOException
public static void copyBytes(InputStream in, OutputStream out, Configuration conf) throws IOException
in
- InputStrem to read fromout
- OutputStream to write toconf
- the Configuration objectIOException
public static void copyBytes(InputStream in, OutputStream out, Configuration conf, boolean close) throws IOException
in
- InputStrem to read fromout
- OutputStream to write toconf
- the Configuration objectclose
- whether or not close the InputStream and
OutputStream at the end. The streams are closed in the finally clause.IOException
public static void copyBytes(InputStream in, OutputStream out, long length, int bufferSize, boolean close) throws IOException
in
- InputStream to read fromout
- OutputStream to write tolength
- number of bytes to copybufferSize
- the size of the bufferclose
- whether to close the streamsIOException
- if bytes can not be read or writtenpublic static int wrappedReadForCompressedData(InputStream is, byte[] buf, int off, int len) throws IOException
InputStream
. It catches any errors
thrown by the underlying stream (either IO or decompression-related), and
re-throws as an IOException.is
- - InputStream to be read frombuf
- - buffer the data is read intooff
- - offset within buflen
- - amount of data to be readIOException
public static void readFully(InputStream in, byte[] buf, int off, int len) throws IOException
in
- The InputStream to read frombuf
- The buffer to filloff
- offset from the bufferlen
- the length of bytes to readIOException
- if it could not read requested number of bytes
for any reason (including EOF)public static void readFileChannelFully(FileChannel fileChannel, byte[] buf, int off, int len) throws IOException
fileChannel
- a FileChannel to read len bytes into bufbuf
- The buffer to filloff
- offset from the bufferlen
- the length of bytes to readIOException
- if it could not read requested number of bytes
for any reason (including EOF)public static void skipFully(InputStream in, long len) throws IOException
in
- The InputStream to skip bytes fromlen
- number of bytes to skip.IOException
- if it could not skip requested number of bytes
for any reason (including EOF)public static void cleanup(org.apache.commons.logging.Log log, Closeable... closeables)
IOException
or
null pointers. Must only be used for cleanup in exception handlers.log
- the log to record problems to at debug level. Can be null.closeables
- the objects to closepublic static void closeStream(Closeable stream)
IOException
.
Must only be called in cleaning up from exception handlers.stream
- the Stream to closepublic static void closeSocket(Socket sock)
IOException
sock
- the Socket to closeCopyright © 2009 The Apache Software Foundation