Package com.fizzed.crux.util
Class InOuts
- java.lang.Object
-
- com.fizzed.crux.util.InOuts
-
public class InOuts extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceInOuts.ByteReadConsumer
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_BUFFER_SIZE
-
Constructor Summary
Constructors Constructor Description InOuts()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]bytes(java.io.InputStream input)Reads all bytes from input to a byte array AND will close input at EOF.static byte[]bytes(java.io.InputStream input, boolean close)Reads all bytes from input to a byte array AND will optionally close the input at EOF.static voidclose(java.io.InputStream input)Null-safe closing of an inputstream (but will still throw an IOException)static voidclose(java.io.OutputStream output)Null-safe closing of an outputstream (but will still throw an IOException)static voidcloseQuietly(java.io.InputStream input)Null-safe closing of an inputstream AND any exception during the close will be discarded.static voidcloseQuietly(java.io.OutputStream output)Null-safe closing of an ouputstream AND any exception during the close will be discarded.static longconsume(java.io.InputStream input, int bufferSize, InOuts.ByteReadConsumer consumer)Consumes an input stream in chunks (the buffer size) and allows you to simply write the consuming code.static longconsume(java.io.InputStream input, InOuts.ByteReadConsumer consumer)Consumes an input stream in chunks (the buffer size) and allows you to simply write the consuming code.static longcopy(java.io.InputStream input, java.io.OutputStream output)Copies an input stream to an output stream in chunks (the buffer size).static longcopy(java.io.InputStream input, java.io.OutputStream output, int bufferSize)Copies an input stream to an output stream in chunks (the buffer size).static java.lang.Stringstring(java.io.InputStream input, java.nio.charset.Charset charset)static java.lang.Stringstring(java.io.InputStream input, java.nio.charset.Charset charset, boolean close)static java.lang.StringstringUTF8(java.io.InputStream input)static java.lang.StringstringUTF8(java.io.InputStream input, boolean close)
-
-
-
Field Detail
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
close
public static void close(java.io.InputStream input) throws java.io.IOExceptionNull-safe closing of an inputstream (but will still throw an IOException)- Parameters:
input-- Throws:
java.io.IOException
-
close
public static void close(java.io.OutputStream output) throws java.io.IOExceptionNull-safe closing of an outputstream (but will still throw an IOException)- Parameters:
output-- Throws:
java.io.IOException
-
closeQuietly
public static void closeQuietly(java.io.InputStream input)
Null-safe closing of an inputstream AND any exception during the close will be discarded.- Parameters:
input-
-
closeQuietly
public static void closeQuietly(java.io.OutputStream output)
Null-safe closing of an ouputstream AND any exception during the close will be discarded.- Parameters:
output-
-
bytes
public static byte[] bytes(java.io.InputStream input) throws java.io.IOExceptionReads all bytes from input to a byte array AND will close input at EOF.- Parameters:
input-- Returns:
- Throws:
java.io.IOException
-
bytes
public static byte[] bytes(java.io.InputStream input, boolean close) throws java.io.IOExceptionReads all bytes from input to a byte array AND will optionally close the input at EOF.- Parameters:
input-- Returns:
- Throws:
java.io.IOException
-
string
public static java.lang.String string(java.io.InputStream input, java.nio.charset.Charset charset) throws java.io.IOException- Throws:
java.io.IOException
-
string
public static java.lang.String string(java.io.InputStream input, java.nio.charset.Charset charset, boolean close) throws java.io.IOException- Throws:
java.io.IOException
-
stringUTF8
public static java.lang.String stringUTF8(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
stringUTF8
public static java.lang.String stringUTF8(java.io.InputStream input, boolean close) throws java.io.IOException- Throws:
java.io.IOException
-
copy
public static long copy(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOExceptionCopies an input stream to an output stream in chunks (the buffer size). Does NOT close the input or output streams.- Parameters:
input-output-- Returns:
- Throws:
java.io.IOException
-
copy
public static long copy(java.io.InputStream input, java.io.OutputStream output, int bufferSize) throws java.io.IOExceptionCopies an input stream to an output stream in chunks (the buffer size). Does NOT close the input or output streams.- Parameters:
input-output-bufferSize-- Returns:
- Throws:
java.io.IOException
-
consume
public static long consume(java.io.InputStream input, InOuts.ByteReadConsumer consumer) throws java.io.IOExceptionConsumes an input stream in chunks (the buffer size) and allows you to simply write the consuming code. Does NOT close the inputstream.- Parameters:
input-consumer-- Returns:
- Throws:
java.io.IOException
-
consume
public static long consume(java.io.InputStream input, int bufferSize, InOuts.ByteReadConsumer consumer) throws java.io.IOExceptionConsumes an input stream in chunks (the buffer size) and allows you to simply write the consuming code. Does NOT close the inputstream.- Parameters:
input-bufferSize-consumer-- Returns:
- Throws:
java.io.IOException
-
-