⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reader.java

📁 基于哈夫曼树的压缩解压程序源代码
💻 JAVA
字号:
package logical;

import java.io.*;

//Read the file and get the huffman tree
public class Reader {
	private long[] weight = new long[256];

	// Cause the numbers are between 0 and 255, we use an long array "weight" to
	// store the weight of the node
	private String textName;// Get the name of the file

	private Node[] tree;
	private String[] codes;

	Reader(String textName) throws IOException {
		this.textName = textName;
		// Get the content of the file
		BufferedInputStream input = new BufferedInputStream(
				new FileInputStream(textName));
		int temp;
		while ((temp = input.read()) != -1) {
			weight[temp]++;// Count the weight of all the node
		}
		input.close();
		// According to the weights of all the node to
		// construct the huffman tree
		HuffmanTree huff = new HuffmanTree(weight);

		codes = huff.getCode();
		tree = huff.getTree();
	}

	// Set the name of the file which needs to be read
	public void setTextName(String textName) {
		this.textName = textName;
	}

	// Get the name of the file which needs to be read
	public String getTextName() {
		return textName;
	}

	// Get the weight of all bytes which are between 0 and 255
	public long[] getweight() {
		return weight;
	}

	// Get the huffmantree 
	public Node[] getHuffmanTree() {
		return tree;
	}
	// Get the huffmancode
	public String[] getHuffmanCode() {
		return codes;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -