From 03568efec3e9e11167eade8c8e2f0e4be38e090c Mon Sep 17 00:00:00 2001 From: lianawadhwani <89544220+lianawadhwani@users.noreply.github.com> Date: Tue, 21 Sep 2021 12:16:10 -0700 Subject: [PATCH 01/11] created comments --- src/LZWDecoder.class | Bin 0 -> 2388 bytes src/LZWDecoder.java | 49 +++++++++++++++++++++++++++---------------- src/lzw-file1.txt | 1 + 3 files changed, 32 insertions(+), 18 deletions(-) create mode 100644 src/LZWDecoder.class create mode 100644 src/lzw-file1.txt diff --git a/src/LZWDecoder.class b/src/LZWDecoder.class new file mode 100644 index 0000000000000000000000000000000000000000..b06fd70ae83439d6569956f3ff9dc3946189e080 GIT binary patch literal 2388 zcmb7FOK%fb7(F+Bj6E4j65@bKLdqi$+X45H2C$P9Vn{GJ1W1}RP#$A@aE6!}*B%Fu zx~YUJb=y_dO;t9mx@biV0;%e%i%Q+~AM^)wU$v#@j-47gTr5a`K#B zTb|J?Dirv_Xosd?hlaPXQ$WpKT|8qH?4nT>@E1*~YgcZIXj+POYUsi)-jz3Ae=X?Ij3q`C4sJ{3YTK@EFD5r08*e=L!T6AzinE2dA9CU>W<3ueHsR& zdBLJfNFMFiZ~zBM^Ip|-jCp(hKKVt4wrYMzadQGEB>bfG%l3#tq%~&IxIn0)S8E2Xl^*cW zX(`LbveJ?dHJrj}T2e9yJnRL&nRiCR8JuMR%Z62Qmfd8`b}@ygHJn3MVE0{p#mLxJ zL3b8SXPK*-qgzhxHGj3}Y$fRRR|}-z0yEZ4Skq2kV){9YGFMnL=P@G-=Ac~7YPcj5 zDNvCJd2&U=oXoaBp={R-I(yD6S-MlNa-C{k?Jb@$51aLL@f@|-Or&KUJaCND)vEqL zpzYeEz>wF2>#p7^8(UxnW>|>=J9DOGu*C94bzaYxd7_@ZUoa|;NslSG?y)#KyYWR} z$DE@VR#@t;l!99V{p+roGRwwA+nKWKR?#D(&e`>9!H{3&y&K)&n3Q7)Oxm_nbE>ylt&LR?;K(KnfqCxQ@DX1&Sa;2i>dp&TbZ0h9 z&OTxT_?WmQ?yht1=NyYag^0g^vh)<;HK_5vHFU%iYv_)5?ODU#cmw_MqYb?M1Hl4U zIUYcW<1UJKlR$)H52CzcfSvgu`q};laE%B*@t^QzU*^b5+s<&+PBr&@W4)aMkI>iq z)p+~~)ZS+})b|X$EV=klh{rGg;AwYG4n7VY4ZJ@Sm%HZXIOz=so*^~Cz1mOV1}1(+ zBIWPelM47ogParzUl&dVUXzXnr1)r1%145)6ey%M8j_+7Omgb@4xdMrUohwbLj*?s zQN`ycq34(aB;lx%@;}BtFT%eWA@%)#Di1?+#690=I1)~@*pwe(Jh7okO-P0f9M8p< zo-kCjC8|ohHtcaZGKvqwRP{oJu+0tO7tAAIgn!ggXgJQmjWDbyaRe!@(#WvoXEDy8 zonoe(#w|>uNPDZ8#^)^DFZuNwT)?-;;d{*DM_k5lxPsp)@h2tz!409|rs!rD8AM(r zV2Cl4#59)0C6;}K`&F#q23aH#`kNK>7Y1J9GlUhiD@gDWuO|NcNA{+hsA=XBf9tI@ zPBD#rRMPVT=a&*sk((K&8}>GEakzoYuX47_P4)^6{uG@wBZAsSj^3mO-E~bK1|DW$sk2?!u;A^gmb{J=_2Q literal 0 HcmV?d00001 diff --git a/src/LZWDecoder.java b/src/LZWDecoder.java index e8e25ad..69496d4 100644 --- a/src/LZWDecoder.java +++ b/src/LZWDecoder.java @@ -5,6 +5,8 @@ import java.io.InputStream; import java.io.PrintWriter; import java.util.HashMap; +import java.util.Timer; +import java.io.IOException; public class LZWDecoder { @@ -14,9 +16,9 @@ public class LZWDecoder { private byte [] byteArray; private String finalOutput; - public LZWDecoder(String binString, int bitNum, String outputFileName) throws IOException + public LZWDecoder(String binString, int bitNum, String outputFileName) throws IOException // this is the constructor { - this.dict = new HashMap (); + this.dict = new HashMap (); // intializes the hash map this.bitNum = bitNum; this.binString = binString; this.finalOutput = ""; @@ -24,12 +26,13 @@ public LZWDecoder(String binString, int bitNum, String outputFileName) throws IO // File binFile = new File (binFileName); // readBinFile(binFile); - decode(); - writeToTxt(outputFileName); + decode(); //calls method below and decodes the binary file + writeToTxt(outputFileName); } //reads the binary file into a string. not working, so I've bypassed this method for now and just input a binary string into the constructor. + /* public void readBinFile(File binFile) throws IOException { FileInputStream is = new FileInputStream(binFile); @@ -42,20 +45,21 @@ public void readBinFile(File binFile) throws IOException is.close(); } + */ public void decode () { for (int x = 0; x<256; x++) { - char ch = (char)x; - dict.put(x, String.valueOf(ch)); + char ch = (char)x; // this converts number into char + dict.put(x, String.valueOf(ch));// puts char into hasmap and assigns it a value } - String binStringCopy = binString; - String currBinString = binString.substring (0,bitNum); - binString= binString.substring(bitNum); - int currDecimal = Integer.parseInt(currBinString, 2); - String currString = dict.get(currDecimal); + String binStringCopy = binString; // makes copy of string + String currBinString = binString.substring (0,bitNum); // gets the current part of the binary string you need + binString= binString.substring(bitNum); // makes the binString smaller + int currDecimal = Integer.parseInt(currBinString, 2); // changes the number into a number + String currString = dict.get(currDecimal); // takes the number and find its string counterpart in the dictionary // finalOutput = currString; String nextBinString = ""; @@ -63,7 +67,7 @@ public void decode () String nextString= ""; // String lastSymbolInDict = ""; - + // same thing as above but for the next string nextBinString = binString.substring(0, bitNum); binString= binString.substring(bitNum); nextDecimal = Integer.parseInt(nextBinString, 2); @@ -81,18 +85,18 @@ public void decode () } - else + else // this is for the edge case if you get to a numebr that hasn't yet been added to the dictionary { - dict.put(counter, currString + currString.substring(0,1)); - currString = currString + currString.substring(0,1); + dict.put(counter, currString + currString.substring(0,1)); // puts the current and the first letter of the current into the dictionary + //currString = currString + currString.substring(0,1); } nextBinString = binString.substring(0, bitNum); binString= binString.substring(bitNum); - nextDecimal = Integer.parseInt(nextBinString, 2); + nextDecimal = Integer.parseInt(nextBinString, 2); nextString = dict.get(nextDecimal); - counter++; + counter++; // increments counter } for (int x = 0; x Date: Tue, 21 Sep 2021 12:34:56 -0700 Subject: [PATCH 02/11] put timer in --- .DS_Store | Bin 6148 -> 8196 bytes src/LZW.class | Bin 0 -> 3281 bytes src/LZWDecoder.class | Bin 2388 -> 2491 bytes src/LZWDecoder.java | 16 ++++++---------- src/TestFile | Bin 0 -> 10 bytes src/Tester.class | Bin 0 -> 911 bytes src/Tester.java | 9 ++++++++- src/lzw-file1.text | 1 + src/lzw-file1.txt | Bin 36 -> 13 bytes 9 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 src/LZW.class create mode 100644 src/TestFile create mode 100644 src/Tester.class create mode 100644 src/lzw-file1.text diff --git a/.DS_Store b/.DS_Store index 331c40256ebbf08481bf53dd38d8d4d63dcbbd74..7998dc9c0820686f83c1c8ea5a160f5d808a64e4 100644 GIT binary patch literal 8196 zcmeHM-D(p-6h70Wx{20CC^VOQq2NW7{LvPQ5MwG95yTV~sn-?SD+?TVu)e2|@{!0b; z^T9;rSW`HYC>|YXL<#^*V^|dQ#gBiW$p?Tng)@m5L1B^#lvJit45o4iCh3^3Df^j3 zNhc;E!;gy0REEM->cLE5POK(Tw^{+Mz_J27cTbT;Ho1pRIDco`n7Q#&6hTu~9lz~Z zp6Bp=xK2G9l7l}lLjD*bZ@^|uBf3d15z3)1mFN})^p=7M^T%JA2xBOWzICVB<#vryE_OWb(g1Mv1jysJq(#BF0GXEa_^ijLvo ze#k?1!9#3R#?=kq>0(sHQFj|3bsrwWUyCFUTzmbgY(FR#zq7Sedi}yh!^j%hjqHnN&l@#^RxtGI zt-&$BdejPfmg*m2yUhD7>xtbRo#eLedT!9N-R?k;?M@da&!5_E#~anXq1*9=pQfBJ zjEs>v$>k@LononAR;tx$!JO>w77J#zvNN4#jP2{C+lQyG-;F2lryoAyLqcKdu%u0S zJ#Rmwr$h+vXEpSuIdC1%J>wow4LZVp^|2rB$-TR%8-GwNsGEt}Q#r!Ge*44F=l}d; z(H*V83KdAnSb3iRA0)s3U*U>$D6N22VATq+bfej*BkJ#;3(*DeT-!uFMdgLt%_Is6 l8j+3z#c2+l|HBY{6Q-O~Q#g}|5fuF*K**pQt-wkZ_yt7zI@|yN delta 288 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{MGjUEV6q~50C;}2-1c@c*B<1Jl0GSMY8w*!3 zf+d(4k{B`>@=}VSl9Ocx^?B`qO6>nb!Q@CmZC-hxh&)_mqM)guK2Ss-CIVy&PVN^H zova`vBghZr@ngs&3CZxH$V~1QGE_hj0qSFBC}t>PNQOISV__`IVs;J=L1v&N5D0Js i30IKkHWq$op3E=f2=YD1dn_QD3F3XQ*yebiIm`eFp;hky diff --git a/src/LZW.class b/src/LZW.class new file mode 100644 index 0000000000000000000000000000000000000000..8a6778dab5fc4ea6a9a155b02eaa14d74ed56a69 GIT binary patch literal 3281 zcmaJ@TT~m@72P9^G(sM*uu&X2Kx}He5)XrojctL!M);u^P--YtCXF+Q0c6BTl}0#r zlE!Iilk|}^=_6^HHn!V_KGHU^Tfs6}Uj67#AK(4y%6~uGpRU&J3f*@!Dr3W{K4x_8 zz2~*hKIhIKKE87oKo36f!v(hjS%n8)34u%6g4UkVjG6YtNXYIQ71v2OdDGM%Ajt{n6nb3xE~K;hk}Pygs@XW&ARm=O`LG&vX>=z z!UF@50Y9oyFH&icAcy1Scpp`<3%hx6Udu_?UJlP0N4KB;KcQj|_A;5YVUA||tso=> zX=GzQetZ&P1rZg^XramVkYcl1UQ3yJUV_iemeUtjVw+m2Mw^QLXctKo3H8yi!&e#q z?u{!>Q}!VR2Z)>%MmpOrYT-u*It3DkgnNe(yCjh@1zjwbQ|G*{P3d_*4&$iMJjR;Y znzqqyq17$np^8?2ae7+M>r)lYD2@wFl4bk4W_i=nJt1MoI#}gU`itp|<+cxQKca}K z7{DpkFVAp@OgKUcoWWTIaTSjVyd5O1AgnBCnWCPU-bOYJsu;pBJgrd!OMT7lA)iKP#1QR##R-q zzo_CVL6Pdq`LwB5crWmtRFMLmZZWfh)F<$Hj)u>0ix_~?iP*F;>w zB?%8#m?1crD4L`-z3JM#A8B-o$Gi#ySvIWYQ8eyEe`HMTd`?AP%pgxHlP!?ICW;Cc zR9qHqS)Lx&V2T^2J|jA;#zyZypeW%N7m_LAHfXA^2?JkPrg4a99YtY@tgCYzE8K5g}ZYP&JaC zF*LK7*CiY)m(@9?dNx$rIUDSRdPR4J;~S4g$Ur%koucingK0w_F3wNt`B7~$!HbKh)(|wAgS91C$$0r=;H)&nl zL`=(MM%YZkiS6riw=2_@|PU)mnpyKkYA$wvP1p~<*z#AuTlQG zLwS_Kp8bh9tTte&kqFY*8 z`{)D9(Kq>QhM&)Uka>ms5Jn>+XhJJmcn=>yJC5?+9H9IdI`J)@tb=Qf9|p3*u2yhH z0`6fi1N}ChW9ST5x&b#ohJb%ClH;rBNVY8F;P5IAC)<{BBr2~WnheRy=!tq((U)At z$*4EvDWShh2`UWubktWCtAbUQ=npEccks5Ag)ij4gL6O$iMKEmtm4L*khi>5!pLuN zriAhF`;OKV3XyrRs!Iv^HyB@Z5s>S&bRG2@EeWNiwHHDazZ=w-)}}(<5++vgr1gHE znY$p6y~J_@M~Lh(-g;5&;OAu%dWq}_9K=bk^z#`*9H)@rsGjA&tHk+L3{rmxZ(tZd z;Lf{v9Pi;gZebL^3W9$GQ@12Y&3{amiP5MvB?kzlQ|dhBo;8q>re3TQFzu! zMh~-6@LdJp<2b>8NXp&!;Q1G+?97oLvUV?}n5#_nJv&!W7-R#rl<@S_arRC9O$1u* z;2C}|Sv~Uimi1EZv~YQbK|YHb5H{eSol|Ueo^aXY$k^yhv1fNPRt|e|m7YIofkAx*~K)A^U f!L4_2o$ng{yTP3$>-kgsoNIo{@8OqtAEEyOtuFe^ literal 0 HcmV?d00001 diff --git a/src/LZWDecoder.class b/src/LZWDecoder.class index b06fd70ae83439d6569956f3ff9dc3946189e080..2e3fd277baded7e44cd9db415a0625bab47a2368 100644 GIT binary patch delta 497 zcmY+AO;1xn7=@p=o!(on1%qwHDxj$-gfzMkiF#EMOHf2HMhSjkXtCE?DYdr6kBuK2 zjV3P4>{!4`SCXJ1#MH!<8%^A?@=wUx81;=iGntw5o@8?7IqO?K#=Wn0_6D=ybGP z!eJB0GrQ=#l~;Dm-J99hzlxWPexN61QYLKHIM8GS*4RJ!zjMUcm#!~G`^BAj^n$b! z4${IQVjQMZbsC>ur5@lIS&lQx5SKZ@HJx${Q&6~?x=%RGbH-TUEK7{D%z55(fp1)7 zovZv{ia$(CD>>;TFFnl2K?>qilrxlMQhSmdv+`Jtr_9;c(ab=<|4R$|$w`E1jT4PV z`9&8*lyduu3gL>L&OftizeoL{yUK8ncJ6C=4>TREQOFbKy6TYrI?y|+-VNPlDmr

E8ocTV^nK|<_{Lm1*{rlq=kfL%KOjur-OtWq7t?QfvXL^U_k%o{prqnmd66)osc3t>^C1Ha~Z@JuPH0jZiB|G69**Y1^=IksC(+)nt9 z969}0HR5CrzR{@yLj*_=;;jk~(Zw)*yi=59QXS1OqM~CgF;12Va=fQPnnShpU4M_6 z<%ADh@QEuvbH^7Rl<}mDKP*d#6^W3Q9@b=lyrkHaG+Q#qwj*VI*r#9~oxwm$^0%Jm tg|rzDBuC4-)E@OZDvJB+a|JJ}y0V8g*0nn7IH$2gQM;g`uk0$X`9D&tN}2!w diff --git a/src/LZWDecoder.java b/src/LZWDecoder.java index 69496d4..6b7f450 100644 --- a/src/LZWDecoder.java +++ b/src/LZWDecoder.java @@ -50,6 +50,7 @@ public void readBinFile(File binFile) throws IOException public void decode () { + for (int x = 0; x<256; x++) { char ch = (char)x; // this converts number into char @@ -88,7 +89,7 @@ public void decode () else // this is for the edge case if you get to a numebr that hasn't yet been added to the dictionary { dict.put(counter, currString + currString.substring(0,1)); // puts the current and the first letter of the current into the dictionary - //currString = currString + currString.substring(0,1); + currString = currString + currString.substring(0,1); } nextBinString = binString.substring(0, bitNum); @@ -106,6 +107,10 @@ public void decode () finalOutput+=dict.get(Integer.parseInt(currBinStringCopy, 2)); } } + + public String getFinalOutput(){ + return (finalOutput); + } //writes the public void writeToTxt(String outputFileName) throws FileNotFoundException @@ -115,15 +120,6 @@ public void writeToTxt(String outputFileName) throws FileNotFoundException output.close(); } - public static void main(String[] args) throws IOException { - LZW compressor = new LZW(9, "lzw-file1.txt"); - - String testString = compressor.encode("lzw-file1.txt"); - System.out.println (testString); - - LZWDecoder expander = new LZWDecoder (testString, 9, "TestFile2"); - - } // class GFG { // // // Function to convert binary to decimal diff --git a/src/TestFile b/src/TestFile new file mode 100644 index 0000000000000000000000000000000000000000..59290975a78732b8eb0bd7c6d1fe52e971f1c0bb GIT binary patch literal 10 RcmY!o;1FO?U}9>J000C~0R;d6 literal 0 HcmV?d00001 diff --git a/src/Tester.class b/src/Tester.class new file mode 100644 index 0000000000000000000000000000000000000000..f28dff138a9aeb9585977f9a06c45673e24a6f4e GIT binary patch literal 911 zcmZuwTW=Ck5dIDY7Pd>d3Ds(qR>h^XAgy1S&(M#e4o6VR01-G)WO-$m+Gm8B5dmgmX|Wv?GW! z#H_EMS3VM;Qu2>|iArinAx%}dW4c|=kk==mFNdPYAgf?j!&O|npu72{=X0A>x_wfg z8AF9zeoI1plEV$Vs^U6sD45r96So-BBfS@M7?dN4upAvC2r46~=qwy-R5 zo;riFhWnBzY4$yjJHF)F8Ko&$Wl(8BuSiRmdl5Wfh@S3gRYe7l(9#g>J2?zhddp)Vh$vn2 z4T8wjZv+dHt)D>IPefDEA*LI})XV^hogcWeJir{8RBnJpvOjTmfPxIr!8lN&zzHh* x%LHB<;^FRDy*yQd{13>cp<<4_MZ{3V4Au}Q6-m_SWOJm7VT<&=AU}YY{{T)P$?O0C literal 0 HcmV?d00001 diff --git a/src/Tester.java b/src/Tester.java index 88d5c3d..019f445 100644 --- a/src/Tester.java +++ b/src/Tester.java @@ -1,13 +1,20 @@ import java.io.IOException; +import java.lang.*; public class Tester { public static void main(String[] args) throws IOException { + LZW compressor = new LZW(9, "TestFile"); String testString = compressor.encode("lzw-file1.txt"); System.out.println (testString); - LZWDecoder expander = new LZWDecoder (testString, 9, "TestFile2"); + System.out.print("time in nanoseconds = "); + System.out.println(System.nanoTime()); + System.out.print("time in milliseconds = "); + System.out.println(System.currentTimeMillis()); + + LZWDecoder expander = new LZWDecoder (testString, 9, "TestFile2"); } } diff --git a/src/lzw-file1.text b/src/lzw-file1.text new file mode 100644 index 0000000..6bb3d84 --- /dev/null +++ b/src/lzw-file1.text @@ -0,0 +1 @@ +abcabcabcabc \ No newline at end of file diff --git a/src/lzw-file1.txt b/src/lzw-file1.txt index a9ef25d86cb996838cce808c3ff385eb1884e5f6..7bee7037e5c0a7cc3bd0f945dfca49a662e30556 100644 GIT binary patch literal 13 UcmXqHXklnnU~q6~WH{ad02G-6rvLx| literal 36 McmYdHN=_t%0RI3D$p8QV From 41f3082eb99cd23113bb37f507be193ec0f0df15 Mon Sep 17 00:00:00 2001 From: lianawadhwani <89544220+lianawadhwani@users.noreply.github.com> Date: Thu, 23 Sep 2021 22:10:02 -0700 Subject: [PATCH 03/11] deleted everything and copy and pasted her orginal code because giving null for some reaosn --- .DS_Store | Bin 8196 -> 8196 bytes src/LZWDecoder.class | Bin 2491 -> 2546 bytes src/LZWDecoder.java | 48 ++++++++++++++++++------------------------- src/Tester.class | Bin 911 -> 911 bytes src/Tester.java | 14 +++++-------- 5 files changed, 25 insertions(+), 37 deletions(-) diff --git a/.DS_Store b/.DS_Store index 7998dc9c0820686f83c1c8ea5a160f5d808a64e4..31d0ec073b7dcc6ce9281405d6c6091dc2788937 100644 GIT binary patch delta 16 XcmZp1XmQxEN0`~z#B%d~VOJgiGg$?J delta 16 XcmZp1XmQxEN0`~nz;N?^VOJgiGbIIh diff --git a/src/LZWDecoder.class b/src/LZWDecoder.class index 2e3fd277baded7e44cd9db415a0625bab47a2368..d1a961b3d7c19dd6363ba97221912ebbef903bcb 100644 GIT binary patch delta 877 zcmb7CO;1x%5IytWYv1dm68UJf(&9%-tgi?{p_CSoQc-Ha5I;hYC{!qI;n^ZB$VxOZ z7`NV?8xuApCM-~F2qs1oS0)-4{sDf0i3=CTi1W}i>dwX7nLGE)nVFmOvgS*T{_e;2 zD*#N690*{Bcnwxil5cPMkuE*ra$x5N#^jod}^rER#!+)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#gmM2yQ@=R8!3-XQG=q>lYS$^K z2*$Rmno;x!tIeN>eDTWa_T;DuYtj>In3lWlk->ekc_4&9mx?$JZc41lB?IE!lDj4E PDC2@miEeX;yZHVB(-F4G diff --git a/src/LZWDecoder.java b/src/LZWDecoder.java index 6b7f450..938796e 100644 --- a/src/LZWDecoder.java +++ b/src/LZWDecoder.java @@ -5,8 +5,6 @@ import java.io.InputStream; import java.io.PrintWriter; import java.util.HashMap; -import java.util.Timer; -import java.io.IOException; public class LZWDecoder { @@ -16,9 +14,9 @@ public class LZWDecoder { private byte [] byteArray; private String finalOutput; - public LZWDecoder(String binString, int bitNum, String outputFileName) throws IOException // this is the constructor + public LZWDecoder(String binString, int bitNum, String outputFileName) throws IOException { - this.dict = new HashMap (); // intializes the hash map + this.dict = new HashMap (); this.bitNum = bitNum; this.binString = binString; this.finalOutput = ""; @@ -26,8 +24,8 @@ public LZWDecoder(String binString, int bitNum, String outputFileName) throws IO // File binFile = new File (binFileName); // readBinFile(binFile); - decode(); //calls method below and decodes the binary file - writeToTxt(outputFileName); + decode(); + writeToTxt(outputFileName); } @@ -45,22 +43,21 @@ public void readBinFile(File binFile) throws IOException is.close(); } - */ +*/ public void decode () { - for (int x = 0; x<256; x++) { - char ch = (char)x; // this converts number into char - dict.put(x, String.valueOf(ch));// puts char into hasmap and assigns it a value + char ch = (char)x; + dict.put(x, String.valueOf(ch)); } - String binStringCopy = binString; // makes copy of string - String currBinString = binString.substring (0,bitNum); // gets the current part of the binary string you need - binString= binString.substring(bitNum); // makes the binString smaller - int currDecimal = Integer.parseInt(currBinString, 2); // changes the number into a number - String currString = dict.get(currDecimal); // takes the number and find its string counterpart in the dictionary + String binStringCopy = binString; + String currBinString = binString.substring (0,bitNum); + binString= binString.substring(bitNum); + int currDecimal = Integer.parseInt(currBinString, 2); + String currString = dict.get(currDecimal); // finalOutput = currString; String nextBinString = ""; @@ -68,7 +65,7 @@ public void decode () String nextString= ""; // String lastSymbolInDict = ""; - // same thing as above but for the next string + nextBinString = binString.substring(0, bitNum); binString= binString.substring(bitNum); nextDecimal = Integer.parseInt(nextBinString, 2); @@ -86,18 +83,18 @@ public void decode () } - else // this is for the edge case if you get to a numebr that hasn't yet been added to the dictionary + else { - dict.put(counter, currString + currString.substring(0,1)); // puts the current and the first letter of the current into the dictionary - currString = currString + currString.substring(0,1); + dict.put(counter, currString + currString.substring(0,1)); + currString = currString + currString.substring(0,1); } nextBinString = binString.substring(0, bitNum); binString= binString.substring(bitNum); - nextDecimal = Integer.parseInt(nextBinString, 2); + nextDecimal = Integer.parseInt(nextBinString, 2); nextString = dict.get(nextDecimal); - counter++; // increments counter + counter++; } for (int x = 0; xz>a8iXRszsN-&-sYH)P9*2(S&&ou9Q@B%#Aq|~C61pz;APAXOOX$`ave+P?bA{^> zgw2+9C1H~wy@=~OuIv2IlVC7x3(G|BX*je!U$}PWG>RQ=-@d(;ut%UvU3=tTImqC%>cLp+#Qc&Rwu7RNr T6-~r&3Lp%EGk(tbe+d_VH_c1Q delta 372 zcmX9)TT22_7@U*J+1<{1S<}o*7rVG-Y8E|2mehlw=u?u^+Y*~>Y+LAd!9QV(@6m54 z*n*%R(y!^9dia=Oh8c!$LMQZjzfU0%1UeUe2?~MKGe>UIvP}gPj3ES-AgQ-H*T#cU zwGC%bJ#~kcGdL)oNr(`r_V}@U#RIj9`{asLj6p+u`a*V883`mQ<{460@R~JMK?Yfh z9K#}(yw{XO?|7MOJKlFHAYsKDXBru-GOS^VAoOP{ykvu+0G-cs4Cl6I-I#o`UTllH zP0>{%2QvU)ykII_-f!R(;3;T$6 z-!Ql3Bh5iu_L1lKiFF@EA#megsBmF=7|8AM_drG*3eueAp`wH^b`e1xF|@dI1Rw~4 L2ESv@XK?ZhSw2Lc diff --git a/src/Tester.java b/src/Tester.java index 019f445..33d1eee 100644 --- a/src/Tester.java +++ b/src/Tester.java @@ -3,18 +3,14 @@ public class Tester { public static void main(String[] args) throws IOException { - - LZW compressor = new LZW(9, "TestFile"); - - String testString = compressor.encode("lzw-file1.txt"); - System.out.println (testString); - - System.out.print("time in nanoseconds = "); + System.out.print("time in nanoseconds = "); System.out.println(System.nanoTime()); System.out.print("time in milliseconds = "); System.out.println(System.currentTimeMillis()); - - LZWDecoder expander = new LZWDecoder (testString, 9, "TestFile2"); + LZW compressor = new LZW(9, "TestFile"); + String testString = compressor.encode("lzw-file1.txt"); + System.out.println (testString); + LZWDecoder expander = new LZWDecoder (testString, 9, "TestFile2"); } } From 2a5f1f50f2c21a8ec9f7c045e76cfffd6a22fd6b Mon Sep 17 00:00:00 2001 From: lianawadhwani <89544220+lianawadhwani@users.noreply.github.com> Date: Thu, 23 Sep 2021 22:15:33 -0700 Subject: [PATCH 04/11] added some comments and chagned the name of a variable to be more fitting the what it represents --- src/LZWDecoder.class | Bin 2546 -> 2408 bytes src/LZWDecoder.java | 24 ++++++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/LZWDecoder.class b/src/LZWDecoder.class index d1a961b3d7c19dd6363ba97221912ebbef903bcb..c3a154199d971dada68016e7a0e408b4727921ae 100644 GIT binary patch delta 931 zcmbV~%}*0i6vcmUW;)XjRRO7SY=!t0po1a;Ra*f8713%mE&xBkYN3D?v@xzss!5~K zoz6nz#)OS47brADqjBNN#GU_v8y6-fE{zfIK*Z?M%)I;Fx$m8K&z(8n)_$(G-~W91 z2G~bo)*e?qHZDyT+ru=lLs2=Ixt?jxXQpz^r>+$yrgDl%LvLgH-*n2xVrQ5Zc6ke` zH|Ww9rk#Z6X!Qd2_+YPhSc{pdu+-}CCbb5$E6jeny+>NhCYRnY2RNuO^P^L_YvT&N zp|QVOl=X!YWz=Cx90F}nRu!P`==-8oiWy?j z2OaS_?C1hpV++K~G!K-Ndb;>YvNdTx=n^W+v>uE5Xc_FDCtK4LSRmOc345ck%XGfQ zO&ZnflL0+p%4GTHf3uT;zv(qjz^5lnpC2**TwsZ=M9`;}>G2*~8$+!xIRv82du=(z z6*S-&j-eZ(Y-vAf{9n0JP`b_OiBKfuN=3P(GCxCyyCU3n{al&d>G;qb#SMaN$M(gq zh+Yyf&xTS+?s_#VpI+m%#CvR(*h)x@5+)(Prd2X~sAn&2BoU6#2kOJ~GHxp)GP&t>T=DF|4*SqT0!*6j_yKObw7z z=NVTw1>a_pVUf~I@CTauPTe9m2w7BExbmt$lY+K*YWY;3*k-d>O7qPldUbTK6l(06 nmX5Aa#Z@t0VZ~}AvY(N28W*@Ib5Ph>8I$A%*|NIKv~ZkXX^FNw delta 1072 zcmb7@&2Jl36vcmcW;|n0OlT4tI*FUm(g@>}gyPf$I}NlZZG+Mh@u8{|+L+XJ90n&O zcE|!@kfI`%FgrGgF6gRK3#nBF39&#dkdRpLAFx3z0I@`faK{1DE|F&L$9wmlIrqIY zKlT3J=YIRw_LsmU8#moWaeFl$iF1fYg71x#nM@ah9wQlb7>n~Lhl4FCc4ZlNI1(qv z<3UrBff&QlEKh_B`C!yY*^_aOG8N1jY5S=-$2cCmZ5-a8<>@%noDgikT&vU<1vCBd zOfSNz@QX8_|7@I>@xi6idTGor)hc6W8oocbT&>m1tJ50`<&}DMxh8a1%Jmb~TFHO5 zQD14)g+y98_L&Zsf}-_echzNy*Bty1^!4CV>+1u{f=HA%1VcoK&(vz=)uLZoTPv?Q zD8z7ZBQhBLW;u$o9$b%<#R~fDGtC4RN$%x765Nl+UWVAmgA9`90nY1TSxWz9eTT3y zI0wcH8g+rZXHE|E2v(s9MCz<8#xTXwP|xQi;d60fRN!Kols-s&TI5dAkakoK&0dvQ7VC0dwn p=)~*v@TRJHqXV;mNm=U+E>lt8t(); + this.dict = new HashMap (); // intializes the hash map this.bitNum = bitNum; this.binString = binString; this.finalOutput = ""; @@ -48,28 +48,28 @@ public void readBinFile(File binFile) throws IOException public void decode () { - for (int x = 0; x<256; x++) + for (int x = 0; x<256; x++) // creating the dictionary { char ch = (char)x; dict.put(x, String.valueOf(ch)); } - String binStringCopy = binString; - String currBinString = binString.substring (0,bitNum); - binString= binString.substring(bitNum); - int currDecimal = Integer.parseInt(currBinString, 2); - String currString = dict.get(currDecimal); + String binStringCopy = binString; // makes copy of string + String currBinString = binString.substring (0,bitNum); // takes the substring of the first probably 9 bits + binString= binString.substring(bitNum); // assings binString to the substring + int currInt = Integer.parseInt(currBinString, 2); // changes the binary code to an integer + String currString = dict.get(currInt); // gets the current string by finding the integer into the dictionary // finalOutput = currString; String nextBinString = ""; - int nextDecimal= 0; + int nextInt= 0; String nextString= ""; // String lastSymbolInDict = ""; nextBinString = binString.substring(0, bitNum); binString= binString.substring(bitNum); - nextDecimal = Integer.parseInt(nextBinString, 2); - nextString = dict.get(nextDecimal); + nextInt = Integer.parseInt(nextBinString, 2); + nextString = dict.get(nextInt); int counter = 256; while (binString.length()>= bitNum) @@ -92,7 +92,7 @@ public void decode () nextBinString = binString.substring(0, bitNum); binString= binString.substring(bitNum); nextDecimal = Integer.parseInt(nextBinString, 2); - nextString = dict.get(nextDecimal); + nextString = dict.get(nextInt); counter++; } From 7805bc9b246a3564857c2f954bb77ae034ed085e Mon Sep 17 00:00:00 2001 From: lianawadhwani <89544220+lianawadhwani@users.noreply.github.com> Date: Thu, 23 Sep 2021 22:28:27 -0700 Subject: [PATCH 05/11] added more comments. attemptng to fix code, but probably making worse --- src/LZWDecoder.java | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/LZWDecoder.java b/src/LZWDecoder.java index 56b475d..2e57348 100644 --- a/src/LZWDecoder.java +++ b/src/LZWDecoder.java @@ -53,37 +53,43 @@ public void decode () char ch = (char)x; dict.put(x, String.valueOf(ch)); } + ArrayList nums= new ArrayList (); // creates an arraylist to put all the numbers when converting from binary to integers String binStringCopy = binString; // makes copy of string String currBinString = binString.substring (0,bitNum); // takes the substring of the first probably 9 bits binString= binString.substring(bitNum); // assings binString to the substring int currInt = Integer.parseInt(currBinString, 2); // changes the binary code to an integer - String currString = dict.get(currInt); // gets the current string by finding the integer into the dictionary + nums.add(currInt); // finalOutput = currString; - String nextBinString = ""; - int nextInt= 0; - String nextString= ""; + String nextBinString = ""; // intializes the next string fr binary numbers + int nextInt= 0; + String nextString= ""; // initalizes next string for actual letters // String lastSymbolInDict = ""; - nextBinString = binString.substring(0, bitNum); - binString= binString.substring(bitNum); - nextInt = Integer.parseInt(nextBinString, 2); - nextString = dict.get(nextInt); - + nextBinString = binString.substring(0, bitNum); // takes the substring of the binString to get the next character after taking the substring of current + binString= binString.substring(bitNum); // chops string off + nextInt = Integer.parseInt(nextBinString, 2); // converts binary of nextBinString into integer + nums.add(nextInt); + int counter = 256; - while (binString.length()>= bitNum) + + while (binString.length()>= bitNum) // as long as the word has enough bits to convert into an intger { if (nextString!= null) { + String currBinString = binString.substring (0,bitNum); // takes the substring of the first probably 9 bits + binString= binString.substring(bitNum); // assings binString to the substring + int currInt = Integer.parseInt(currBinString, 2); // changes the binary code to an integer + nums.add(currInt); dict.put(counter, currString+ nextString.substring(0,1)); currString = nextString; } - else + else // this is the edge case { dict.put(counter, currString + currString.substring(0,1)); currString = currString + currString.substring(0,1); From ab2ba668a9c1666937ffe00d4bb3b9fe848840f3 Mon Sep 17 00:00:00 2001 From: lianawadhwani <89544220+lianawadhwani@users.noreply.github.com> Date: Thu, 23 Sep 2021 22:45:25 -0700 Subject: [PATCH 06/11] created new method that coverts binary into integers, and added comments --- src/LZWDecoder.class | Bin 2408 -> 1902 bytes src/LZWDecoder.java | 26 +++++++++++++++++++++++--- src/output | 0 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 src/output diff --git a/src/LZWDecoder.class b/src/LZWDecoder.class index c3a154199d971dada68016e7a0e408b4727921ae..aae08f993551b3a15aee8f915d7a3fe5bfeb234a 100644 GIT binary patch literal 1902 zcmc&#TUQ%Z6#h;Um|UhMq$Gv5v_*^NN}#2*5TuqC+GrrvP!RCaNiw8E!z3n?THd{^ zr9SureDTRwbxG)wwfq4-_>-#NnOuN^&k{0cX3sv~{`R-`+4<|$AAbUv#phl);8fsJ z(Su$A|F-sAOO`dW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X~Mns)jk)6boexx$(`k1<&=yX9&^!$p}$ zp{hj4lMgja%4`c2D|XGGvnS26rMq>9>rC@%fAI|Y*es`u@2JIQI4kSmzH6Lx9R0pP z+tpJ7alZ$bUANz&zqLP5-S+alwPRtL_Kq_XjEO39#e4LXK`*~<&D6) zNmnl}veZ2(1-AsYExTsatQh0AJ8IXhl21gPwChgMkZmEwnJZh<99;~*i?E>w@MYG z)|a>K#d_6WCoOOJob{UE)cvZl2K=fIzedKkRE+4A$|N&|ooSJg5<)=BS(f39RP)Z!9Cz4Mgk}sglK1Fm1YO;3;9m&)ZHYU5aEMaT1fo;is4ZQm!!2(w} z?m~oP7sWS_z()RcBgQtq13lQy?i|N6`BDLxpM^4;NA3KY^Bj7ZT2PI2n^9$&?jU(xRYBLv2R zF(nWrq30L{B;lBn2|mVtKO*=BA{g_XWP(!v|EKmKLdTQ?gVFA2s>QDI2**+@n$(nJ z+`!>{a`p*BN84hmv~$Hik29nCAWBs)WJue*kbcRa0tfhoJp>Jd4B`Qv9Kl{3#X)2+ zf-G|U49wyOZbEN_7|mI;+j~; z*3*j{q7OI4A?PBDlE`CD%%Ci8VP1U7{pVP~4Khh1@(-)(Z|r!9PY_kmt{}yK@oM7l zfrH6x6LpsP#ZP@JwKGiZ0F`Wdf%CJer^t^D&=p%77$0ch(yKg{84TDox{6NRVHP_p fd3%!@biQpv0Y%Oc-caJRfC_giSGOs72eJPEHB>=a diff --git a/src/LZWDecoder.java b/src/LZWDecoder.java index 2e57348..eab904a 100644 --- a/src/LZWDecoder.java +++ b/src/LZWDecoder.java @@ -5,6 +5,7 @@ import java.io.InputStream; import java.io.PrintWriter; import java.util.HashMap; +import java.util.*; public class LZWDecoder { @@ -24,7 +25,7 @@ public LZWDecoder(String binString, int bitNum, String outputFileName) throws IO // File binFile = new File (binFileName); // readBinFile(binFile); - decode(); + //decode(); writeToTxt(outputFileName); } @@ -44,8 +45,22 @@ public void readBinFile(File binFile) throws IOException } */ + public ArrayList getList () throws IOException{ + String binary = binString; // copies the binary string + String temp=""; // creates temp varibale + ArrayList nums= new ArrayList (); // creates an arraylist to put all the numbers when converting from binary to integers + while (binary.length()>=bitNum){ + int number=0; + temp=binary.substring(0,bitNum); // takes substring and sets to temp + number=Integer.parseInt(temp,2); // turns binary to integer number + nums.add(number); // adds the number into an arrayList of nums + binary=binary.substring(bitNum);// chops the string off + } - + return (nums); + } + + /* public void decode () { for (int x = 0; x<256; x++) // creating the dictionary @@ -110,7 +125,7 @@ public void decode () finalOutput+=dict.get(Integer.parseInt(currBinStringCopy, 2)); } } - + */ //writes the public void writeToTxt(String outputFileName) throws FileNotFoundException { @@ -118,6 +133,11 @@ public void writeToTxt(String outputFileName) throws FileNotFoundException output.print (finalOutput); output.close(); } + + public static void main (String [] args) throws IOException{ + LZWDecoder decoder = new LZWDecoder ("011000010110001001100011011000010110001001100011011000010110001001100011011000010110001001100011011000010110001001100011011000010110001001100011", 9, "output"); + System.out.println(decoder.getList()); + } // class GFG { // diff --git a/src/output b/src/output new file mode 100644 index 0000000..e69de29 From a0ac49053bcb9a72c34640300f388138c7955a79 Mon Sep 17 00:00:00 2001 From: lianawadhwani <89544220+lianawadhwani@users.noreply.github.com> Date: Thu, 23 Sep 2021 22:54:40 -0700 Subject: [PATCH 07/11] tried to make work better. Not very sucessful yet. Added more comments To see progress made please just run decode method. The encoder doesn't work. However, the decoder doesnt work either but it does print arraylist of numbers. Also timer is in the decoder method --- src/LZWDecoder.class | Bin 1902 -> 3235 bytes src/LZWDecoder.java | 106 +++++++++++++++++-------------------------- 2 files changed, 41 insertions(+), 65 deletions(-) diff --git a/src/LZWDecoder.class b/src/LZWDecoder.class index aae08f993551b3a15aee8f915d7a3fe5bfeb234a..9cee3250f0cabf2c0780212d46ec6f91550aae30 100644 GIT binary patch literal 3235 zcmc&$TW}NC8UBuLE3FnVishhi3l}H0Y#|K9AvPg^!JtI8N$l9QN!qNW#VnRrinJm) zy`&e?=F&^XOopdC1&_*()Z5vfu^C~*?K5bWul z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k zqU_fwutbZZ3nkIV`2fy4NpKj^+ejm>$lorZKoNYoDIwpy&)&k$|M0dg{*7Ap7Q$b% z%5O2%{29(WtyfM%%{vfD_P!>*)89nlPW>dDqFW#aWn!?%3bIx; zzDnxr__?R?G_eX$18F<~}^uM9rODZsL1)tAC!Ip@uC4Y&Yyx m^)J)GUr=EHzr?RNZshC@ruuu%`vd%%G?nY$;A8w2ss92gPW)T| delta 491 zcmYL_NlPP95XXPrNhh78jZSnlieSX$;DQGSM@5K^`@Sz3_t7{yE{WS!VQ>NU_LxuL zCs3pXg@L(x^LvQ*xro&*D7AEUyLFGBX7%Wa*2MW{ zVGs)vr_G|Bn1+$wS=-ukGMyG(_$0Hmk=jj~^r)!!PfnkPFSWmy-WN`Y0jGXY{qt6b zh8giQYB9#R`tPkZLrhvskx;XGX-1G~X8g=r%rURN8ujYZ_^qv~a^Ix3p$>fW9Tbb4 zE<+k}hsi`^K_Z<+u?X4jJC{7y|6s}Wg>LK>u1q1kWp!xQX-Q?9CD|*&aFCy3G6o(& zpUf#i+XJ getList () throws IOException{ return (nums); } - /* - public void decode () - { - for (int x = 0; x<256; x++) // creating the dictionary - { - char ch = (char)x; - dict.put(x, String.valueOf(ch)); - } - ArrayList nums= new ArrayList (); // creates an arraylist to put all the numbers when converting from binary to integers - String binStringCopy = binString; // makes copy of string - String currBinString = binString.substring (0,bitNum); // takes the substring of the first probably 9 bits - binString= binString.substring(bitNum); // assings binString to the substring - int currInt = Integer.parseInt(currBinString, 2); // changes the binary code to an integer - nums.add(currInt); -// finalOutput = currString; - - String nextBinString = ""; // intializes the next string fr binary numbers - int nextInt= 0; - String nextString= ""; // initalizes next string for actual letters - -// String lastSymbolInDict = ""; - - nextBinString = binString.substring(0, bitNum); // takes the substring of the binString to get the next character after taking the substring of current - binString= binString.substring(bitNum); // chops string off - nextInt = Integer.parseInt(nextBinString, 2); // converts binary of nextBinString into integer - nums.add(nextInt); - - int counter = 256; - - while (binString.length()>= bitNum) // as long as the word has enough bits to convert into an intger - { - - if (nextString!= null) - { - String currBinString = binString.substring (0,bitNum); // takes the substring of the first probably 9 bits - binString= binString.substring(bitNum); // assings binString to the substring - int currInt = Integer.parseInt(currBinString, 2); // changes the binary code to an integer - nums.add(currInt); - dict.put(counter, currString+ nextString.substring(0,1)); - currString = nextString; - - - - } - else // this is the edge case - { - dict.put(counter, currString + currString.substring(0,1)); - currString = currString + currString.substring(0,1); - } - - nextBinString = binString.substring(0, bitNum); - binString= binString.substring(bitNum); - nextDecimal = Integer.parseInt(nextBinString, 2); - nextString = dict.get(nextInt); - - counter++; - } - - for (int x = 0; x numbers = getList(); // calls other method to get arraylist of nums + int counter=256; // keeps track of how big the hash map is + HashMap map = new HashMap (); // intialized and delcres hash map + int current=0; + int next=0; + String word="";// this will eventually be the whole word that will get returned + String combined ="";// string that contains current and next as one string + String wordC=""; // the string version of the number of the current value + String wordN=""; // the string version of the number of the next value + for (int i=0; i<256; i++){ + map.put(i, ""+(char)i); // created dictionary assigning ascii values to the first 255 characters + } + int size=numbers.size(); + for (int i=0; i Date: Thu, 23 Sep 2021 22:55:38 -0700 Subject: [PATCH 08/11] added timer --- src/LZWDecoder.class | Bin 3235 -> 3421 bytes src/LZWDecoder.java | 4 ++++ 2 files changed, 4 insertions(+) diff --git a/src/LZWDecoder.class b/src/LZWDecoder.class index 9cee3250f0cabf2c0780212d46ec6f91550aae30..83cefb15603babd2ce24790819ec38c7cd27d593 100644 GIT binary patch delta 785 zcmY*WSx*yD6#i}(W;z{NihvjsYfZHcnqn|MsKmJRL4wglgZk!J2OOAAVP*={rFF+0 ze7-=Y?R*Z{Z@J2oA9^zN}(5yTOYU`O13= z?&E=kNfl{4buHI@)|b6%kt7%P8|WNjMCYNP4H9ohrEZX=}=4a zI903Qn?bdNxc4ntjlYmt>1za~Cko=XQ=v2?>`!Hwjq_r-^*{c_hy*8TTcV$O3N*QoeEJRaNKYAA^6$}GhAR?-bBRNg_=xb{$kFOh zr1TEQ+o{}C#)dLZ%|=6IT$m;zjX_KhgG{!MtW6U*XoO3-JeujRuEhYhVDQgGqqLjb e)a}C^Opvdn=q^3|k!PRaDdiNpKf?>WLgR0e@vbib delta 544 zcmY+B%WG3n5XOI#$9?4*Bq_#fXe9*&i&QDN@_|Yb!G$3BSY{D5HN8piy@~Hut+m!y z)nk3Xz?}=B3Q-hXxf1*n#Q#K`+)~8FIp55D-V#modRZedzq4iQoX>eK7_lnph)ZUpH7D22d+Vs&G?v}Y-}iWcv3ck- z#-f?GzYjhZL>!(9DG|Xx5CpYwU!xjDwaDg$X*ioRuY>{9bOy|4r#w2Po>ENfDNsz} zHIx#(%#{SoNuEV|)>L=Z*zR_jF}vKM;x$!dl$q7DhrOhgjoo9){&YuW&WP8y{-0)f z)(zFFt6ry%TfH$+aVNK+V$0w8U&BE*B;$_wn^ZI9m!?-*&Es;5+dWnn*sqJF6oZuJkB@Cp^=lr-kRd Date: Thu, 23 Sep 2021 22:56:32 -0700 Subject: [PATCH 09/11] no changes made just see summary below I copied and pasted my code into her program that is why it looks exaclty the same --- src/LZWDecoder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/LZWDecoder.java b/src/LZWDecoder.java index bbaaebc..fa714ea 100644 --- a/src/LZWDecoder.java +++ b/src/LZWDecoder.java @@ -117,6 +117,7 @@ public static void main (String [] args) throws IOException{ LZWDecoder decoder = new LZWDecoder ("011000010110001001100011011000010110001001100011011000010110001001100011011000010110001001100011011000010110001001100011011000010110001001100011", 9, "output"); System.out.println(decoder.getList()); System.out.println(decoder.decode()); + System.out.println("helloworld"); } // class GFG { From e32ca92814c85c793a833f0c3147d0864714f3da Mon Sep 17 00:00:00 2001 From: lianawadhwani <89544220+lianawadhwani@users.noreply.github.com> Date: Tue, 28 Sep 2021 13:03:35 -0700 Subject: [PATCH 10/11] working! --- src/LZWDecoder.class | Bin 3421 -> 3341 bytes src/LZWDecoder.java | 3 +-- src/Tester.class | Bin 911 -> 810 bytes src/Tester.java | 2 +- 4 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/LZWDecoder.class b/src/LZWDecoder.class index 83cefb15603babd2ce24790819ec38c7cd27d593..ac6c9e36af33bb5b4785de7d661c014bc70570a5 100644 GIT binary patch delta 441 zcmY*TIZH!f5S)!k-r-XuF^XptFVH4Iu<-zo6oRⅅThN7)U&@u@Eex#Hbq+@B2QY zQ4z7QvJ(6W{s>DOag!k82fI7FGt4(1rIAwo?fdx!KpRpi{mWWc>+yKK9(mF-AiZQk z_MYZAW=j;PSS0A9e$xz01%l=XH`!+?!AbidZL(dN$Uo3=h$98Z27EZ-u=46YBM_;$ zAXtb9M(@~|KiF*!heH04f@?O_M(Yisk^^cbKdI#vQHf^3l9U6^3@$=(W-eoeKUEho zD_RT1xI?RPt_ouXAuiR4F64lDTpJShU2CQ_CcUuiPm}dt7i}2x@&n&{bRUU$GB+w> zyV3s7(2c6JhzE=Y(aadd?q917XxPGbnw0=^un7YC`N8OM-NEmOJYpdw7eY*WJv6rE nRk!wG8ov&4iMk`41-sajnJ;Kx^rxAAj!U`evR@&ITa^3&h)Z0% delta 563 zcmcgnxlTe+5IytY@fMzl5I16iXpF|h1cH%5DO@OQZKSoJ5=oR;Sea<034&Y&_k9JI z5IYMiD;pbI8~;KJ;_yf$#@?HI=ge~E%-odc-J`#hAD;jW;l8AQS{F0^K)}x@P(}95 zn9aZBU4I9Q9yu>w0jv=hhXhR)inkvcl^u1^|r+?YILs?dK@nm2c8sccc3>uO65#QqM4t6Vi<}C2$5@SR}jj_5CdxVNY m2UJlqe4*M(7VL3e!afcd9qb)4_uRCXxaOSBaRE2DL+dx!Hfo*# diff --git a/src/LZWDecoder.java b/src/LZWDecoder.java index fa714ea..6cf3110 100644 --- a/src/LZWDecoder.java +++ b/src/LZWDecoder.java @@ -114,10 +114,9 @@ public static void main (String [] args) throws IOException{ System.out.println(System.nanoTime()); System.out.print("time in milliseconds = "); System.out.println(System.currentTimeMillis()); - LZWDecoder decoder = new LZWDecoder ("011000010110001001100011011000010110001001100011011000010110001001100011011000010110001001100011011000010110001001100011011000010110001001100011", 9, "output"); + LZWDecoder decoder = new LZWDecoder ("001100001001100010001100011100000000", 9, "output"); System.out.println(decoder.getList()); System.out.println(decoder.decode()); - System.out.println("helloworld"); } // class GFG { diff --git a/src/Tester.class b/src/Tester.class index 6e380f982a38af75ae82db49763430c4e965d61c..623b92baf807abb18c47ad72303bf568fe383530 100644 GIT binary patch delta 148 zcmeBYU&Y3C>ff$?3=9l53^p6Nt};$GX7XpWoZQT0;$_Id1Qcfgl8g+j3~WHs7|4?a z(u_cwRcku~<3=EZk--E=f}|N3SQt1NOc~68T0lw*fqZ5lZ9AEf*@hRPR*8XQayYZR VC_jTaSPvtE1yHvYkj=zk4FH(~5mx{J delta 233 zcmZ3**3Zs$>ff$?3=9l549*+5t}?1~`9y`gq$cO5q!w{7m@qPMhNKpkxMk*~8gVfg zGMMo&urio4GH6UZC@kUWla*MOsGpOVm#!aNQk0pOZmk){&R{wDE@L30!(@FX6E6z} zCZO32K#~!tkqt;%0eP}Onh{8|YHep=+z4baGFSsikTe4W3j-(6F}6T0Af-(}Z7e|A zYw}tq8>!t4hLJh~oI=Li8BF~U8r2v$Cx2s-m*i#eWZ-A80~^A~U=K9T5y)m@Z~_3& CB`9hD diff --git a/src/Tester.java b/src/Tester.java index 33d1eee..6fbfa76 100644 --- a/src/Tester.java +++ b/src/Tester.java @@ -10,7 +10,7 @@ public static void main(String[] args) throws IOException { LZW compressor = new LZW(9, "TestFile"); String testString = compressor.encode("lzw-file1.txt"); System.out.println (testString); - LZWDecoder expander = new LZWDecoder (testString, 9, "TestFile2"); + //LZWDecoder expander = new LZWDecoder (testString, 9, "TestFile2"); } } From f109bdb7197f098df3d503a5f53eca32d748e97a Mon Sep 17 00:00:00 2001 From: lianawadhwani <89544220+lianawadhwani@users.noreply.github.com> Date: Tue, 28 Sep 2021 13:09:21 -0700 Subject: [PATCH 11/11] added catch., try exception thing --- src/LZWDecoder.class | Bin 3341 -> 3428 bytes src/LZWDecoder.java | 6 ++++++ 2 files changed, 6 insertions(+) diff --git a/src/LZWDecoder.class b/src/LZWDecoder.class index ac6c9e36af33bb5b4785de7d661c014bc70570a5..7211596cb1a5ff1072805a4e35b7679ad606ef06 100644 GIT binary patch delta 1898 zcmY*aX>3$g6#njPZ|2PdO4})&(!c=4ZZovdTFaD{rBG<;f)-j@L_2Km8VKwUl!c;YTVkO|qCF7{1_lL`A$=E)C|E8R zh}?{Fm{nBbaRpTxo3Xh5bL^TZQIkOts z(Iqhrao8y73rFKYJCaO$A~dL{-4h8!DC>(x`s1Ej+ItaIS*L><4&g9?=;vFhOYB9( zP5Sv!y(Y&PTv1bThaD+_dDTZ%bfk zYoIqwnCdj&;tJlGL7m37=@S8OQE{_eB(mf=TdsId-moQSUsZ7pA1fHqbNq?)Dc>)= zAs~bup9z?R5YQSUkzlMo9Eit*bpEBxu$PEYS!1tVeU7X*;XL0=WEtxm%rj<*3&xyp z?5$uKaEf{tDU~pD2dt1|_JY(1X8A3*uq3lMjnYvnT3CoeETZz8R4ReWF^f_c<{$^z zbm&Gd7GeSQmKd7FSd8UZinpja52kSnEef0pDg|F~SmeOlJhagLCB9@bG3Zz>rzXK{ zEcqJQ&6&9^cTwIoh83-)X;e^_aRokem8I0IuhUrB;4LepM1AfeBJ1yWnQG{AnxQ^1*jaY{@Y{qp4`Z+K?L2kW%VO(=Lb%~{a7#B)i&NO!3LtPpH#^`cddj8*AUDo_zteFb5{~jv+cAtykGi+n$ zaNFGuvxQl?gWZ5%@ul*4>Q;=8o5Tnz9zYWp>}!>vu&IDCeQW76cLlaRX&usX_N zcpt&2xotj|HjQAyh0QR!@3!4UYAXAuNeQ5V+205UHeoKWxNJ0$9-CQ(X40pHhDl8G=Q5@5zc4eN(aAdwXhL@Xp%(}Fuae88P)@a%(1dGXZ z-~h*iL~w|WdYE-M!e7Brvi}&fe0&60u5m--880mM^$8Cx z0`VcCv4;O_nWn0+qgBH)Ea(52>Z~g@v|$zZo5R-C8rGnL51Lo>c+jaK3Lk@%PaR0A z@Ssb>I;g*vlXrfuu9ULtTfjN5OuE>394MrP6_PYNE&OcwEC10&{A-n9C(I1pymPrAbY} zA>L~7RX)jJ%@zy8Mas{Pr$z3E`9VvdK7*se>#_eSW{*&RR>N~R&Tm@W)gsIngn?VZ ziwx?HWICPQo6V&Y{7*|Uq_*vgCx;8EY$h+`%mfnFbd8@dOzJMg;=7`;;f=9@bdsO5 zHnKPQ_txU%5f$&^JsB57x!&g+BjsDP8xHKvA2MViNmDFNxBJUNHlx-k4kOn60I0c(f9!M3j^6@>H>7H#&IkCt?f-u^Cdk+4igJadVAppnq$LqQWN5W;;} zKyilY@-C#dUxa4*EvGx#M)&+R(w+j-EmX+x8lNXLA?Pw$uT$_;%`z3H$*@b9LBNB^?DJ*>^{B zfCSfI?{yrkusKSX@l+=rQ(czoI8t6cqvLsDa)Rc&k<2DnO5hi*GG-(); // intializes the hash map this.bitNum = bitNum; this.binString = binString; @@ -28,6 +29,11 @@ public LZWDecoder(String binString, int bitNum, String outputFileName) throws IO //decode(); writeToTxt(outputFileName); + } + catch(Exception e) { + System.out.println("File inputed not found"); + } + } //reads the binary file into a string. not working, so I've bypassed this method for now and just input a binary string into the constructor.