I was wondering if you guys can clear up a few questions for me concering how data is stored.

1. If I have a txt file that is 78,390 bytes long. If I wish to view and manipulate the raw binary data, I have to convert byte data into binary data and then write the binary data to a txt file. This binary data txt file is 8 times larger than the orignal txt file. Is there a way to have access and/or manipulate the original txt file's binary data without having to write it to a file?

2. The previous is a compression related question, so I was also wondering if anyone can explain the principle upon which winZip or winRar work? How do these programs compress the data to a smaller size? What level of access do they have to the file they are compressing?

Edit: I have found an article on the Huffman Compression algorithm and have answered the second question myself. I am still interested in how I can access the data on that level with Java though. I have found a java applet that shows the process, but it doesnt actually write the compressed file.

I was wondering if you guys can clear up a few questions for me concering how data is stored.

1. If I have a txt file that is 78,390 bytes long. If I wish to view and manipulate the raw binary data, I have to convert byte data into binary data and then write the binary data to a txt file. This binary data txt file is 8 times larger than the orignal txt file.

Im not sure I udnerstand this. Do you mena to say youa re taking each bit sequentially in the file and writing it out as a 0 or 1 valued byte?

If so why?

Quote

2. The previous is a compression related question, so I was also wondering if anyone can explain the principle upon which winZip or winRar work? How do these programs compress the data to a smaller size? What level of access do they have to the file they are compressing?

Edit: I have found an article on the Huffman Compression algorithm and have answered the second question myself. I am still interested in how I can access the data on that level with Java though. I have found a java applet that shows the process, but it doesnt actually write the compressed file.

Well, huffman is just oen of many compression schemes and a failry simple on.

But if yopu want to work with Zip style comrepssed fiels in Java the ehavy lifting is all done for you by Zip* classes (ZipFile, ZipInputStream and ZipOutputStream). A ncie Java feature.

Any answers to these questions are greatly appreciated.[/quote]

Got a question about Java and game programming? Just new to the Java Game Development Community? Try my FAQ. Its likely you'll learn something!

Well my point of confusion is that if I take a txt file and run a Huffman algorith on it, How would I write the compressed binary back to a smaller file? Just convert it back into text (it would be all jumpbled of course)?

Well my point of confusion is that if I take a txt file and run a Huffman algorith on it, How would I write the compressed binary back to a smaller file? Just convert it back into text (it would be all jumpbled of course)?

How is your binary data stored in the program? In a byte array, char array??

If each element in your array represents 1 bit you should pack it into bytes before writing to the output file.

This code packs the the data from an array of ints (with values 0 or 1) into bytes and writes them to a file.

Well my point of confusion is that if I take a txt file and run a Huffman algorith on it, How would I write the compressed binary back to a smaller file? Just convert it back into text (it would be all jumpbled of course)?

As the man says, it is totally dependant on how the data is stored and what exactly you are "huffman-ing."

If your goal is to reduce individual bytes down to sub-byte strinsg of bits (less then 8 bits per symbol) then you need to byte pack it or you will get no benefit.

That seems fairly obvious, so myabe Im missing something?

Got a question about Java and game programming? Just new to the Java Game Development Community? Try my FAQ. Its likely you'll learn something!

Oh! Well if you are trying to learn about compression, might I suggestyou google "LZW"?

Lempel/Ziff is well documented. Unfortunately its also patented so you can't use it in a product without a lciense (Unisys's terms actually used to be pretty reasonable. They'd give youa fre elicense for free stuff and charge you for comemrical use.)

Its quite aways beyond a simple huffman, though not so far that i think yould have any problems grapsing it. I actually wrote an LZW decomrepssor in Java years ago in order to read PDF files, which use it.

Got a question about Java and game programming? Just new to the Java Game Development Community? Try my FAQ. Its likely you'll learn something!

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org