Skip to content

Commit

Permalink
Adding Everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Glank committed Jun 28, 2012
1 parent dbeea45 commit 5d6ef7e
Show file tree
Hide file tree
Showing 41 changed files with 69,080 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .classpath
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions .project
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Compression</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,12 @@
#Tue Jun 26 16:51:28 EDT 2012
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
Binary file added Bible.cmp
Binary file not shown.
33,979 changes: 33,979 additions & 0 deletions Bible.txt

Large diffs are not rendered by default.

33,979 changes: 33,979 additions & 0 deletions Bible_2.txt

Large diffs are not rendered by default.

Binary file added bin/Tests.class
Binary file not shown.
Binary file added bin/huffman/HList.class
Binary file not shown.
Binary file added bin/huffman/HNode.class
Binary file not shown.
Binary file added bin/huffman/HRepresentation.class
Binary file not shown.
Binary file added bin/huffman/HTree.class
Binary file not shown.
Binary file added bin/huffman/HTreeIOFactory.class
Binary file not shown.
Binary file added bin/huffman/HuffmanCompressor.class
Binary file not shown.
Binary file added bin/io/BitIOFactory.class
Binary file not shown.
Binary file added bin/io/BitInputStream.class
Binary file not shown.
Binary file added bin/io/BitOutputStream.class
Binary file not shown.
Binary file added bin/io/ByteIOFactory.class
Binary file not shown.
Binary file added bin/util/BSTIterator.class
Binary file not shown.
Binary file added bin/util/BSTNode.class
Binary file not shown.
Binary file added bin/util/BinarySortedTree.class
Binary file not shown.
Binary file added bin/util/ByteIterableArrayWrapper$1.class
Binary file not shown.
Binary file added bin/util/ByteIterableArrayWrapper.class
Binary file not shown.
Binary file added bin/util/IterableArrayWrapper$1.class
Binary file not shown.
Binary file added bin/util/IterableArrayWrapper.class
Binary file not shown.
226 changes: 226 additions & 0 deletions src/Tests.java
@@ -0,0 +1,226 @@
import huffman.HList;
import huffman.HNode;
import huffman.HTree;
import huffman.HTreeIOFactory;
import huffman.HuffmanCompressor;
import io.BitInputStream;
import io.BitOutputStream;
import io.ByteIOFactory;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableSet;

import util.BinarySortedTree;

//0010 0001 = !
public class Tests {
/*
public static void main(String[] args)throws Throwable{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(new File("Bible.txt"));
int read;
while((read=fis.read())!=-1)
baos.write(read);
fis.close();
byte[] bytes = baos.toByteArray();
baos.close();
fis = null;
baos = null;
System.out.println("Creating list...");
HList<Byte> list = new HList<Byte>();
for(byte b:bytes)
list.add(b);
System.out.println("Created List");
System.out.println("Making tree...");
HTree<Byte> tree = new HTree<Byte>(list.getAll());
System.out.println("____Old Tree____");
tree.getRoot().print();
HTreeIOFactory<Byte> factory = new HTreeIOFactory<Byte>(new ByteIOFactory());
FileOutputStream fos = new FileOutputStream("testTreeSave.dat");
factory.write(tree, new BitOutputStream(fos));
fos.close();
fis = new FileInputStream("testTreeSave.dat");
tree = factory.read(new BitInputStream(fis));
System.out.println("____New Tree____");
tree.getRoot().print();
}
//*/
//* Decompress
public static void main(String[] args) throws Throwable{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(new File("Bible.cmp"));
int read;
while((read=fis.read())!=-1)
baos.write(read);
fis.close();
byte[] bytes = baos.toByteArray();
baos.close();
fis = null;
baos = null;
System.out.println("Starting decompression...");
Iterable<Byte> data = HuffmanCompressor.decompress(bytes);
System.out.println("Finished decompression.");
FileOutputStream fos = new FileOutputStream(new File("Bible_2.txt"));
for(Byte b:data){
fos.write(b);
}
fos.flush();
fos.close();
}
//*/
/* Compress
public static void main(String[] args) throws Throwable{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(new File("Bible.txt"));
int read;
while((read=fis.read())!=-1)
baos.write(read);
fis.close();
byte[] bytes = baos.toByteArray();
baos.close();
fis = null;
baos = null;
System.out.println("Starting compression...");
bytes = HuffmanCompressor.compress(bytes);
System.out.println("Finished compression.");
FileOutputStream fos = new FileOutputStream(new File("Bible.cmp"));
fos.write(bytes);
fos.flush();
fos.close();
}
//*/
/*
public static void main(String[] args) throws Throwable{
HList<Character> list = new HList<Character>();
String str = "j'aime aller sur le bord de l'eau les jeudis ou les jours impairs";
for(char c:str.toCharArray())
list.add(c);
for(HNode<Character> n:list.getAll())
System.out.println(n);
HTree<Character> tree = new HTree<Character>(list.getAll());
list = null;
tree.getRoot().print();
Map<Character, boolean[]> map = tree.compileWritingMap();
for(Entry<Character, boolean[]> e:map.entrySet()){
System.out.print(e.getKey()+": ");
print(e.getValue());
}
}
public static void print(boolean[] binary){
for(int i = 0; i<binary.length; i++)
if(binary[i])
System.out.print("1");
else
System.out.print("0");
System.out.println();
}
//*/
/*
public static void main(String[] args) throws Throwable{
BinarySortedTree<Integer> tree = new BinarySortedTree<Integer>();
tree.add(5);
tree.add(6);
tree.add(2);
tree.add(4);
tree.add(4);
tree.add(3);
for(Integer i:tree)
System.out.println(i);
System.out.println();
tree.treePrint();
System.out.println();
while(tree.size()>0){
System.out.println("Removing: " + tree.pollFirst());
System.out.println();
for(Integer i:tree)
System.out.println(i);
System.out.println();
tree.treePrint();
System.out.println();
}
}
//*/
/*
public static void main(String[] args) throws Throwable{
HList<Byte> list = new HList<Byte>();
list.add((byte)3);
list.add((byte)8);
list.add((byte)7);
list.add((byte)3);
list.add((byte)7);
list.add((byte)7);
NavigableSet<HNode<Byte>> nodes = list.getAll();
for(HNode<Byte> b:nodes)
System.out.println(b.symbol + ": " + b.count);
}
//*/
/*
public static void main(String[] args) throws Throwable{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BitOutputStream bos = new BitOutputStream(baos);
bos.write(false);
bos.write(false);
bos.write(true);
bos.write(false);
bos.write(18);
bos.write(false);
bos.write(false);
bos.write(false);
bos.write(true);
bos.close();
byte[] bytes = baos.toByteArray();
for(byte b:bytes)
System.out.println(b);
}
//*/
/*
public static void main(String[] args) throws Throwable{
ByteArrayInputStream bais = new ByteArrayInputStream(new byte[]{7});
BitInputStream bis = new BitInputStream(bais);
Boolean bit;
int i = 0;
while((bit=bis.readBit())!=null){
if(bit)
System.out.print(1);
else
System.out.print(0);
i++;
if(i%8==0)
System.out.println();
}
}
//*/
/*
public static void main(String[] args) throws Throwable{
FileInputStream fis = new FileInputStream(new File("test.txt"));
BitInputStream bis = new BitInputStream(fis);
FileOutputStream fos = new FileOutputStream(new File("test2.txt"));
BitOutputStream bos = new BitOutputStream(fos);
Boolean bit;
int i = 0;
while((bit=bis.readBit())!=null){
if(bit)
System.out.print(1);
else
System.out.print(0);
i++;
if(i%8==0)
System.out.println();
bos.write(bit);
}
bos.flush();
bos.close();
}
//*/
}
34 changes: 34 additions & 0 deletions src/huffman/HList.java
@@ -0,0 +1,34 @@
package huffman;

import java.util.HashMap;
import java.util.Map.Entry;

import util.BinarySortedTree;

public class HList<S>{
private HashMap<S, HNode<S>> map;

public HList(){
map = new HashMap<S, HNode<S>>();
}

public void add(S symbol){
HNode<S> node = map.get(symbol);
if(node==null){
node = new HNode<S>(symbol);
map.put(symbol, node);
}
else
node.increment();
}

public BinarySortedTree<HNode<S>> getAll(){
BinarySortedTree<HNode<S>> set = new BinarySortedTree<HNode<S>>();
for(Entry<S,HNode<S>> e:map.entrySet()){
set.add(e.getValue());
}
return set;
}


}

0 comments on commit 5d6ef7e

Please sign in to comment.