Package com.storedobject.common
Class IO
java.lang.Object
com.storedobject.common.IO
Generic Input/Output routines.
All 'get' methods return 'buffered' streams/readers/writers. 'Double buffering' is avoided.
Conversion between streams and reader/writer are with UTF-8 encoding.
- Author:
- Syam
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ByteBufferCreate a read/write byte buffer from the content of the input stream.static voidclose(AutoCloseable... closeables) static BufferedInputStreamconcat(InputStream in1, InputStream in2) Create a concatenated stream from the 2 streams.static BufferedReaderCreate a concatenated reader from the 2 readers.static InputStreamconnect(InputStream in, OutputStream out) Connect an input stream to an output stream so that the output stream is closed when the input stream is closed.static OutputStreamconnect(OutputStream out, InputStream in) Connect an output stream to an input stream so that the input stream is closed when the output stream is closed.static voidcopy(InputStream input, OutputStream output) Copy one stream to another.static voidcopy(InputStream input, OutputStream output, boolean close) Copy one stream to anotherstatic voidcopy(InputStream input, OutputStream output, int bufferSize) Copy one stream to another.static voidcopy(InputStream input, OutputStream output, int bufferSize, boolean close) Copy one stream to anotherstatic voidCopy from reader to writer.static voidCopy from reader to writer.static BufferedInputStreamget(InputStream in) Convert a stream to a buffered streamstatic BufferedOutputStreamget(OutputStream out) Convert a stream to a buffered streamstatic BufferedReaderConvert a reader to a buffered readerstatic BufferedWriterConvert a writer to a buffered writerstatic DataInputStreamgetData(InputStream in) Convert a stream to a buffered data streamstatic DataOutputStreamgetData(OutputStream out) Convert a stream to a buffered data streamstatic DataInputStreamgetDataInput(File file) Create a buffered data stream from the filestatic DataInputStreamgetDataInput(String fileName) Create a buffered data stream from the filestatic DataInputStreamgetDataInput(Path path) Create a buffered data stream from the filestatic DataOutputStreamgetDataOutput(File file) Create a buffered data stream to write for the filestatic DataOutputStreamgetDataOutput(String fileName) Create a buffered data stream to write for the filestatic DataOutputStreamgetDataOutput(Path path) Create a buffered data stream to write for the pathstatic BufferedInputStreamCreate a buffered stream from the filestatic BufferedInputStreamCreate a buffered stream from the filestatic BufferedInputStreamCreate a buffered stream from the pathstatic BufferedOutputStreamCreate a buffered stream to write for the filestatic BufferedOutputStreamCreate a buffered stream to write for the filestatic BufferedOutputStreamCreate a buffered stream to write for the filestatic PathGet the path class for the file name passed.static BufferedReaderCreate a buffered reader from the filestatic BufferedReadergetReader(InputStream in) Convert a stream to a buffered UTF-8 readerstatic BufferedReaderCreate a buffered reader from the filestatic BufferedReaderCreate a buffered reader from the pathstatic BufferedWriterCreate a buffered writer to write for the filestatic BufferedWritergetWriter(OutputStream out) Convert a stream to a buffered UTF-8 writerstatic BufferedWriterCreate a buffered writer to write for the filestatic BufferedWriterCreate a buffered writer to write for the pathstatic InputStreamCreate a null input stream.static OutputStreamCreate a null output stream.static ByteBufferCreate a read only byte buffer from the content of the input stream.static OutputStreamtee(OutputStream first, OutputStream second) Create a Tee output stream that simultaneously writes content to 2 different output streams.
-
Constructor Details
-
IO
public IO()
-
-
Method Details
-
copy
Copy one stream to another. Both the streams will be closed.- Parameters:
input- Source streamoutput- Destination stream- Throws:
IOException- I/O exception
-
copy
Copy one stream to another. Both the streams will be closed.- Parameters:
input- Source streamoutput- Destination streambufferSize- Buffer size to use- Throws:
IOException- I/O exception
-
copy
Copy one stream to another- Parameters:
input- Source streamoutput- Destination streamclose- Whether to close the streams or not- Throws:
IOException- I/O exception
-
copy
public static void copy(InputStream input, OutputStream output, int bufferSize, boolean close) throws IOException Copy one stream to another- Parameters:
input- Source streamoutput- Destination streamclose- Whether to close the streams or not- Throws:
IOException- I/O exception
-
copy
Copy from reader to writer. Both reader and writer will be closed.- Parameters:
reader- Readerwriter- Writer- Throws:
IOException- I/O exception
-
copy
Copy from reader to writer. Both reader and writer will be closed.- Parameters:
reader- Readerwriter- Writerclose- Whether to close the reader/writer or not- Throws:
IOException- I/O exception
-
get
Convert a stream to a buffered stream- Parameters:
in- Stream to convert- Returns:
- Buffered stream
-
get
Convert a stream to a buffered stream- Parameters:
out- Stream to convert- Returns:
- Buffered stream
-
getReader
Convert a stream to a buffered UTF-8 reader- Parameters:
in- Stream to convert- Returns:
- Buffered reader
-
getWriter
Convert a stream to a buffered UTF-8 writer- Parameters:
out- Stream to convert- Returns:
- Buffered writer
-
get
Convert a reader to a buffered reader- Parameters:
in- Reader to convert- Returns:
- Buffered reader
-
get
Convert a writer to a buffered writer- Parameters:
out- Writer to convert- Returns:
- Buffered writer
-
getData
Convert a stream to a buffered data stream- Parameters:
in- Stream to convert- Returns:
- Buffered data stream
-
getData
Convert a stream to a buffered data stream- Parameters:
out- Stream to convert- Returns:
- Buffered data stream
-
getInput
Create a buffered stream from the file- Parameters:
fileName- Name of the file- Returns:
- Buffered stream
- Throws:
IOException- if I/O error occurs.
-
getPath
-
getInput
Create a buffered stream from the file- Parameters:
file- File- Returns:
- Buffered stream
- Throws:
IOException- if I/O error occurs.
-
getInput
Create a buffered stream from the path- Parameters:
path- Path- Returns:
- Buffered stream
- Throws:
IOException- if I/O error occurs.
-
getOutput
Create a buffered stream to write for the file- Parameters:
fileName- Name of the file- Returns:
- Buffered stream
- Throws:
IOException- if I/O error occurs.
-
getOutput
Create a buffered stream to write for the file- Parameters:
file- File- Returns:
- Buffered stream
- Throws:
IOException- if I/O error occurs.
-
getOutput
Create a buffered stream to write for the file- Parameters:
path- Path- Returns:
- Buffered stream
- Throws:
IOException- if I/O error occurs.
-
getDataInput
Create a buffered data stream from the file- Parameters:
fileName- Name of the file- Returns:
- Buffered stream
- Throws:
IOException- if I/O error occurs.
-
getDataInput
Create a buffered data stream from the file- Parameters:
file- File- Returns:
- Buffered stream
- Throws:
IOException- if I/O error occurs.
-
getDataInput
Create a buffered data stream from the file- Parameters:
path- Path- Returns:
- Buffered stream
- Throws:
IOException- if I/O error occurs.
-
getDataOutput
Create a buffered data stream to write for the file- Parameters:
fileName- Name of the file- Returns:
- Buffered stream
- Throws:
IOException- if I/O error occurs.
-
getDataOutput
Create a buffered data stream to write for the file- Parameters:
file- File- Returns:
- Buffered stream
- Throws:
IOException- if I/O error occurs.
-
getDataOutput
Create a buffered data stream to write for the path- Parameters:
path- Path- Returns:
- Buffered stream
- Throws:
IOException- if I/O error occurs.
-
getReader
Create a buffered reader from the file- Parameters:
fileName- Name of the file- Returns:
- Buffered reader
- Throws:
IOException- if I/O error occurs.
-
getReader
Create a buffered reader from the file- Parameters:
file- File- Returns:
- Buffered reader
- Throws:
IOException- if I/O error occurs.
-
getReader
Create a buffered reader from the path- Parameters:
path- Path- Returns:
- Buffered reader
- Throws:
IOException- if I/O error occurs.
-
getWriter
Create a buffered writer to write for the file- Parameters:
fileName- Name of the file- Returns:
- Buffered writer
- Throws:
IOException- if I/O error occurs.
-
getWriter
Create a buffered writer to write for the file- Parameters:
file- File- Returns:
- Buffered writer
- Throws:
IOException- if I/O error occurs.
-
getWriter
Create a buffered writer to write for the path- Parameters:
path- Path- Returns:
- Buffered writer
- Throws:
IOException- if I/O error occurs.
-
nullInput
Create a null input stream. A read from this stream always returns EOF (-1).- Returns:
- Null input stream
-
nullOutput
Create a null output stream. Anything written to this stream just disappears.- Returns:
- Null output stream
-
concat
Create a concatenated stream from the 2 streams. Data read from the resulting stream will be from the first stream and then, from the second stream when EOF is reached. One of the streams may benull.- Parameters:
in1- First stream.in2- Second stream.- Returns:
- Concatenated stream.
-
concat
Create a concatenated reader from the 2 readers. Data read from the resulting reader will be from the first one and then, from the second one when EOF is reached. One of the readers may benull.- Parameters:
reader1- First reader.reader2- Second reader.- Returns:
- Concatenated reader.
-
connect
Connect an output stream to an input stream so that the input stream is closed when the output stream is closed.- Parameters:
out- Output streamin- Input stream to connect to- Returns:
- Modified output stream
-
connect
Connect an input stream to an output stream so that the output stream is closed when the input stream is closed.- Parameters:
in- Input streamout- Output stream to connect to- Returns:
- Modified input stream
-
tee
Create a Tee output stream that simultaneously writes content to 2 different output streams.- Parameters:
first- First output streamsecond- Second output stream- Returns:
- An output stream that will write to 2 simultaneous streams.
-
readOnlyByteBuffer
Create a read only byte buffer from the content of the input stream.- Parameters:
in- Input stream- Returns:
- A read only byte buffer containing the content of the input stream.
- Throws:
IOException- if IO can not be happen.
-
byteBuffer
Create a read/write byte buffer from the content of the input stream.- Parameters:
in- Input stream- Returns:
- A read/write byte buffer containing the content of the input stream.
- Throws:
IOException- if buffer can not be created.
-
close
- Parameters:
closeables- Closable instances to close.
-