Package org.forgerock.http.io
Class FileBranchingStream
- java.lang.Object
-
- java.io.InputStream
-
- org.forgerock.http.io.BranchingInputStream
-
- org.forgerock.http.io.FileBranchingStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public final class FileBranchingStream extends BranchingInputStream
ABranchingInputStream
for reading from files. Uses aFileInputStream
to read from the file, but tracks the position read to so that branches can skip to the same location.This stream would be most suited for when a large file is expected to piped straight to output, without modification and minimal branching. If the stream is not a large file, is going to be modified by filters, or is going to have substantial branching, a wrapper
BranchingInputStream
could be considered instead.
-
-
Constructor Summary
Constructors Constructor Description FileBranchingStream(File file)
Creates a new stream for the specified file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BranchingInputStream
branch()
Creates a new branch at this stream's current position.void
close()
Closes this branching stream and all of the branches created from it.BranchingInputStream
copy()
Creates a twin of this stream at this stream's current position.int
read()
-
Methods inherited from class org.forgerock.http.io.BranchingInputStream
parent
-
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
-
-
-
Constructor Detail
-
FileBranchingStream
public FileBranchingStream(File file) throws FileNotFoundException
Creates a new stream for the specified file.- Parameters:
file
- The file to read from.- Throws:
FileNotFoundException
- If the file does not exist.
-
-
Method Detail
-
branch
public BranchingInputStream branch() throws IOException
Description copied from class:BranchingInputStream
Creates a new branch at this stream's current position. The returned stream will have this stream as its parent.- Specified by:
branch
in classBranchingInputStream
- Returns:
- a new branching stream, in the same position as this branch.
- Throws:
IOException
- if an I/O exception occurs.
-
copy
public BranchingInputStream copy() throws IOException
Description copied from class:BranchingInputStream
Creates a twin of this stream at this stream's current position. The returned stream will have the same parent as this stream.- Specified by:
copy
in classBranchingInputStream
- Returns:
- a new twin stream, in the same position as this branch.
- Throws:
IOException
- if an I/O exception occurs.
-
read
public int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
close
public void close() throws IOException
Description copied from class:BranchingInputStream
Closes this branching stream and all of the branches created from it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classBranchingInputStream
- Throws:
IOException
- if an I/O exception occurs.
-
-