Hi -
I'm trying to write a file with a description/header at the front.
The header can't be calculated until all the bytes are written.
So far, I write a dummy header just to consume the space. Then
I write the actual file. I'm stuck on how to backup the file
pointer to the beginning to write the actual header.
What's worse is that by the time I'm writing, I'm inside a
FilterOutputStream object. So I don't have access to the
original file.
Any ideas?
Thanks!
jessu - 28 Sep 2005 18:37 GMT
Have you tried RandomAccessFile? It allows you to seek to any location
and write there.
-----------
FeedFeeds : A new way to read news and blogs!
http://www.feedfeeds.com
Brian - 28 Sep 2005 18:40 GMT
> Have you tried RandomAccessFile? It allows you to seek to any location
> and write there.
Yeah, that occurred to me searching around in google. But I'm
already in my extended FilterStreamClass at that point and have
no way to call the RandomAccessFile methods.
Actually, it just occured to me. I probably extended the wrong
class. I should probably write a File-like class that either
extends or includes a RandomAccessFile, then put the header stuff
in there.
Thanks for the reply.
Andrey Kuznetsov - 28 Sep 2005 19:37 GMT
> I'm trying to write a file with a description/header at the front.
> The header can't be calculated until all the bytes are written.
[quoted text clipped - 6 lines]
> FilterOutputStream object. So I don't have access to the
> original file.
Take a look at UnifiedIO (http://uio.imagero.com), it gives you random
access to anything.
Cheers
Andrey

Signature
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Roedy Green - 28 Sep 2005 23:30 GMT
>What's worse is that by the time I'm writing, I'm inside a
>FilterOutputStream object. So I don't have access to the
>original file.
One way to do it is close the file, then open a RandomAccessFile to
plop it in. see http://mindprod.com/applets/fileio.html for details.
Another is to buffer stuff after the header in ram or another file
until you know enough to write the header.
Another is to write the header and file is separate files, and in
script language, concatenate the files when you are done.
Another is to change rules so you use two files instead of one.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
Andrey Kuznetsov - 29 Sep 2005 10:00 GMT
> Another is to buffer stuff after the header in ram or another file
> until you know enough to write the header.
UnifiedIO makes it for you.

Signature
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities