Results 1 to 3 of 3
- 10-28-2010, 01:48 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 32
- Rep Power
- 0
How do I write bits to a file( for Huffman Tree compressing)
My current program just creates the tree and prints out the character along with the shortened code. This of course is much longer than the original file.
"the" => "101000100" or something like that.
I'm not sure what the next step is though, FileOutputStream can write bytes to a file...but I don't think you can actually control it...
out = FileOutputStream (file)
if (next char is equal to "e")
out.write("0")
if (next char is equal to "z")
out.write("101101010")
?
- 10-28-2010, 05:02 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
I notice that the API docs for OutputStream says "This abstract class is the superclass of all classes representing an output stream of bytes. An output stream accepts output bytes and sends them to some sink." So it seems to be byte centric.
You could write your own OutputStream subclass that allows writing bits. It might wrap an OutputStream and provide a new method to write bits. That method would add the bits to a buffer and write bytes as soon as it had a byte-full of bits. There have to be methods to close() and flush() that the user would have to call to ensure that the last few bits were written correctly.
A bit capable InputStream would also seem to be called for - just the reverse, I guess: read whole bytes and buffer them returning individual bits on demand.
- 10-28-2010, 10:45 AM #3
Member
- Join Date
- Jan 2010
- Posts
- 32
- Rep Power
- 0
Similar Threads
-
Help with random bits array
By AnimeKitty in forum New To JavaReplies: 11Last Post: 07-30-2010, 04:37 AM -
how to change the layout of an input file and write to an output file
By renu in forum New To JavaReplies: 8Last Post: 05-12-2010, 07:19 PM -
48 bits JPEG 2000
By user_java in forum Java 2DReplies: 0Last Post: 03-02-2010, 05:19 AM -
BufferedInputStream with Huffman Compression
By Msnforum in forum New To JavaReplies: 0Last Post: 11-03-2009, 09:04 PM -
extracting bits from big numbers
By ankitmcgill in forum New To JavaReplies: 6Last Post: 05-05-2009, 04:36 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks