Results 1 to 3 of 3
  1. #1
    ryuzog is offline Member
    Join Date
    Jan 2010
    Rep Power

    Default 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")
    if (next char is equal to "z")

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power


    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.

  3. #3
    ryuzog is offline Member
    Join Date
    Jan 2010
    Rep Power

Similar Threads

  1. Help with random bits array
    By AnimeKitty in forum New To Java
    Replies: 11
    Last Post: 07-30-2010, 05:37 AM
  2. Replies: 8
    Last Post: 05-12-2010, 08:19 PM
  3. 48 bits JPEG 2000
    By user_java in forum Java 2D
    Replies: 0
    Last Post: 03-02-2010, 06:19 AM
  4. BufferedInputStream with Huffman Compression
    By Msnforum in forum New To Java
    Replies: 0
    Last Post: 11-03-2009, 10:04 PM
  5. extracting bits from big numbers
    By ankitmcgill in forum New To Java
    Replies: 6
    Last Post: 05-05-2009, 05:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts