Package org.jppf.utils.streams
Class StreamUtils
java.lang.Object
org.jppf.utils.streams.StreamUtils
Collection of utility methods for manipulating streams.
- Author:
- Laurent Cohen
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidclose(AutoCloseable closeable) Attempt to close the specified closeable without logging an eventual error.static voidclose(AutoCloseable closeable, org.slf4j.Logger log) Attempt to close the specified closeable and log any eventual error.static voidcloseSilent(AutoCloseable closeable) Attempt to silently close (no exception logging) the specified closeable.static longCopy the data read from the specified input stream to the specified output stream.static longcopyStream(InputStream is, OutputStream os) Copy the data read from the specified input stream to the specified output stream.static longcopyStream(InputStream is, OutputStream os, boolean closeStreams) Copy the data read from the specified input stream to the specified output stream.static byte[]Get the content of an input stream as an array of bytes.static voidConvenience method to print a formatted mssage to System.out and a specified logger.static voidDisplay a message and wait until a key is pressed.static voidwaitKeyPressed(char c, String message) Display a message and wait until the specified key is pressed.static voidwaitKeyPressed(String message) Display a message and wait until a key is pressed.
-
Method Details
-
close
Attempt to close the specified closeable without logging an eventual error.- Parameters:
closeable- the closeable to close.- Throws:
Exception- if any error occurs while closing the closeable.
-
closeSilent
Attempt to silently close (no exception logging) the specified closeable.- Parameters:
closeable- the closeable to close.
-
close
Attempt to close the specified closeable and log any eventual error.- Parameters:
closeable- the closeable to close.log- the logger to use; if null no logging occurs.
-
getInputStreamAsByte
Get the content of an input stream as an array of bytes. This method closes the input stream before terminating.- Parameters:
is- the input stream to read from.- Returns:
- a byte array.
- Throws:
IOException- if an IO error occurs.
-
copyFile
Copy the data read from the specified input stream to the specified output stream. This method closes both streams before terminating.- Parameters:
src- the input stream to read from.dest- the output stream to write to.- Returns:
- the number of bytes copied.
- Throws:
IOException- if an I/O error occurs.
-
copyStream
Copy the data read from the specified input stream to the specified output stream. This method closes both streams before terminating.- Parameters:
is- the input stream to read from.os- the output stream to write to.- Returns:
- the number of bytes copied.
- Throws:
IOException- if an I/O error occurs.
-
copyStream
public static long copyStream(InputStream is, OutputStream os, boolean closeStreams) throws IOException Copy the data read from the specified input stream to the specified output stream. This method closes both streams before terminating.- Parameters:
is- the input stream to read from.os- the output stream to write to.closeStreams-trueto cause the streams to be closed at the end of the copy,falseotherwise.- Returns:
- the number of bytes copied.
- Throws:
IOException- if an I/O error occurs.
-
waitKeyPressed
Display a message and wait until a key is pressed.- Throws:
Exception- if any I/O error occurs.
-
waitKeyPressed
Display a message and wait until a key is pressed.- Parameters:
message- the message to dispplay- Throws:
Exception- if any I/O error occurs.
-
waitKeyPressed
Display a message and wait until the specified key is pressed.- Parameters:
c- the character to wait for.message- the message to dispplay.- Throws:
Exception- if any I/O error occurs.
-
printf
Convenience method to print a formatted mssage to System.out and a specified logger.- Parameters:
logger- the logger to print to, may benull. If specified, the message is logged at INFO level.format- the message format as specified inFormatter.params- the formatted message parameters.
-