From 7bdfd7a1349f30225da06871435c721a31fa87c8 Mon Sep 17 00:00:00 2001 From: SoumyajitBasu1988 Date: Tue, 31 May 2016 14:54:38 +0530 Subject: [PATCH] Adding some more files to the Dummy Base --- bin/Zipper.class | Bin 0 -> 3330 bytes .../tryouts/producer_consumer/Consumer.class | Bin 0 -> 1580 bytes .../tryouts/producer_consumer/Message.class | Bin 0 -> 501 bytes .../tryouts/producer_consumer/Producer.class | Bin 0 -> 1681 bytes .../producer_consumer/Producer_Consumer.class | Bin 0 -> 1301 bytes src/Zipper.java | 86 ++++++++++++++++++ .../tryouts/producer_consumer/Consumer.java | 31 +++++++ .../tryouts/producer_consumer/Message.java | 15 +++ .../tryouts/producer_consumer/Producer.java | 31 +++++++ .../producer_consumer/Producer_Consumer.java | 17 ++++ 10 files changed, 180 insertions(+) create mode 100644 bin/Zipper.class create mode 100644 bin/com/tryouts/producer_consumer/Consumer.class create mode 100644 bin/com/tryouts/producer_consumer/Message.class create mode 100644 bin/com/tryouts/producer_consumer/Producer.class create mode 100644 bin/com/tryouts/producer_consumer/Producer_Consumer.class create mode 100644 src/Zipper.java create mode 100644 src/com/tryouts/producer_consumer/Consumer.java create mode 100644 src/com/tryouts/producer_consumer/Message.java create mode 100644 src/com/tryouts/producer_consumer/Producer.java create mode 100644 src/com/tryouts/producer_consumer/Producer_Consumer.java diff --git a/bin/Zipper.class b/bin/Zipper.class new file mode 100644 index 0000000000000000000000000000000000000000..ac5a0fdec584c0ab519ec6a71c59054fe42ff475 GIT binary patch literal 3330 zcma)8TXz%J8Qmj|HL@765eO_GiDMwhHlRSLX=IudY}2UtR?9Y#35Bsewg==Hb!HSW zy`&eKr0JbDZAqK7>CJ6=NuY@o$CRecTf0{C(ENn1KK2Lnq3%9sWLw6tRv$E)bIy0& z-~PTcfBo+}w*fqY_cVkQM8>RQ(R4Ma3K}mMPaEliVNa(A#xIx?zJlnKRWN%kkFSlr z^0?$%g|yh|R8XI@rftJ7xu$|WcN`xJ*3w$ecP)F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9U?d`JDuOaD$r%XnINoKx`9(sN0*jL(Y4 z=jl2A1;#dyX#asSzI1~*M({WMos%m}RDe<91L7TFFbnPKnHH)DBi=Pw3(sRPQ1^n{2#nAMKz0(D<4#=Nks9yWK4vT zU%?BkMFVc(tN0pYN#Z8Hj&HDTSzaUGq+A_+cjH_5HW_%0Hm>12tk{cW#dqbCIaS}@ zr`GrIeOmc}^cq=W5Sj)>!&wd2H5}47&oxeaEa5a_cbrJ6Cp8!v*iZNmqDyGJr~ds2 zujmU8S5;!l&$NI&_$T8Q9g`z5Ub>DZ!HPD%zg)(vW&CsjzYO6t*RNg2VgCKDZ+|`$ zx!qA0?oj8EOhyvw;eNJDOTL|4yFqGSRh5LAsC#wkUxMC2(OQ@~&_zc*1o{c==GRFI zrwD%^SEo4d24w--WE`BY+MPcQPx^? K;Gd=ZU;YOGwiAp1 literal 0 HcmV?d00001 diff --git a/bin/com/tryouts/producer_consumer/Consumer.class b/bin/com/tryouts/producer_consumer/Consumer.class new file mode 100644 index 0000000000000000000000000000000000000000..1b5f73bf86e8b8f6944c7e0a798cc93bd9274091 GIT binary patch literal 1580 zcma)6?{Cvq6g{s=abjFrLJNa!P%@xNN->48m8L7u@?$_s3n>+RLay_ax=rlhJR|xK zjn5!xVUwmweB;CZpb4>^7dwJz)0#;3d+++*bI-l^ynOid>+b+AV$HySz!^7a+A7=* zBGtBAVNi=)89s3Xza2GYXfGxk18ISgP3M_oHypoiFRyP(R~gtRko# z$1!f;M9-vGH$v&uESyB1V{JF2Y_Xcc9nJm}&KNk|<6hlvE7`O#fdXr!sszU3wtIoS z5_-O>Dgrjk21)`)K5K_&3SuGh8Z{YaaF)VKil~h@<8jW8n<(O(ZlF!rWJn!7#?c&} ziD_Ika6#a7UlOtKJuV5Db*U232#gkrG376zb?P52%-}L5<+NJTuL(^37l(hvCPkGs zMA^cePMA?a%-O^|t{S*PC3Kq6+a?Rwbgf29cdp^@$0BYRxGs?2`(9bNiCdhNa<+J_ zdW(whZ#je8bdb+IW#TTD3{<)_I;G!u?#h<(0^h%3We zsIhw;DMrR5dg#qSp$>I`mz-82b+Z~op(}5C`VVEOtLSsOaH^5H`3&-5dywHfOAQae zmFIp2N9l2llKKW$ zd3!bS5-E^CLOg{NSjGy`&NDvV&C%mN9?({$=Lpgtkuos-7mhzNa5qi+D(wS!_z%E$ BlKB7t literal 0 HcmV?d00001 diff --git a/bin/com/tryouts/producer_consumer/Message.class b/bin/com/tryouts/producer_consumer/Message.class new file mode 100644 index 0000000000000000000000000000000000000000..7595d657b1165174b9f8394dd2f4a9581b3a7037 GIT binary patch literal 501 zcma)2u};G<5Pg@V4J|1xr3F?7L|Y^>FoIZ+Iu#g-x*|8Vf~zJ$wu8i9fdoQg-~;$5 z#3e*x=z^>}`}v;Vz4O=i$0vYO?E7#Chf$Vqw4O(LAWwC&jQhV52VoBXO`>&JLe_Y;bNc8Z&lyZ;swMj^EIF zDLHMax_ z+mBSg5`=y`a%A|u<9q$6C&S9dNMax*kbPkPU{|`f*QwmvdLSKT;DA7GPkJZvJbSAv z1*RTFGU9orHhhhg+pW;36NRDlRAs5_I}cs2b6aaw1u_k{Feh+quiy<8vWiQQ+ilCx#7SiJcFMwOd_d;yAdp^L;6!n)6mvgpo-tHaBhFel zhw}ny<;RZ#M~eT4P&bc~Ca^3pJ1Wv^CRsca^SEeWVXRx5_d{v7EmUxct=aEN8L%S7 z8>QAke1wk;ToyRJf1_IX1fQ~UL8SiUJ{||U&){=hG4REh`^I)($)1HO7K!Gh5gpUv z`kXM=Q%qXgy=oe4)7+?b?Lsf^;wuGBQAy|iwS^_kli87K)Z_Z?8%_9ifrU3w@)qJ( zv1Z^~_TVu0@n9_6&@3B)j<4&PsA1heU0`mn{A-?)VHgEUwy*!_$UwQiXW^D^@0lU4 zp={@2GqfGfwQ#xCNIA}&MZEN@3+ZJx(?BM$Ely&UJaMGvvWxCG8G3{d5rY>!T>ja z5+a{%|MKeT6FSLb87r)09C(>w0a?1+e53D_}yU2tJG-XF73ByIgiv!Oo>;xhNJ-@3`)4wULd7e{*EdM-1`^cT&^hq literal 0 HcmV?d00001 diff --git a/bin/com/tryouts/producer_consumer/Producer_Consumer.class b/bin/com/tryouts/producer_consumer/Producer_Consumer.class new file mode 100644 index 0000000000000000000000000000000000000000..9f26a703ae71a7ce62dd4a04e6f8582365310c2f GIT binary patch literal 1301 zcmb7ETTc@~7(GK@G?FlP~%} z6Px%0{87d;Evwd;P+#Wy&3Dc>=gfTn@%0;kdw6D`Pr!2gx)rL1ABBN+qWr_ik?O$l zy&$SfWxa`4HqTcKBn5_#?Ni&T*1d^Nnq0AtGbQUS} z3k;QAPi{x`id4IHr6vV(W#6%Dd$w}*{CqJP9=UI z26>F>!`BFCcDVcv*@f0-H*sP9Sb+@2F=k+@ONQMeCGEouCQ;PT(*mRC&~268MV_Z` znNT|BRu(f_lvEJfDokS*rh&PxggcEOl=Up;u|Q4f4uO297T2dMTrcF+O1oYfz!F^) z`=n?UW1dC2$&o=IgW{2WDvK2mqn1)&rWXmAOPgQ7?9q8NT!J3D_&|IeJW%L%eB&f`{Zw&*LVka-iP5bV#`WO(b_@~ literal 0 HcmV?d00001 diff --git a/src/Zipper.java b/src/Zipper.java new file mode 100644 index 0000000..78e11ee --- /dev/null +++ b/src/Zipper.java @@ -0,0 +1,86 @@ +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +public class Zipper +{ + List fileList; + private static final String OUTPUT_ZIP_FILE = "/Users/soumyajit/Desktop/Screenshots.zip"; + private static final String SOURCE_FOLDER = "/Users/soumyajit/Desktop/CIP_App/TestReports/Screenshot"; + + Zipper() + { + fileList = new ArrayList(); + } + public static void main(String [] args) + { + Zipper zip = new Zipper(); + zip.generateFileList(new File(SOURCE_FOLDER)); + zip.zipit(OUTPUT_ZIP_FILE); + } + + public void zipit(String zipFile) + { + byte[] buffer = new byte[1024]; + + try + { + FileOutputStream fos = new FileOutputStream(zipFile); + ZipOutputStream zos = new ZipOutputStream(fos); + + System.out.println("Output to zip: " +zipFile); + for(String file: this.fileList) + { + System.out.println("File added: " +file); + ZipEntry ze = new ZipEntry(file); + zos.putNextEntry(ze); + + FileInputStream fis = new FileInputStream(SOURCE_FOLDER + File.separator + file); + + int len; + while((len = fis.read(buffer)) > 0) + { + zos.write(buffer,0,len); + } + + fis.close(); + } + + zos.closeEntry(); + zos.close(); + + System.out.println("Done"); + } + catch(IOException e) + { + e.printStackTrace(); + } + } + + public void generateFileList(File node) + { + if(node.isFile()) + { + fileList.add(generateZipEntry(node.getAbsoluteFile().toString())); + } + + if(node.isDirectory()) + { + String[] subnode = node.list(); + for(String filename: subnode) + { + generateFileList(new File(node,filename)); + } + } + } + + String generateZipEntry(String file) + { + return file.substring(SOURCE_FOLDER.length()+1,file.length()); + } +} diff --git a/src/com/tryouts/producer_consumer/Consumer.java b/src/com/tryouts/producer_consumer/Consumer.java new file mode 100644 index 0000000..e0b2586 --- /dev/null +++ b/src/com/tryouts/producer_consumer/Consumer.java @@ -0,0 +1,31 @@ +package com.tryouts.producer_consumer; + +import java.util.concurrent.BlockingQueue; + +public class Consumer implements Runnable +{ +public BlockingQueue queue; + + public Consumer(BlockingQueue q) + { + this.queue = q; + } + + @Override + public void run() + { + try + { + Message msg; + while((msg = queue.take()).getMessage() != "exit") + { + Thread.sleep(10); + System.out.println("Consumed message: " +msg.getMessage()); + } + } + catch(Exception e) + { + e.printStackTrace(); + } + } +} diff --git a/src/com/tryouts/producer_consumer/Message.java b/src/com/tryouts/producer_consumer/Message.java new file mode 100644 index 0000000..f5b1730 --- /dev/null +++ b/src/com/tryouts/producer_consumer/Message.java @@ -0,0 +1,15 @@ +package com.tryouts.producer_consumer; + +public class Message +{ + String msg; + public Message(String str) + { + this.msg = str; + } + + public String getMessage() + { + return msg; + } +} diff --git a/src/com/tryouts/producer_consumer/Producer.java b/src/com/tryouts/producer_consumer/Producer.java new file mode 100644 index 0000000..c47b4f9 --- /dev/null +++ b/src/com/tryouts/producer_consumer/Producer.java @@ -0,0 +1,31 @@ +package com.tryouts.producer_consumer; + +import java.util.concurrent.BlockingQueue; + +public class Producer implements Runnable +{ + public BlockingQueue queue; + + public Producer(BlockingQueue q) + { + this.queue = q; + } + @Override + public void run() + { + for(int i=0;i<100;i++) + { + Message msg = new Message(""+i); + try + { + Thread.sleep(i); + queue.put(msg); + System.out.println("Produced message: " +msg.getMessage()); + } + catch(InterruptedException e) + { + e.printStackTrace(); + } + } + } +} diff --git a/src/com/tryouts/producer_consumer/Producer_Consumer.java b/src/com/tryouts/producer_consumer/Producer_Consumer.java new file mode 100644 index 0000000..64b0588 --- /dev/null +++ b/src/com/tryouts/producer_consumer/Producer_Consumer.java @@ -0,0 +1,17 @@ +package com.tryouts.producer_consumer; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; + +public class Producer_Consumer +{ + public static void main(String [] args) + { + BlockingQueue queue = new ArrayBlockingQueue(2); + Producer prod = new Producer(queue); + Consumer con = new Consumer(queue); + new Thread(prod).start(); + new Thread(con).start(); + System.out.println("Producer / Consumer processes have been started"); + } +}