1 package be
.nikiroo
.utils
.streams
;
4 import java
.io
.FileInputStream
;
5 import java
.io
.FileNotFoundException
;
6 import java
.io
.FilterInputStream
;
7 import java
.io
.IOException
;
8 import java
.nio
.channels
.FileChannel
;
11 * This is a markable (and thus reset-able) stream that you can create from a
16 public class MarkableFileInputStream
extends FilterInputStream
{
17 private FileChannel channel
;
18 private long mark
= 0;
21 * Create a new {@link MarkableFileInputStream} from this file.
24 * the {@link File} to wrap
26 * @throws FileNotFoundException
27 * if the {@link File} cannot be found
29 public MarkableFileInputStream(File file
) throws FileNotFoundException
{
30 this(new FileInputStream(file
));
34 * Create a new {@link MarkableFileInputStream} from this stream.
37 * the original {@link FileInputStream} to wrap
39 public MarkableFileInputStream(FileInputStream in
) {
41 channel
= in
.getChannel();
45 public boolean markSupported() {
50 public synchronized void mark(int readlimit
) {
52 mark
= channel
.position();
53 } catch (IOException ex
) {
60 public synchronized void reset() throws IOException
{
62 throw new IOException("mark position not valid");
64 channel
.position(mark
);