Class StreamHelper
- java.lang.Object
-
- org.fugerit.java.core.io.helper.StreamHelper
-
public class StreamHelper extends Object
This class provides primitives for piping streams and readers/writers content.
- Author:
- Fugerit
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
checkCloseInput(int modeClose)
Check if the source should be closed.static boolean
checkCloseOutput(int modeClose)
Check if the destination should be closed.static boolean
closeSafe(InputStream in)
Close an InputStream, eventually flushing itstatic boolean
closeSafe(OutputStream out)
Close an OutputStream, flushing itstatic boolean
closeSafe(OutputStream out, boolean flush)
Close an OutputStream, eventually flushing itstatic boolean
closeSafe(Reader in)
Close an Reader, eventually flushing itstatic boolean
closeSafe(Writer out)
Close an Writer, flushing itstatic boolean
closeSafe(Writer out, boolean flush)
Close an Writer, eventually flushing itstatic <T> InputStream
getResourceStream(String path, Class<T> c)
static long
pipe(InputStream src, OutputStream dst)
Pipe the content of a java.io.InputStream into a java.io.OutputStream.static long
pipe(InputStream src, OutputStream dst, int bufferSize, int modeClose)
Pipe the content of a java.io.InputStream into a java.io.OutputStream.static long
pipe(Reader src, Writer dst)
Pipe the content of a java.io.Reader into a java.io.Writer.static long
pipe(Reader src, Writer dst, int bufferSize, int modeClose)
Pipe the content of a java.io.Reader into a java.io.Writer.static InputStream
resolveStream(String path)
static InputStream
resolveStream(String path, String basePath)
static InputStream
resolveStream(String path, String basePath, Class<?> c)
static InputStream
resolveStreamByMode(String mode, String path)
static InputStream
resolveStreamByMode(String mode, String path, Class<?> c)
-
-
-
Field Detail
-
MODE_CLASSLOADER
public static final String MODE_CLASSLOADER
- See Also:
- Constant Field Values
-
MODE_FILE
public static final String MODE_FILE
- See Also:
- Constant Field Values
-
MODE_JNDI
public static final String MODE_JNDI
- See Also:
- Constant Field Values
-
PATH_CLASSLOADER
public static final String PATH_CLASSLOADER
- See Also:
- Constant Field Values
-
PATH_FILE
public static final String PATH_FILE
- See Also:
- Constant Field Values
-
PATH_JNDI
public static final String PATH_JNDI
- See Also:
- Constant Field Values
-
-
Method Detail
-
resolveStream
public static InputStream resolveStream(String path) throws IOException
- Throws:
IOException
-
resolveStream
public static InputStream resolveStream(String path, String basePath) throws IOException
- Throws:
IOException
-
getResourceStream
public static <T> InputStream getResourceStream(String path, Class<T> c) throws IOException
- Throws:
IOException
-
resolveStreamByMode
public static InputStream resolveStreamByMode(String mode, String path) throws IOException
- Throws:
IOException
-
resolveStreamByMode
public static InputStream resolveStreamByMode(String mode, String path, Class<?> c) throws IOException
- Throws:
IOException
-
resolveStream
public static InputStream resolveStream(String path, String basePath, Class<?> c) throws IOException
- Throws:
IOException
-
checkCloseInput
public static boolean checkCloseInput(int modeClose)
Check if the source should be closed.
- Parameters:
modeClose
- the mode for closing source- Returns:
true
if the source should be closed,false
otherwise.- See Also:
StreamIO
-
checkCloseOutput
public static boolean checkCloseOutput(int modeClose)
Check if the destination should be closed.
- Parameters:
modeClose
- the mode for closing destination- Returns:
true
if the destination should be closed,false
otherwise.- See Also:
StreamIO
-
pipe
public static long pipe(InputStream src, OutputStream dst, int bufferSize, int modeClose) throws IOException
Pipe the content of a java.io.InputStream into a java.io.OutputStream.
StreamIO provides constants for bufferSize and closeMode.
- Parameters:
src
- the sourcedst
- the destinationbufferSize
- buffer size for reading and writingmodeClose
- the mode for closing source and/or destination- Returns:
- the number of byte read/written
- Throws:
IOException
- in case of troubles during the operation- See Also:
StreamIO
-
pipe
public static long pipe(Reader src, Writer dst, int bufferSize, int modeClose) throws IOException
Pipe the content of a java.io.Reader into a java.io.Writer.
StreamIO provides constants for bufferSize and closeMode.
- Parameters:
src
- the sourcedst
- the destinationbufferSize
- buffer size for reading and writingmodeClose
- the mode for closing source and/or destination- Returns:
- the number of char read/written
- Throws:
IOException
- in case of troubles during the operation- See Also:
StreamIO
-
pipe
public static long pipe(InputStream src, OutputStream dst) throws IOException
Pipe the content of a java.io.InputStream into a java.io.OutputStream.
StreamIO.BUFFERSIZE_DEFAULT is used as bufferSize, both source and destination are closed at the end.
- Parameters:
src
- the sourcedst
- the destination- Returns:
- the number of byte read/written
- Throws:
IOException
- in case of troubles during the operation- See Also:
StreamIO
-
pipe
public static long pipe(Reader src, Writer dst) throws IOException
Pipe the content of a java.io.Reader into a java.io.Writer.
StreamIO.BUFFERSIZE_DEFAULT is used as bufferSize, both source and destination are closed at the end.
- Parameters:
src
- the sourcedst
- the destination- Returns:
- the number of byte read/written
- Throws:
IOException
- in case of troubles during the operation- See Also:
StreamIO
-
closeSafe
public static boolean closeSafe(OutputStream out)
Close an OutputStream, flushing it
- Parameters:
out
- the java.io.OutputStream to close- Returns:
true
if the stream has been closed without exception,false
otherwise
-
closeSafe
public static boolean closeSafe(OutputStream out, boolean flush)
Close an OutputStream, eventually flushing it
- Parameters:
out
- the java.io.OutputStream to closeflush
-true
if the stream should be flushed before closing- Returns:
true
if the stream has been closed without exception,false
otherwise
-
closeSafe
public static boolean closeSafe(InputStream in)
Close an InputStream, eventually flushing it
- Parameters:
in
- the java.io.InputStream to close- Returns:
true
if the stream has been closed without exception,false
otherwise
-
closeSafe
public static boolean closeSafe(Writer out)
Close an Writer, flushing it
- Parameters:
out
- the java.io.Writer to close- Returns:
true
if the writer has been closed without exception,false
otherwise
-
closeSafe
public static boolean closeSafe(Writer out, boolean flush)
Close an Writer, eventually flushing it
- Parameters:
out
- the java.io.Writer to closeflush
-true
if the writer should be flushed before closing- Returns:
true
if the writer has been closed without exception,false
otherwise
-
closeSafe
public static boolean closeSafe(Reader in)
Close an Reader, eventually flushing it
- Parameters:
in
- the java.io.Reader to close- Returns:
true
if the reader has been closed without exception,false
otherwise
-
-