473,382 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Java - Problems with the Huffman Algorithm Output

Hello everyone,

I'm trying to make a compression application using the Huffman Algorithm but i'm not sure on how to write to a file the output.

I have a binary sequence associated to every character in the input file.

Now the problem is:
- I create a binary string based on the input file.
- Then I have to write the compressed file, but I have no idea on how to work with my binary string.

(the binary string is something like:
String binaryString = "011110110"

any help would be appreciated

Thanks,

Stephane
Sep 26 '07 #1
3 2721
JosAH
11,448 Expert 8TB
Hello everyone,

I'm trying to make a compression application using the Huffman Algorithm but i'm not sure on how to write to a file the output.

I have a binary sequence associated to every character in the input file.

Now the problem is:
- I create a binary string based on the input file.
- Then I have to write the compressed file, but I have no idea on how to work with my binary string.

(the binary string is something like:
String binaryString = "011110110"

any help would be appreciated

Thanks,

Stephane
That's not a 'binary String' that's a String that just consists of the characters '1'
and '0'. If you group eight of these characters together you can convert them to
a byte and write that byte to the OutputStream. Keep on repeating that until you've
written your entire String.

This raises the question: what do you need that String for to begin with?

kind regards,

Jos
Sep 26 '07 #2
That's not a 'binary String' that's a String that just consists of the characters '1'
and '0'. If you group eight of these characters together you can convert them to
a byte and write that byte to the OutputStream. Keep on repeating that until you've
written your entire String.

This raises the question: what do you need that String for to begin with?

kind regards,

Jos
Instead of going throught the tree the whole time, i've created a conversion Hashtable where you call .get(char) and that returns the associated "(not)binary string"

Thanks for your help still :)
Sep 26 '07 #3
Instead of going throught the tree the whole time, i've created a conversion Hashtable where you call .get(char) and that returns the associated "(not)binary string"

Thanks for your help still :)
Having a small problem with the byte conversion still ...

while((readedCharacter ) != EOFChar)
{
binaryString += this.correspondance.get(readedCharacter);
if(binaryString.length() >=8)
{
String subString = binaryString.substring(0, 8);
binaryString = binaryString.substring(8);
Byte convertedString = new Byte(subString);
out.write(convertedString);
out.flush();
}

readedCharacter = (char)dis.read();
}

I'm getting the following exception when trying to convert the string to a byte

Exception in thread "main" java.lang.NumberFormatException: Value out of range. Value:"11111111" Radix:10
Sep 26 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
8
by: dirgesh | last post by:
I am having a hard time making a Program in C/C++ that uses the Huffman Compression to compress a file. I have a file "Hello World" That i need to compress. can someone please give me an...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
4
by: A_StClaire_ | last post by:
hi all, I'm trying to implement Huffman coding on letters of a string. I've written functions to define the initial leaf nodes (letters and their frequencies) and to sort them. I've also put...
3
by: AHanso | last post by:
Hey I am new to C# (My background is in Java), I am writing a C# application (that uses the Compact Framework) that communicates to a Java server. To login the server is expecting the password...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
3
by: Udhay | last post by:
Sir, I am udhay. I am a student and i am working on Audio compression for my exam. I want to know how does the compression take place in audio?? Can anyone suggest a link for the novice to...
7
realin
by: realin | last post by:
hi guys, This is my first post in Java section, well i am a newbie in java and now i have started to actually program in java after php,c++ after two months i have to give my final year's...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.