jas.util
Class FileReaderWithProgressBar

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FileInputStream
          extended by jas.util.FileReaderWithProgressBar
All Implemented Interfaces:
Closeable

public class FileReaderWithProgressBar
extends FileInputStream

This class should be used when you want to have a BoundedRangeModel display the progress as a file is being opened. The model is updated with each call to read, so it is ideally used in a BufferedReader where the stream is read in buffer-sized amounts. That way, the model updates only when the buffer is filled. For example, you might use it like this:
BufferedReader input = new BufferedReader(new InputStreamReader(new FileReaderWithProgressBar(name, model)));

Author:
Jonas Gifford
See Also:
BoundedRangeModel, BufferedReader, InputStreamReader

Constructor Summary
FileReaderWithProgressBar(String fileName, BoundedRangeModel model)
          Creates a new FileReaderWithProgressBar.
 
Method Summary
 int read()
          Works just like the equivalent method in FileInputStream, except that it updates the model to reflect the progress in reading the file.
 int read(byte[] cbuf)
          Works just like the equivalent method in FileInputStream, except that it updates the model to reflect the progress in reading the file.
 int read(byte[] cbuf, int off, int len)
          Works just like the equivalent method in FileInputStream, except that it updates the model to reflect the progress in reading the file.
 long skip(long n)
          Works just like the equivalent method in FileInputStream, except that it updates the model to reflect the progress in reading the file.
 
Methods inherited from class java.io.FileInputStream
available, close, finalize, getChannel, getFD
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileReaderWithProgressBar

public FileReaderWithProgressBar(String fileName,
                                 BoundedRangeModel model)
                          throws FileNotFoundException
Creates a new FileReaderWithProgressBar.

Parameters:
fileName - the file to read
model - the BoundedRangeModel to update
Throws:
FileNotFoundException - thrown from the constructor of FileInputStream
See Also:
BoundedRangeModel
Method Detail

read

public int read()
         throws IOException
Works just like the equivalent method in FileInputStream, except that it updates the model to reflect the progress in reading the file.

Overrides:
read in class FileInputStream
Throws:
IOException
See Also:
FileInputStream, FileInputStream.read()

read

public int read(byte[] cbuf)
         throws IOException
Works just like the equivalent method in FileInputStream, except that it updates the model to reflect the progress in reading the file.

Overrides:
read in class FileInputStream
Throws:
IOException
See Also:
FileInputStream, FileInputStream.read(byte[])

read

public int read(byte[] cbuf,
                int off,
                int len)
         throws IOException
Works just like the equivalent method in FileInputStream, except that it updates the model to reflect the progress in reading the file.

Overrides:
read in class FileInputStream
Throws:
IOException
See Also:
FileInputStream, FileInputStream.read(byte[], int, int)

skip

public long skip(long n)
          throws IOException
Works just like the equivalent method in FileInputStream, except that it updates the model to reflect the progress in reading the file.

Overrides:
skip in class FileInputStream
Throws:
IOException
See Also:
FileInputStream, FileInputStream.skip(long)


Copyright © 2000-2009 FreeHEP. All Rights Reserved.