Package com.castlabs.utils
Class IOUtils
java.lang.Object
com.castlabs.utils.IOUtils
Utility functions for IO operations
- Since:
- 2.0.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
closeQuietly
(com.google.android.exoplayer2.upstream.DataSource closeable) Quietly close the given DataSource and ignore any IO exceptions.static void
closeQuietly
(Closeable closeable) Quietly close the given closable and ignore any IO exceptions.static void
copy
(InputStream input, OutputStream output) Copy the content from the input to the output stream and closes both the input and the output streamstatic void
copy
(InputStream input, Writer writer) Copy the input stream content as UTF-8 chars to the writerstatic void
Copy the content from teh given reader to the given writer and closes reader and writerstatic byte[]
toByteArray
(InputStream content) Read and return the content of the given stream as byte[]static String
toString
(InputStream content) Gets the contents of an InputStream as a String assuming UTF8 encoding
-
Constructor Details
-
IOUtils
public IOUtils()
-
-
Method Details
-
toString
Gets the contents of an InputStream as a String assuming UTF8 encoding- Parameters:
content
- the input- Returns:
- content of the given input stream as String
- Throws:
IOException
- in case of any errors
-
toByteArray
Read and return the content of the given stream as byte[]- Parameters:
content
- the content- Returns:
- byte array of the content of the stream
- Throws:
IOException
- in case of any errors
-
closeQuietly
Quietly close the given closable and ignore any IO exceptions. Null input will be ignored.- Parameters:
closeable
- the closable. If null the method will just return.
-
closeQuietly
public static void closeQuietly(@Nullable com.google.android.exoplayer2.upstream.DataSource closeable) Quietly close the given DataSource and ignore any IO exceptions. Null input will be ignored.- Parameters:
closeable
- the closable. If null the method will just return.
-
copy
Copy the input stream content as UTF-8 chars to the writer- Parameters:
input
- input streamwriter
- output writer- Throws:
IOException
- in case of an error
-
copy
Copy the content from teh given reader to the given writer and closes reader and writer- Parameters:
reader
- the readerwriter
- the writer- Throws:
IOException
- in case of an error
-
copy
Copy the content from the input to the output stream and closes both the input and the output stream- Parameters:
input
- the input streamoutput
- the output stream- Throws:
IOException
- in case of an IO error while reading or writing the streams
-