java.lang.Object
org.jorigin.io.IOStreamUtil
This class is an helper class designed for the handling of I/O streams. This class provide methods for creating and managing streams from various sources.
- Since:
- 1.0.0
- Version:
- "1.0.14" - b202111241200L
- Author:
- Julien SEINTURIER - Université de Toulon / CNRS LIS umr 7020 - github.com/jorigin/jcommon (contact@jorigin.org)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancopy(InputStream source, OutputStream destination) Simple copy of an input stream to an output stream.static BufferedInputStreamGet a buffered input stream from theurigiven in parameter.static BufferedInputStreamgetBufferedInputStream(String uri, int bufferSize) Get a buffered input stream from theurigiven in parameter.static BufferedOutputStreamGet a buffered output stream to theurigiven in parameter.static BufferedOutputStreamgetBufferedOutputStream(String uri, int bufferSize) Get a buffered output stream to theurigiven in parameter.static InputStreamgetInputStream(String uri) Open anInputStreamfrom the resource located by the givenuri.static OutputStreamgetOutputStream(String uri) Get an output stream to theurigiven in parameter.
-
Constructor Details
-
IOStreamUtil
public IOStreamUtil()
-
-
Method Details
-
getInputStream
Open anInputStreamfrom the resource located by the givenuri. The returned stream can be:
- a
FileInputStreamif the resource is a file on a local system; - a
BufferedInputStreamif the resource is anurlor a location on a remote system;
- Parameters:
uri- the location of the resource- Returns:
- the input stream opened to the resource
- Throws:
IOException- if an error occurs.
- a
-
getBufferedInputStream
Get a buffered input stream from theurigiven in parameter.- Parameters:
uri- the uri source of the input stream.- Returns:
- a buffered input stream.
- Throws:
IOException- if the stream cannot be set up.
-
getBufferedInputStream
public static BufferedInputStream getBufferedInputStream(String uri, int bufferSize) throws IOException Get a buffered input stream from theurigiven in parameter. The input stream buffer size is given by thebufferSizeparameter. If the buffer size is less than 1, the buffered input stream created have a default buffer size.- Parameters:
uri- the uri source of the input stream.bufferSize- the size of the buffer- Returns:
- a buffered input stream.
- Throws:
IOException- if the stream cannot be set up.
-
getOutputStream
Get an output stream to theurigiven in parameter.- Parameters:
uri- the uri of the resource outputed- Returns:
- an output stream to the resource.
- Throws:
IOException- if the output stream cannot be set up.
-
getBufferedOutputStream
Get a buffered output stream to theurigiven in parameter.- Parameters:
uri- the uri source of the output stream.- Returns:
- a buffered output stream.
- Throws:
IOException- if the stream cannot be set up.- See Also:
-
getBufferedOutputStream
public static BufferedOutputStream getBufferedOutputStream(String uri, int bufferSize) throws IOException Get a buffered output stream to theurigiven in parameter. The output stream buffer size is given by thebufferSizeparameter. If the buffer size is less than 1, the buffered output stream created have a default buffer size.- Parameters:
uri- the uri source of the output stream.bufferSize- the size of the buffer- Returns:
- a buffered output stream.
- Throws:
IOException- if the stream cannot be set up.
-
copy
Simple copy of an input stream to an output stream.- Parameters:
source- Input stream to the sourcedestination- Output stream to the destination- Returns:
trueif the copy was successfull,falseif not
-