Package org.cyclos.server.utils
Class IOHelper
- java.lang.Object
-
- org.cyclos.server.utils.IOHelper
-
public class IOHelper extends Object
Contains helper methods for IO handling
-
-
Constructor Summary
Constructors Constructor Description IOHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(Closeable closeable)Closes the givenCloseable, ignoring any exceptionsstatic voidclose(Closeable... closeables)Closes the givenCloseables, ignoring any exceptionsstatic voidcopyAndClose(InputStream in, File file)Copies all data from the givenInputStreaminto the givenFile, closing both streamsstatic voidcopyAndClose(InputStream in, OutputStream out)Copies all data from the givenInputStreaminto the givenOutputStream, closing both streamsstatic voidcopyAndClose(Reader in, File file)Copies all data from the givenReaderinto the givenOutputStream, closing both streamsstatic voidcopyAndClose(Reader in, Writer out)static longparseFileSize(String fileSize)Parses the given file size string into the number of bytes.static byte[]readBytesAndClose(InputStream in)Reads all bytes in the given input stream, closing it before returningstatic StringreadContentAndClose(Reader in)Reads the entire contents of the given reader as string, closing the readerstatic StringreadContentAsString(URL url)Reads the given URL content as string
-
-
-
Method Detail
-
close
public static void close(Closeable... closeables)
Closes the givenCloseables, ignoring any exceptions
-
close
public static void close(Closeable closeable)
Closes the givenCloseable, ignoring any exceptions
-
copyAndClose
public static void copyAndClose(InputStream in, File file) throws IOException
Copies all data from the givenInputStreaminto the givenFile, closing both streams- Throws:
IOException
-
copyAndClose
public static void copyAndClose(InputStream in, OutputStream out) throws IOException
Copies all data from the givenInputStreaminto the givenOutputStream, closing both streams- Throws:
IOException
-
copyAndClose
public static void copyAndClose(Reader in, File file) throws IOException
Copies all data from the givenReaderinto the givenOutputStream, closing both streams- Throws:
IOException
-
copyAndClose
public static void copyAndClose(Reader in, Writer out) throws IOException
- Throws:
IOException
-
parseFileSize
public static long parseFileSize(String fileSize)
Parses the given file size string into the number of bytes. It's accepted a floating point number followed by either G, GB, M, MB, K, KB, B or with no suffix. Throws IllegalArgumentException if the input doesn't match
-
readBytesAndClose
public static byte[] readBytesAndClose(InputStream in) throws IOException
Reads all bytes in the given input stream, closing it before returning- Throws:
IOException
-
readContentAndClose
public static String readContentAndClose(Reader in) throws IOException
Reads the entire contents of the given reader as string, closing the reader- Throws:
IOException
-
readContentAsString
public static String readContentAsString(URL url) throws IOException
Reads the given URL content as string- Throws:
IOException
-
-