public class IO
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
bufferSize |
static java.lang.String |
CRLF |
static byte[] |
CRLF_BYTES |
Constructor and Description |
---|
IO() |
Modifier and Type | Method and Description |
---|---|
static void |
close(java.io.Closeable closeable)
Closes an arbitrary closable, and logs exceptions at ignore level
|
static void |
close(java.io.InputStream is)
closes an input stream, and logs exceptions
|
static void |
close(java.io.OutputStream os)
closes an output stream, and logs exceptions
|
static void |
close(java.io.Reader reader)
closes a reader, and logs exceptions
|
static void |
close(java.io.Writer writer)
closes a writer, and logs exceptions
|
static void |
copy(java.io.File from,
java.io.File to)
Copy files or directories
|
static void |
copy(java.io.InputStream in,
java.io.OutputStream out)
Copy Stream in to Stream out until EOF or exception.
|
static void |
copy(java.io.InputStream in,
java.io.OutputStream out,
long byteCount)
Copy Stream in to Stream for byteCount bytes or until EOF or exception.
|
static void |
copy(java.io.Reader in,
java.io.Writer out)
Copy Reader to Writer out until EOF or exception.
|
static void |
copy(java.io.Reader in,
java.io.Writer out,
long byteCount)
Copy Reader to Writer for byteCount bytes or until EOF or exception.
|
static void |
copyDir(java.io.File from,
java.io.File to) |
static void |
copyFile(java.io.File from,
java.io.File to) |
static boolean |
delete(java.io.File file)
Delete File.
|
static java.io.InputStream |
getClosedStream() |
static java.io.PrintWriter |
getNullPrintWriter() |
static java.io.OutputStream |
getNullStream() |
static java.io.Writer |
getNullWriter() |
static boolean |
isEmptyDir(java.io.File dir)
Test if directory is empty.
|
static byte[] |
readBytes(java.io.InputStream in) |
static java.lang.String |
toString(java.io.InputStream in)
Read input stream to string.
|
static java.lang.String |
toString(java.io.InputStream in,
java.nio.charset.Charset encoding)
Read input stream to string.
|
static java.lang.String |
toString(java.io.InputStream in,
java.lang.String encoding)
Read input stream to string.
|
static java.lang.String |
toString(java.nio.file.Path path,
java.nio.charset.Charset charset)
Read Path to string.
|
static java.lang.String |
toString(java.io.Reader in)
Read input stream to string.
|
static long |
write(java.nio.channels.GatheringByteChannel out,
java.nio.ByteBuffer[] buffers,
int offset,
int length)
A gathering write utility wrapper.
|
public static final java.lang.String CRLF
public static final byte[] CRLF_BYTES
public static final int bufferSize
public static void copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
in
- the input stream to read from (until EOF)out
- the output stream to write tojava.io.IOException
- if unable to copy streamspublic static void copy(java.io.Reader in, java.io.Writer out) throws java.io.IOException
in
- the read to read from (until EOF)out
- the writer to write tojava.io.IOException
- if unable to copy the streamspublic static void copy(java.io.InputStream in, java.io.OutputStream out, long byteCount) throws java.io.IOException
in
- the stream to read fromout
- the stream to write tobyteCount
- the number of bytes to copyjava.io.IOException
- if unable to copy the streamspublic static void copy(java.io.Reader in, java.io.Writer out, long byteCount) throws java.io.IOException
in
- the Reader to read fromout
- the Writer to write tobyteCount
- the number of bytes to copyjava.io.IOException
- if unable to copy streamspublic static void copy(java.io.File from, java.io.File to) throws java.io.IOException
from
- the file to copyto
- the destination to copy tojava.io.IOException
- if unable to copypublic static void copyDir(java.io.File from, java.io.File to) throws java.io.IOException
java.io.IOException
public static void copyFile(java.io.File from, java.io.File to) throws java.io.IOException
java.io.IOException
public static java.lang.String toString(java.nio.file.Path path, java.nio.charset.Charset charset) throws java.io.IOException
path
- the path to read from (until EOF)charset
- the charset to read withjava.io.IOException
- if unable to read the path (or handle the charset)public static java.lang.String toString(java.io.InputStream in) throws java.io.IOException
in
- the stream to read from (until EOF)java.io.IOException
- if unable to read the stream (or handle the charset)public static java.lang.String toString(java.io.InputStream in, java.lang.String encoding) throws java.io.IOException
in
- the stream to read from (until EOF)encoding
- the encoding to use (can be null to use default Charset)java.io.IOException
- if unable to read the stream (or handle the charset)public static java.lang.String toString(java.io.InputStream in, java.nio.charset.Charset encoding) throws java.io.IOException
in
- the stream to read from (until EOF)encoding
- the Charset to use (can be null to use default Charset)java.io.IOException
- if unable to read the stream (or handle the charset)public static java.lang.String toString(java.io.Reader in) throws java.io.IOException
in
- the reader to read from (until EOF)java.io.IOException
- if unable to read the stream (or handle the charset)public static boolean delete(java.io.File file)
file
- The file (or directory) to be deleted.public static boolean isEmptyDir(java.io.File dir)
dir
- the directorypublic static void close(java.io.Closeable closeable)
closeable
- the closeable to closepublic static void close(java.io.InputStream is)
is
- the input stream to closepublic static void close(java.io.OutputStream os)
os
- the output stream to closepublic static void close(java.io.Reader reader)
reader
- the reader to closepublic static void close(java.io.Writer writer)
writer
- the writer to closepublic static byte[] readBytes(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public static long write(java.nio.channels.GatheringByteChannel out, java.nio.ByteBuffer[] buffers, int offset, int length) throws java.io.IOException
This method wraps a gather write with a loop that handles the limitations of some operating systems that have a limit on the number of buffers written. The method loops on the write until either all the content is written or no progress is made.
out
- The GatheringByteChannel to write tobuffers
- The buffers to writeoffset
- The offset into the buffers arraylength
- The length in buffers to writejava.io.IOException
- if unable write to the GatheringByteChannelpublic static java.io.OutputStream getNullStream()
public static java.io.InputStream getClosedStream()
public static java.io.Writer getNullWriter()
public static java.io.PrintWriter getNullPrintWriter()
Copyright © 1995–2021 Webtide. All rights reserved.