forked from Corefinder89/SampleJavaCodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding some more files to the Dummy Base
- Loading branch information
SoumyajitBasu1988
committed
May 31, 2016
1 parent
9d66ed1
commit 7bdfd7a
Showing
10 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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<String>(); | ||
} | ||
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.tryouts.producer_consumer; | ||
|
||
import java.util.concurrent.BlockingQueue; | ||
|
||
public class Consumer implements Runnable | ||
{ | ||
public BlockingQueue<Message> queue; | ||
|
||
public Consumer(BlockingQueue<Message> 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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.tryouts.producer_consumer; | ||
|
||
import java.util.concurrent.BlockingQueue; | ||
|
||
public class Producer implements Runnable | ||
{ | ||
public BlockingQueue<Message> queue; | ||
|
||
public Producer(BlockingQueue<Message> 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(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Message> queue = new ArrayBlockingQueue<Message>(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"); | ||
} | ||
} |