Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2005

Tip: Looking for answers? Try searching our database.

How to write a file header?

Thread view: 
Brian - 28 Sep 2005 18:06 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.