Skip to content

Commit 2d9e0e5

Browse files
committed
chore: Renaming
1 parent 8204004 commit 2d9e0e5

File tree

7 files changed

+46
-50
lines changed

7 files changed

+46
-50
lines changed

src/main/java/prog/huffman/HuffmanCompressor.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ public int compareTo(HuffmanNode other) {
4545
/*******************************************************************************
4646
* calculating frequence of file filename
4747
******************************************************************************/
48-
49-
public static void calculateFrequency(String filename) {
50-
File file = null;
48+
public static void calculateFrequencyOfBytesInFile(String filename) {
49+
File file = new File(filename);;
5150
Byte currentByte;
52-
53-
file = new File(filename);
5451
try {
5552
FileInputStream file_input = new FileInputStream(file);
5653
DataInputStream data_in = new DataInputStream(file_input);
@@ -69,7 +66,6 @@ public static void calculateFrequency(String filename) {
6966
} catch (IOException e) {
7067
System.out.println("IO Exception =: " + e);
7168
}
72-
file = null;
7369
}
7470

7571
/************************************** ============ ************************/
@@ -346,7 +342,7 @@ public static void realzip(String filename, String filename1) {
346342

347343
public static void beginHuffmanCompression(String arg1) {
348344
initHuffmanCompressor();
349-
calculateFrequency(arg1); // calculate the frequency of each digit
345+
calculateFrequencyOfBytesInFile(arg1); // calculate the frequency of each digit
350346
buildHuffmanTree(); // build huffman tree from frequencies
351347
if (uniqueCharCount > 1)
352348
generateHuffmanCodes(root, ""); // dfs to make the codes

src/main/java/prog/huffman/HuffmanDecompressor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ public static void readbin(String zip, String unz) {
270270
f1 = new File(zip);
271271
f2 = new File(unz);
272272
try {
273-
FileOutputStream file_output = new FileOutputStream(f2);
274-
DataOutputStream data_out = new DataOutputStream(file_output);
273+
FileOutputStream fileOutput = new FileOutputStream(f2);
274+
DataOutputStream dataOut = new DataOutputStream(fileOutput);
275275
FileInputStream file_input = new FileInputStream(f1);
276276
DataInputStream data_in = new DataInputStream(file_input);
277277
try {
@@ -305,7 +305,7 @@ public static void readbin(String zip, String unz) {
305305
tempCode += bitBuffer.charAt(i);
306306
// System.out.println(tempCode);
307307
if (got() == 1) {
308-
data_out.write(decodedByte);
308+
dataOut.write(decodedByte);
309309
ok = 0;
310310
String s = "";
311311
for (j = tempCode.length(); j < bitBuffer.length(); j++) {
@@ -324,8 +324,8 @@ public static void readbin(String zip, String unz) {
324324
break;
325325
}
326326
}
327-
file_output.close();
328-
data_out.close();
327+
fileOutput.close();
328+
dataOut.close();
329329
file_input.close();
330330
data_in.close();
331331
} catch (IOException e) {

src/main/java/prog/lzw/LzwCompressor.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ public static void calculateBitSize(String filename) {
9090
filei = new File(filename);
9191

9292
try {
93-
FileInputStream file_inputut = new FileInputStream(filei);
94-
DataInputStream data_in = new DataInputStream(file_inputut);
93+
FileInputStream fileInput = new FileInputStream(filei);
94+
DataInputStream dataIn = new DataInputStream(fileInput);
9595

9696
Byte c;
9797
int ch;
9898
while (true) {
9999
try {
100-
c = data_in.readByte();
100+
c = dataIn.readByte();
101101
ch = CommonUtil.byteToUnsignedInt(c);
102102
String wc = w + (char) ch;
103103
if (dictionary.containsKey(wc))
@@ -114,8 +114,8 @@ public static void calculateBitSize(String filename) {
114114
break;
115115
}
116116
}
117-
file_inputut.close();
118-
data_in.close();
117+
fileInput.close();
118+
dataIn.close();
119119
} catch (IOException e) {
120120
System.out.println("IO exception = " + e);
121121
}
@@ -160,17 +160,17 @@ public static void compressFile(String filename) {
160160
fileo = new File(fileos);
161161

162162
try {
163-
FileInputStream file_inputut = new FileInputStream(filei);
164-
DataInputStream data_in = new DataInputStream(file_inputut);
165-
FileOutputStream file_output = new FileOutputStream(fileo);
166-
DataOutputStream data_out = new DataOutputStream(file_output);
163+
FileInputStream fileInput = new FileInputStream(filei);
164+
DataInputStream dataIn = new DataInputStream(fileInput);
165+
FileOutputStream fileOutput = new FileOutputStream(fileo);
166+
DataOutputStream dataOut = new DataOutputStream(fileOutput);
167167

168-
data_out.writeInt(bitSize);
168+
dataOut.writeInt(bitSize);
169169
Byte c;
170170
int ch;
171171
while (true) {
172172
try {
173-
c = data_in.readByte();
173+
c = dataIn.readByte();
174174
ch = CommonUtil.byteToUnsignedInt(c);
175175

176176
String wc = w + (char) ch;
@@ -179,7 +179,7 @@ public static void compressFile(String filename) {
179179
else {
180180
bitBuffer += intToBinaryString(dictionary.get(w));
181181
while (bitBuffer.length() >= 8) {
182-
data_out.write(stringToByte(bitBuffer.substring(0, 8)));
182+
dataOut.write(stringToByte(bitBuffer.substring(0, 8)));
183183
bitBuffer = bitBuffer.substring(8, bitBuffer.length());
184184
}
185185

@@ -198,17 +198,17 @@ public static void compressFile(String filename) {
198198
if (!w.equals("")) {
199199
bitBuffer += intToBinaryString(dictionary.get(w));
200200
while (bitBuffer.length() >= 8) {
201-
data_out.write(stringToByte(bitBuffer.substring(0, 8)));
201+
dataOut.write(stringToByte(bitBuffer.substring(0, 8)));
202202
bitBuffer = bitBuffer.substring(8, bitBuffer.length());
203203
}
204204
if (bitBuffer.length() >= 1) {
205-
data_out.write(stringToByte(bitBuffer));
205+
dataOut.write(stringToByte(bitBuffer));
206206
}
207207
}
208-
data_in.close();
209-
data_out.close();
210-
file_inputut.close();
211-
file_output.close();
208+
dataIn.close();
209+
dataOut.close();
210+
fileInput.close();
211+
fileOutput.close();
212212
} catch (IOException e) {
213213
System.out.println("IO exception = " + e);
214214
}

src/main/java/prog/lzw/LzwDecompressor.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ public static void decompressFile(String filename) {
6868
filei = new File(filename);
6969
fileo = new File(fileos);
7070
try {
71-
FileInputStream file_input = new FileInputStream(filei);
72-
DataInputStream data_in = new DataInputStream(file_input);
73-
FileOutputStream file_output = new FileOutputStream(fileo);
74-
DataOutputStream data_out = new DataOutputStream(file_output);
71+
FileInputStream fileInput = new FileInputStream(filei);
72+
DataInputStream dataIn = new DataInputStream(fileInput);
73+
FileOutputStream fileOutput = new FileOutputStream(fileo);
74+
DataOutputStream dataOut = new DataOutputStream(fileOutput);
7575

7676
Byte c;
77-
bitSize = data_in.readInt();
77+
bitSize = dataIn.readInt();
7878

7979
while (true) {
8080
try {
81-
c = data_in.readByte();
81+
c = dataIn.readByte();
8282
bitBuffer += byteToString[CommonUtil.byteToUnsignedInt(c)];
8383
if (bitBuffer.length() >= bitSize)
8484
break;
@@ -92,20 +92,20 @@ public static void decompressFile(String filename) {
9292
k = CommonUtil.binaryStringToInt(bitBuffer.substring(0, bitSize));
9393
bitBuffer = bitBuffer.substring(bitSize, bitBuffer.length());
9494
} else {
95-
data_in.close();
96-
data_out.close();
95+
dataIn.close();
96+
dataOut.close();
9797
return;
9898
}
9999

100100
String w = "" + (char) k;
101101

102-
data_out.writeBytes(w);
102+
dataOut.writeBytes(w);
103103
// System.out.println(w);
104104

105105
while (true) {
106106
try {
107107
while (bitBuffer.length() < bitSize) {
108-
c = data_in.readByte();
108+
c = dataIn.readByte();
109109
bitBuffer += byteToString[CommonUtil.byteToUnsignedInt(c)];
110110
}
111111
k = CommonUtil.binaryStringToInt(bitBuffer.substring(0, bitSize));
@@ -119,7 +119,7 @@ public static void decompressFile(String filename) {
119119
entry = w + w.charAt(0);
120120

121121
}
122-
data_out.writeBytes(entry);
122+
dataOut.writeBytes(entry);
123123

124124
if (mpsz < 100000) {
125125
ts = w + entry.charAt(0);
@@ -132,10 +132,10 @@ public static void decompressFile(String filename) {
132132
break;
133133
}
134134
}
135-
data_in.close();
136-
data_out.close();
137-
file_input.close();
138-
file_output.close();
135+
dataIn.close();
136+
dataOut.close();
137+
fileInput.close();
138+
fileOutput.close();
139139
} catch (IOException e) {
140140
System.out.println("IO exception = " + e);
141141
}

src/test/java/prog/huffman/HuffmanCompressorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class HuffmanCompressorTest {
2121
@BeforeEach
2222
void setUp() throws IOException {
2323
// Create a temporary input file for testing
24-
inputFile = tempDir.resolve("test_input.txt").toFile();
24+
inputFile = tempDir.resolve("testInput.txt").toFile();
2525
}
2626

2727
@Test
@@ -75,7 +75,7 @@ void testFrequencyCalculation() throws IOException {
7575
}
7676

7777
HuffmanCompressor.initHuffmanCompressor();
78-
HuffmanCompressor.calculateFrequency(inputFile.getAbsolutePath());
78+
HuffmanCompressor.calculateFrequencyOfBytesInFile(inputFile.getAbsolutePath());
7979

8080
// Check frequencies
8181
assertEquals(2, HuffmanCompressor.frequency['a']);
@@ -99,7 +99,7 @@ void testTreeConstruction() throws IOException {
9999
}
100100

101101
HuffmanCompressor.initHuffmanCompressor();
102-
HuffmanCompressor.calculateFrequency(inputFile.getAbsolutePath());
102+
HuffmanCompressor.calculateFrequencyOfBytesInFile(inputFile.getAbsolutePath());
103103
HuffmanCompressor.buildHuffmanTree();
104104

105105
// Verify tree construction

src/test/java/prog/huffman/HuffmanDecompressorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class HuffmanDecompressorTest {
2323
@BeforeEach
2424
void setUp() throws IOException {
2525
// Create temporary files for testing
26-
inputFile = tempDir.resolve("test_input.txt").toFile();
26+
inputFile = tempDir.resolve("testInput.txt").toFile();
2727
compressedFile = new File(inputFile.getAbsolutePath() + ".huffz");
2828
decompressedFile = new File(inputFile.getAbsolutePath());
2929
}

src/test/java/prog/lzw/LzwCompressorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class LzwCompressorTest {
2222
@BeforeEach
2323
void setUp() throws IOException {
2424
// Create temporary files for testing
25-
inputFile = tempDir.resolve("test_input.txt").toFile();
25+
inputFile = tempDir.resolve("testInput.txt").toFile();
2626
compressedFile = new File(inputFile.getAbsolutePath() + ".LmZWp");
2727
}
2828

0 commit comments

Comments
 (0)