I see that RandomAccessFile has getFilePointer(), but don't see how to make
use of this in an InputStream or Reader, without defining my own Reader to
operate on a RandomAccessFile.
I also see InputStream.available(), which _might_ return the offset from the
end of the file (though this is not specified explicitly), but it returns an
int rather than a long -- so it couldn't return all offsets from the end of
a really large file.
My goal is to show the progress of reading a large file. I can find the
total length of the file in bytes with File.length(), and the current offset
in lines with a LineNumberReader, but don't know how to find (efficiently)
the current offset in bytes or the total number of lines.
============================================================================
Andrew R. Thomas-Cramer
Home: ar...@execpc.com http://www.execpc.com/~artc/
Work: ar...@prism-cs.com 608.287.1043
============================================================================
InputStream and Reader are designed to be used in a stream of indefinite
or undefined length, so they do not have a concept of 'percentage
complete'. They also dont have a byte counter (of bytes read), probably
just because no-one considered it important enough to include in the spec.
: I see that RandomAccessFile has getFilePointer(), but don't see how to make
: use of this in an InputStream or Reader, without defining my own Reader to
: operate on a RandomAccessFile.
:
: I also see InputStream.available(), which _might_ return the offset from the
: end of the file (though this is not specified explicitly), but it returns an
: int rather than a long -- so it couldn't return all offsets from the end of
: a really large file.
available() will return the number of bytes ready to be read. Typically,
this is the number of bytes in the input buffer which you have not read.
: My goal is to show the progress of reading a large file. I can find the
: total length of the file in bytes with File.length(), and the current offset
: in lines with a LineNumberReader, but don't know how to find (efficiently)
: the current offset in bytes or the total number of lines.
I think you have found all there is to find. Implement a counter which
counts the number of bytes you have read so far and compare that with
File.length().
For fairly obvious reasons, you cant know the number of lines until after
the last line has been read.
Brian.