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 / General / October 2007

Tip: Looking for answers? Try searching our database.

How to use both ObjectStream and ByteArrayStream to access one file?

Thread view: 
ZelluX - 24 Oct 2007 12:59 GMT
Hello, I want to write a simple Zip compression and decompression tool
in Java.

Now I'm confronted with a problem,
i store compression infomation in a serializable HuffmanTree, and use
ObjectOutputStream to write the whole tree in a binary file, after
that, i append compressed bytes to the end of the file.

When decompressing, how can i first get the HuffmanTree out of the
file and then read compressed bytes from the file?

Or any better solution to this problem?

Many thanks.
Roedy Green - 24 Oct 2007 13:08 GMT
>When decompressing, how can i first get the HuffmanTree out of the
>file and then read compressed bytes from the file?

ask the file I/O amanuensis to generate you some code.
Just tick off "read", "compressed", "serialised binary objects"

see http://mindprod.com/applet/fileio.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

ZelluX - 24 Oct 2007 13:44 GMT
On 10 24 ,   8 08 , Roedy Green <see_webs...@mindprod.com.invalid>
wrote:

> >When decompressing, how can i first get the HuffmanTree out of the
> >file and then read compressed bytes from the file?
[quoted text clipped - 6 lines]
> Roedy Green Canadian Mind Products
> The Java Glossaryhttp://mindprod.com

Thanks for that.

But what if i want to write the compression code myself?
then how to store both the tree and the compressed infomation in a
file?
bcr666 - 24 Oct 2007 15:48 GMT
> On 10 24 ,   8 08 , Roedy Green <see_webs...@mindprod.com.invalid>
> wrote:
[quoted text clipped - 15 lines]
> then how to store both the tree and the compressed infomation in a
> file?

I would just make the compressed information a Serializable Object,
then just write it to the ObjectOutputStream after the tree.
Roedy Green - 24 Oct 2007 20:52 GMT
>But what if i want to write the compression code myself?
>then how to store both the tree and the compressed infomation in a
>file?

You use that code as a model.  You write your own class to replace the
GZIP.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Gordon Beaton - 24 Oct 2007 16:18 GMT
> Now I'm confronted with a problem, i store compression infomation in
> a serializable HuffmanTree, and use ObjectOutputStream to write the
> whole tree in a binary file, after that, i append compressed bytes
> to the end of the file.

It will hurt when you do that. Don't.

Store either both as serialized Objects or both as "bytes" in the
file, don't try to be too clever. Read Thing 1 and Thing 2 from the
file using one kind of stream, and separate them in your code.

/gordon

--


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.