Skip to content

Commit

Permalink
Adding some more files to the Dummy Base
Browse files Browse the repository at this point in the history
  • Loading branch information
SoumyajitBasu1988 committed May 31, 2016
1 parent 9d66ed1 commit 7bdfd7a
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 0 deletions.
Binary file added bin/Zipper.class
Binary file not shown.
Binary file added bin/com/tryouts/producer_consumer/Consumer.class
Binary file not shown.
Binary file added bin/com/tryouts/producer_consumer/Message.class
Binary file not shown.
Binary file added bin/com/tryouts/producer_consumer/Producer.class
Binary file not shown.
Binary file not shown.
86 changes: 86 additions & 0 deletions src/Zipper.java
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());
}
}
31 changes: 31 additions & 0 deletions src/com/tryouts/producer_consumer/Consumer.java
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();
}
}
}
15 changes: 15 additions & 0 deletions src/com/tryouts/producer_consumer/Message.java
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;
}
}
31 changes: 31 additions & 0 deletions src/com/tryouts/producer_consumer/Producer.java
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();
}
}
}
}
17 changes: 17 additions & 0 deletions src/com/tryouts/producer_consumer/Producer_Consumer.java
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");
}
}

0 comments on commit 7bdfd7a

Please sign in to comment.