From ca69cc01b1f9d572826472073d95a4cf59136d2c Mon Sep 17 00:00:00 2001 From: coliny125 Date: Thu, 16 Sep 2021 17:40:42 -0700 Subject: [PATCH 1/2] Created Decoder Commit #1 Still testing; works for test file 1 --- .DS_Store | Bin 0 -> 6148 bytes .classpath | 7 ++++ .gitignore | 1 + .project | 17 ++++++++++ Writer.java | 3 -- decoded.txt | 1 + intcodesOutput.txt | 1 + lzw-file1.txt | 1 + lzw-file3.txt | 83 +++++++++++++++++++++++++++++++++++++++++++++ src/Decoder.java | 76 +++++++++++++++++++++++++++++++++++++++++ src/Encoder.java | 71 +++++++++++++++++++------------------- 11 files changed, 221 insertions(+), 40 deletions(-) create mode 100644 .DS_Store create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project delete mode 100644 Writer.java create mode 100644 decoded.txt create mode 100644 intcodesOutput.txt create mode 100644 lzw-file1.txt create mode 100644 lzw-file3.txt create mode 100644 src/Decoder.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2cd6f1c10b49f9fbbf16cb81102e17e7998e5649 GIT binary patch literal 6148 zcmeHK&2G~`5S~p!aZ*){5aQ>6t#@nyAkCp`08{}$!^W^w z!ES*tJ!?5B$eBxsgvIc?hSjG1FlVVI6a$KZe~|(9?v|hqUGN~zzQ5ykTGywomg7?g z=d|YW@zK%2r(0RQ`&)h3OWh6P<|u-Ls|LG1ZOh1b4Usn(wf=((jsT=pHn;2FXPR_o zr?r9kT4W~u`gE38UYp4Z-m>+U!G#XAfpT<_n-~rt&SnX0?;lcGUSK;x%c)-kcVURn zA@3K)ASW2(Bo$)?d^m&z*5DaN^Dzr!@#=*xdZszbdo~t(l52nT+&IJYbk4I3_hAQl zXu%!CI`qL^z)?EOB1ABN_MFwnxwz8GNup4miqB5ydr`c;{)H5ZrE^Q?HLX&qtW=&_ zJ(^gt9S@_XJ$THX?%8qAk>dxH`oG4u^U&)gd)14#X%O39&>3)N&+VYelSf|Q(xgd; zfgABSmQZL~xm@0>ULB3rjK+3NHyVv`O&@J<88v-tb7MR%YnN{rH+T2@FAhg9$FJVu zUQh^DLoTZlr|=#Ja(~(Lyi}WM(&u^g>$gz8Y0@u!p7Yx5d1h68y54hZ5co7;Cuf?S zL~WUwDNzh41{4D+2H5?eV`FGaoCxGs2X?%WBbIQQ3y%4%gQ&9!L{s8KAkLr=;fg3+ ziTuSN!X4*zX=h5D2o&x>#3uw0xiXP|D1@($@pWzv#1yD{#eiZU%Ro^)R$2YuIs5-V z>!h9(1B!wFiUCq;S*<2+N!Hff=2)%OvF&4H!t5pjxeIo(9P + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/.project b/.project new file mode 100644 index 0000000..df4a539 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + LZW_Compression + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/Writer.java b/Writer.java deleted file mode 100644 index 43facb6..0000000 --- a/Writer.java +++ /dev/null @@ -1,3 +0,0 @@ -public class Writer { - -} diff --git a/decoded.txt b/decoded.txt new file mode 100644 index 0000000..50a0185 --- /dev/null +++ b/decoded.txt @@ -0,0 +1 @@ +abcabcabcabcabcabcabcabcabcabcabcabc diff --git a/intcodesOutput.txt b/intcodesOutput.txt new file mode 100644 index 0000000..c05e661 --- /dev/null +++ b/intcodesOutput.txt @@ -0,0 +1 @@ +97 98 99 256 258 257 259 262 261 264 260 266 263 99 10 \ No newline at end of file diff --git a/lzw-file1.txt b/lzw-file1.txt new file mode 100644 index 0000000..50a0185 --- /dev/null +++ b/lzw-file1.txt @@ -0,0 +1 @@ +abcabcabcabcabcabcabcabcabcabcabcabc diff --git a/lzw-file3.txt b/lzw-file3.txt new file mode 100644 index 0000000..20fb9d1 --- /dev/null +++ b/lzw-file3.txt @@ -0,0 +1,83 @@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*##############################################################&############################################################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*###########################################################&,,,/###########################################################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*#########################################################&,,,,,,,&#########################################################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*#################% &##################################&,,,,,,,,,,,&################################### &#################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*################& .###############################&,,,,,,,,,,,,,,,&###############################& ################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*################ &#############################(,,,,,,,&&&,,,,,,,,&############################# &###############&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*###############% %###########################&,,,,,,,&&&&&&&,,,,,,,*%########################### ################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*################ &#########################&,,,,,,,%&&&&&&&&&&,,,,,,,&########################## &###############&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*#######% *###( ###% &###############&,,,,,,,,&&&&&&&&&&&&&&,,,,,,,&###############% *###% ###& &#######&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*###### &# &# &###########&,,,,,,,,&&&&&&&&&&&&&&&&&%,,,,,,,&############ &# &# &#####&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*###### *% (& &##########(,,,,,,,&&&&&&&&&&&&&&&&&&&&&*,,,,,,,&########## ,% /% &#####&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*#######.%######* %& % %###### %#########&,,,,,,,&&&&&&&&&&&&&&&&&&&&&&&&&,,,,,,,,%#########.%######( #& % %###### %######&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*################/ ## #&################&,,,,,,,%&&&&&&&&&&&&&&&&&&&&&&&&&&&&,,,,,,,%#################/ ## #&###############&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*################# #% %###############&,,,,,,,*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&,,,,,,,&################ #% %################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*###############* &, # %###########&,,,,,,,,&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&%,,,,,,,&############/ &, # %##############&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*############## %# # &########%/,,,,,,,&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*,,,,,,,&######### %& #. &#############&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*#################% *###########&,,,,,,,&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&,,,,,,,,&##########& (#################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*##############################&,,,,,,,%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&,,,,,,,###############################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*############################&,,,,,,,*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&,,,,,,,&############################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*##########################&,,,,,,,,&&&&&&&&&&&&&&&%(&&&&&&&&&, ,&&&&&%&&%/&&&&&&&&&&&&&%,,,,,,,&##########################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*########################%/,,,,,,,&&&&&&&&&&&&&&&&&&, , ,, ,, , ,&&&&&&&&&&&&&&&*,,,,,,,&########################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*##############&&&%#####&&,&,,,,&&&&&&&&&&&&&&&&&&&&&, ,&&&&&&&&&&&&, .&&&,,,,*///&######################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*##############&,,,,,,&/,&,,,&%&&&&&&&&&&&&&&&&&&&&&&&,,,,,,,,,,,,,,,,,,,,,&&&&&&&&&&&, ,,,, ,*&#################&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*###############&, ,(, ,&&&&&&&&&&&&&&&&&&#,,,,, ,, ., , ,&&&&&#&&&, ,&###############&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*#############%&&&. %&&&&&&&&&&&&&&&&, ,,,,,, ,,,, , ,&&&&&&&&. ,,, ,&&&&,#&, ,&&/,,%&########&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*#########&,,,, ,#&&&&&&&&&&&&, ,&%. .,,. ,.., , ,&&&&&&&, ,&&&&,&*,,&, , ,&#########&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*#########&&&(, ,&&&&&&&&&&&, #&&&&&&,,,,, ,,, . ,&&&&&&&, ,,,, ,&&,,&, ,&##########&,,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&,,*############&,&#, .%&&&&&&&&&&&/,, .,,,,..,, , ,, ,%&&&&&&&&&, ,, %&&&&*, ,%**%#######&,,,@@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@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&#,,,,,,,,,,,,,,,/#%&&&&&&&&&&&&&&&&&&&%#/,,,,,,,,,,,,,,,(&&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&&&&%(*,,,,,,,,,,,,,,,,,,,,,,,*(%&&&&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \ No newline at end of file diff --git a/src/Decoder.java b/src/Decoder.java new file mode 100644 index 0000000..603d324 --- /dev/null +++ b/src/Decoder.java @@ -0,0 +1,76 @@ +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.*; + +public class Decoder { + + //private static double maxTableSize; + private static String decodedOutputFileName = "decoded.txt"; + + public static String decode (String inputFile, int maxDictSize) throws IOException{ + //maxTableSize = Math.pow(2, bit_Length); + + String[] compressedValuesStr = null; + List compressedValues = new ArrayList(); + int dictSize = 255; + + String inputIntCodes = ""; + BufferedReader br = null; + br = new BufferedReader(new FileReader(inputFile)); + inputIntCodes = br.readLine(); + br.close(); + compressedValuesStr = inputIntCodes.split(" "); + for (String str: compressedValuesStr) { + int num = Integer.parseInt(str); + compressedValues.add(num); + } + + Map dict = new HashMap(); + for (int i = 0; i < 255; i++) + dict.put(i, "" + (char) i); + + String inputStr = ""+ (char) (int) compressedValues.get(0); + StringBuffer decodedValues = new StringBuffer(); + + String newStr = null; + for (int key : compressedValues) { + if (dict.containsKey(key)) + newStr = dict.get(key); + else if (key == dictSize) + newStr = inputStr + inputStr.charAt(0); + decodedValues.append(newStr); + + if(dictSize dictionary; BufferedReader in; - String output; - int tracker; - int binary; + int dictTracker; public Encoder (String filename) throws IOException { in = new BufferedReader (new FileReader(new File (filename))); dictionary = new HashMap(); - output = ""; - tracker = 256; - binary = 0; + dictTracker = 256; } public String encode () throws IOException { - while (true) { - StringBuilder cur = new StringBuilder (in.read()); - if (in.read() >= 0) { - String next = in.read(); - if (dictionary.containsKey(cur + next)) { - cur.append(next); - } - else { - output += cur; - dictionary.put(cur + next, tracker++); - cur = next; - } - } - else - break; + for (int i = 0; i < 256; i++)//load ascii table + dictionary.put("" + (char)i, i); + StringBuilder sb = new StringBuilder (); + String cur = ""; + while (in.ready()) { + String next = ""+(char)in.read(); + String combined = cur + next; + if (dictionary.containsKey(combined)) { + cur = combined; + }else { + sb.append(dictionary.get(cur) + " "); + dictionary.put(combined, dictTracker++); + cur = next; + } } - } - - /** - * variable naming is very poor here but they are simple placeholders to go from char to a big binary int. - */ - public void toBinary () { - for (int i = 0; i Date: Fri, 17 Sep 2021 08:45:41 -0700 Subject: [PATCH 2/2] Working Encoder and Created Decoder --- .DS_Store | Bin 6148 -> 6148 bytes decoded.txt | 2 +- intcodesOutput.txt | 2 +- lzw-file2.txt | 2 ++ src/Decoder.java | 10 +++++----- src/Encoder.java | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 lzw-file2.txt diff --git a/.DS_Store b/.DS_Store index 2cd6f1c10b49f9fbbf16cb81102e17e7998e5649..c614366902bc3725b24ee01e18ca66d97d87c899 100644 GIT binary patch delta 21 ccmZoMXffE(&dMspz`)QuiA{F%O4ev007AzF%m4rY delta 21 ccmZoMXffE(&dR!pfq`MuBsSU2D_Nt308BInkpKVy diff --git a/decoded.txt b/decoded.txt index 50a0185..7e75d29 100644 --- a/decoded.txt +++ b/decoded.txt @@ -1 +1 @@ -abcabcabcabcabcabcabcabcabcabcabcabc +abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcdefgabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcdefgabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc \ No newline at end of file diff --git a/intcodesOutput.txt b/intcodesOutput.txt index c05e661..98ea32f 100644 --- a/intcodesOutput.txt +++ b/intcodesOutput.txt @@ -1 +1 @@ -97 98 99 256 258 257 259 262 261 264 260 266 263 99 10 \ No newline at end of file +97 98 99 256 258 257 259 262 261 264 260 266 263 267 265 268 271 270 273 269 275 272 276 274 277 280 279 282 278 284 281 285 283 286 289 288 283 100 101 102 103 290 287 298 297 300 291 99 293 295 301 299 302 306 309 308 311 307 313 310 314 312 315 318 317 320 316 322 319 323 321 324 327 326 329 325 331 328 99 \ No newline at end of file diff --git a/lzw-file2.txt b/lzw-file2.txt new file mode 100644 index 0000000..5fa2b99 --- /dev/null +++ b/lzw-file2.txt @@ -0,0 +1,2 @@ +abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcdefgabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcdefgabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc + diff --git a/src/Decoder.java b/src/Decoder.java index 603d324..3a30eb4 100644 --- a/src/Decoder.java +++ b/src/Decoder.java @@ -36,21 +36,21 @@ public static String decode (String inputFile, int maxDictSize) throws IOExcepti for (int i = 0; i < 255; i++) dict.put(i, "" + (char) i); - String inputStr = ""+ (char) (int) compressedValues.get(0); + String oldStr = "" + compressedValues.get(0); StringBuffer decodedValues = new StringBuffer(); String newStr = null; for (int key : compressedValues) { if (dict.containsKey(key)) newStr = dict.get(key); - else if (key == dictSize) - newStr = inputStr + inputStr.charAt(0); + else + newStr = oldStr + oldStr.charAt(0); decodedValues.append(newStr); if(dictSize