Package org.jlab.jlog.util
Class IOUtil
java.lang.Object
org.jlab.jlog.util.IOUtil
IO Utilities.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
arrayToCSV
(String[] values) Converts an array of String values to a comma-separated-values String.static void
Closes a Closeable without generating any checked Exceptions.static long
copy
(InputStream in, OutputStream out) Copies all of the bytes from the InputStream into the OutputStream using a buffer of 4096 bytes.static String[]
csvToArray
(String values) Converts a comma-separated-values String to an array of String values.static byte[]
decodeBase64
(String data) Decodes a base64 String to an array of bytes.static void
deleteQuietly
(File file) Deletes a file without generating any checked Exceptions.static String
encodeBase64
(byte[] data) Encodes an array of bytes to base64.static byte[]
fileToBytes
(File file) Fully reads in a file and returns an array of the bytes representing the file.static String
streamToString
(InputStream is, String encoding) Reads in an InputStream fully and returns the result as a String.
-
Method Details
-
closeQuietly
Closes a Closeable without generating any checked Exceptions. If an IOException does occur while closing it is logged as a WARNING.- Parameters:
c
- The Closeable
-
deleteQuietly
Deletes a file without generating any checked Exceptions. If unable to delete then a WARNING will be logged.- Parameters:
file
- The file
-
fileToBytes
Fully reads in a file and returns an array of the bytes representing the file. Be careful reading in large files because they may result in an OutOfMemoryError. This method uses the File length to efficiently allocate memory.- Parameters:
file
- The file to load into memory.- Returns:
- The bytes
- Throws:
IOException
- If an error occurs reading in the file.
-
copy
Copies all of the bytes from the InputStream into the OutputStream using a buffer of 4096 bytes.- Parameters:
in
- The InputStreamout
- The OutputStream- Returns:
- The number of bytes copied
- Throws:
IOException
- If unable to copy
-
streamToString
Reads in an InputStream fully and returns the result as a String.- Parameters:
is
- The InputStreamencoding
- The character encoding of the String- Returns:
- The String representation of the data
-
arrayToCSV
Converts an array of String values to a comma-separated-values String.- Parameters:
values
- The array- Returns:
- The comma-separated-values
-
csvToArray
Converts a comma-separated-values String to an array of String values. Whitespace on either side of commas are trimmed off.- Parameters:
values
- The comma-separated-values- Returns:
- The array of String values
-
encodeBase64
Encodes an array of bytes to base64.- Parameters:
data
- The bytes- Returns:
- A base64 encoded String
-
decodeBase64
Decodes a base64 String to an array of bytes.- Parameters:
data
- The base64 encoded String- Returns:
- The bytes
-