Package io.microsphere.io
Class IOUtils
- java.lang.Object
-
- io.microsphere.io.IOUtils
-
-
Field Summary
Fields Modifier and Type Field Description static intBUFFER_SIZEThe buffer size for I/Ostatic intDEFAULT_BUFFER_SIZEThe default buffer size for I/O
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(java.io.Closeable closeable)Unconditionally close aCloseable.static intcopy(java.io.InputStream in, java.io.OutputStream out)Copy the contents of the given InputStream to the given OutputStream.static intcopy(java.io.Reader reader, java.io.Writer writer)Copy the contents of the given Reader to the given Writer.static java.lang.StringcopyToString(java.io.InputStream in)Copy the contents of the given InputStream into a newStringusingCharsetUtils.DEFAULT_CHARSET.static java.lang.StringcopyToString(java.io.InputStream in, java.lang.String encoding)Copy the contents of the given InputStream into a newString.static java.lang.StringcopyToString(java.io.InputStream in, java.nio.charset.Charset charset)static java.lang.StringcopyToString(java.io.Reader reader)Copy the contents of the given Reader into a newString.static byte[]toByteArray(java.io.InputStream in)Copy the contents of the given InputStream into a new byte array.static java.lang.StringtoString(java.io.InputStream in)copyToString(InputStream)as recommendedstatic java.lang.StringtoString(java.io.InputStream in, java.lang.String encoding)copyToString(InputStream, String)as recommendedstatic java.lang.StringtoString(java.io.InputStream in, java.nio.charset.Charset charset)copyToString(InputStream, Charset)as recommendedstatic java.lang.StringtoString(java.io.Reader reader)copyToString(Reader)as recommended
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
The default buffer size for I/O- See Also:
- Constant Field Values
-
BUFFER_SIZE
public static final int BUFFER_SIZE
The buffer size for I/O
-
-
Method Detail
-
toByteArray
public static byte[] toByteArray(java.io.InputStream in) throws java.io.IOExceptionCopy the contents of the given InputStream into a new byte array.Leaves the stream open when done.
- Parameters:
in- the stream to copy from (may benullor empty)- Returns:
- the new byte array that has been copied to (possibly empty)
- Throws:
java.io.IOException- in case of I/O errors
-
toString
public static java.lang.String toString(java.io.InputStream in) throws java.io.IOExceptioncopyToString(InputStream)as recommended- Throws:
java.io.IOException- See Also:
copyToString(InputStream)
-
toString
public static java.lang.String toString(java.io.InputStream in, java.lang.String encoding) throws java.io.IOExceptioncopyToString(InputStream, String)as recommended- Throws:
java.io.IOException- See Also:
copyToString(InputStream, String)
-
toString
public static java.lang.String toString(java.io.InputStream in, java.nio.charset.Charset charset) throws java.io.IOExceptioncopyToString(InputStream, Charset)as recommended- Throws:
java.io.IOException- See Also:
copyToString(InputStream, Charset)
-
toString
public static java.lang.String toString(java.io.Reader reader) throws java.io.IOExceptioncopyToString(Reader)as recommended- Throws:
java.io.IOException- See Also:
copyToString(Reader)
-
copyToString
public static java.lang.String copyToString(java.io.InputStream in, java.lang.String encoding) throws java.io.IOExceptionCopy the contents of the given InputStream into a newString.Leaves the stream open when done.
- Parameters:
in- the stream to copy from (may benullor empty)encoding- the encoding to use, if it'snull, take theSystemUtils.FILE_ENCODINGas default- Returns:
- the new byte array that has been copied to (possibly empty)
- Throws:
java.io.IOException- in case of I/O errors
-
copyToString
public static java.lang.String copyToString(java.io.InputStream in) throws java.io.IOExceptionCopy the contents of the given InputStream into a newStringusingCharsetUtils.DEFAULT_CHARSET.Leaves the stream open when done.
- Parameters:
in- the stream to copy from (may benullor empty)- Returns:
- the new byte array that has been copied to (possibly empty)
- Throws:
java.io.IOException- in case of I/O errors
-
copyToString
public static java.lang.String copyToString(java.io.InputStream in, java.nio.charset.Charset charset) throws java.io.IOException- Throws:
java.io.IOException
-
copyToString
public static java.lang.String copyToString(java.io.Reader reader) throws java.io.IOExceptionCopy the contents of the given Reader into a newString.Leaves the Reader open when done.
- Parameters:
reader- the Reader to copy from (may benullor empty)- Returns:
- the new String that has been copied to (possibly empty)
- Throws:
java.io.IOException- in case of I/O errors
-
copy
public static int copy(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOExceptionCopy the contents of the given InputStream to the given OutputStream.Leaves both streams open when done.
- Parameters:
in- the InputStream to copy fromout- the OutputStream to copy to- Returns:
- the number of bytes copied
- Throws:
java.io.IOException- in case of I/O errors
-
copy
public static int copy(java.io.Reader reader, java.io.Writer writer) throws java.io.IOExceptionCopy the contents of the given Reader to the given Writer.Leaves both streams open when done.
- Parameters:
reader- the Reader to copy fromwriter- the Writer to copy to- Returns:
- the number of chars copied
- Throws:
java.io.IOException- in case of I/O errors
-
close
public static void close(java.io.Closeable closeable)
Unconditionally close aCloseable.Equivalent to
Closeable.close(), except any exceptions will be ignored. This is typically used in finally blocks.Example code:
Closeable closeable = null; try { closeable = new FileReader("foo.txt"); // process closeable closeable.close(); } catch (Exception e) { // error handling } finally { IOUtils.closeQuietly(closeable); }- Parameters:
closeable- the object to close, may be null or already closed
-
-