Package org.eclipse.jetty.util
Class IO
java.lang.Object
org.eclipse.jetty.util.IO
IO Utilities.
Provides stream handling utilities in
singleton Threadpool implementation accessed by static members.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Closes an arbitrary closable, and logs exceptions at ignore levelstatic void
close
(InputStream is) closes an input stream, and logs exceptionsstatic void
close
(OutputStream os) closes an output stream, and logs exceptionsstatic void
closes a reader, and logs exceptionsstatic void
closes a writer, and logs exceptionsstatic void
Copy files or directoriesstatic void
copy
(InputStream in, OutputStream out) Copy Stream in to Stream out until EOF or exception.static void
copy
(InputStream in, OutputStream out, long byteCount) Copy Stream in to Stream for byteCount bytes or until EOF or exception.static void
Copy Reader to Writer out until EOF or exception.static void
Copy Reader to Writer for byteCount bytes or until EOF or exception.static void
static void
static boolean
Delete File.static InputStream
static PrintWriter
static OutputStream
static Writer
static boolean
isEmptyDir
(File dir) Test if directory is empty.static byte[]
readBytes
(InputStream in) static String
toString
(InputStream in) Read input stream to string.static String
toString
(InputStream in, String encoding) Read input stream to string.static String
toString
(InputStream in, Charset encoding) Read input stream to string.static String
Read input stream to string.static String
Read Path to string.static long
write
(GatheringByteChannel out, ByteBuffer[] buffers, int offset, int length) A gathering write utility wrapper.
-
Field Details
-
CRLF
- See Also:
-
CRLF_BYTES
public static final byte[] CRLF_BYTES -
bufferSize
public static final int bufferSize- See Also:
-
-
Constructor Details
-
IO
public IO()
-
-
Method Details
-
copy
Copy Stream in to Stream out until EOF or exception.- Parameters:
in
- the input stream to read from (until EOF)out
- the output stream to write to- Throws:
IOException
- if unable to copy streams
-
copy
Copy Reader to Writer out until EOF or exception.- Parameters:
in
- the read to read from (until EOF)out
- the writer to write to- Throws:
IOException
- if unable to copy the streams
-
copy
Copy Stream in to Stream for byteCount bytes or until EOF or exception.- Parameters:
in
- the stream to read fromout
- the stream to write tobyteCount
- the number of bytes to copy- Throws:
IOException
- if unable to copy the streams
-
copy
Copy Reader to Writer for byteCount bytes or until EOF or exception.- Parameters:
in
- the Reader to read fromout
- the Writer to write tobyteCount
- the number of bytes to copy- Throws:
IOException
- if unable to copy streams
-
copy
Copy files or directories- Parameters:
from
- the file to copyto
- the destination to copy to- Throws:
IOException
- if unable to copy
-
copyDir
- Throws:
IOException
-
copyFile
- Throws:
IOException
-
toString
Read Path to string.- Parameters:
path
- the path to read from (until EOF)charset
- the charset to read with- Returns:
- the String parsed from path (default Charset)
- Throws:
IOException
- if unable to read the path (or handle the charset)
-
toString
Read input stream to string.- Parameters:
in
- the stream to read from (until EOF)- Returns:
- the String parsed from stream (default Charset)
- Throws:
IOException
- if unable to read the stream (or handle the charset)
-
toString
Read input stream to string.- Parameters:
in
- the stream to read from (until EOF)encoding
- the encoding to use (can be null to use default Charset)- Returns:
- the String parsed from the stream
- Throws:
IOException
- if unable to read the stream (or handle the charset)
-
toString
Read input stream to string.- Parameters:
in
- the stream to read from (until EOF)encoding
- the Charset to use (can be null to use default Charset)- Returns:
- the String parsed from the stream
- Throws:
IOException
- if unable to read the stream (or handle the charset)
-
toString
Read input stream to string.- Parameters:
in
- the reader to read from (until EOF)- Returns:
- the String parsed from the reader
- Throws:
IOException
- if unable to read the stream (or handle the charset)
-
delete
Delete File. This delete will recursively delete directories - BE CAREFUL- Parameters:
file
- The file (or directory) to be deleted.- Returns:
- true if file was deleted, or directory referenced was deleted. false if file doesn't exist, or was null.
-
isEmptyDir
Test if directory is empty.- Parameters:
dir
- the directory- Returns:
- true if directory is null, doesn't exist, or has no content. false if not a directory, or has contents
-
close
Closes an arbitrary closable, and logs exceptions at ignore level- Parameters:
closeable
- the closeable to close
-
close
closes an input stream, and logs exceptions- Parameters:
is
- the input stream to close
-
close
closes an output stream, and logs exceptions- Parameters:
os
- the output stream to close
-
close
closes a reader, and logs exceptions- Parameters:
reader
- the reader to close
-
close
closes a writer, and logs exceptions- Parameters:
writer
- the writer to close
-
readBytes
- Throws:
IOException
-
write
public static long write(GatheringByteChannel out, ByteBuffer[] buffers, int offset, int length) throws IOException A gathering write utility wrapper.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.
- Parameters:
out
- The GatheringByteChannel to write tobuffers
- The buffers to writeoffset
- The offset into the buffers arraylength
- The length in buffers to write- Returns:
- The total bytes written
- Throws:
IOException
- if unable write to the GatheringByteChannel
-
getNullStream
- Returns:
- An outputstream to nowhere
-
getClosedStream
- Returns:
- An outputstream to nowhere
-
getNullWriter
- Returns:
- An writer to nowhere
-
getNullPrintWriter
- Returns:
- An writer to nowhere
-