Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ZipToolTest.java

Go to the documentation of this file.
00001 package net.threebit.utils.sosc.test;
00002 
00003 /*
00004         Copyright 2003 Shawn Deleurme
00005         Copyright 2003 Kevin O'Donnell
00006 
00007         This program is free software; you can redistribute it and/or modify
00008         it under the terms of the GNU General Public License as published by
00009         the Free Software Foundation; either version 2 of the License, or
00010         (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016 
00017         You should have received a copy of the GNU General Public License
00018         along with this program; if not, write to the Free Software
00019         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 import java.io.*;
00023 import java.sql.*;
00024 import java.util.*;
00025 import java.util.zip.*;
00026 import java.util.logging.*;
00027 import junit.framework.*;
00028 import net.threebit.utils.sosc.*;
00029 
00033 public class ZipToolTest extends TestCase {
00034 
00035         private Logger logger = Logger.getLogger("net.threebit.utils.sosc.test");
00036 
00037         public void test10() throws Exception {
00038 
00039                 ZipTool zt = new ZipTool(Deflater.NO_COMPRESSION);
00040                 final InputStream zipIn = zt.getInputStream();
00041                 final File zipFile = File.createTempFile("ZipToolTest10",".zip");
00042                 final File inFile = File.createTempFile("ZipToolTest10",".zip");
00043                 Thread t1 = new Thread() {
00044                         public void run() {
00045                                 try {
00046                                         FileOutputStream fos = new FileOutputStream(zipFile);
00047                                         StreamTool.dumpStream(zipIn,fos);
00048                                         fos.close();
00049                                 }
00050                                 catch (Exception e) { logger.throwing("","",e); }
00051                         }
00052                 };
00053                 t1.start();
00054 
00055                 PrintWriter pw = new PrintWriter( new FileOutputStream( inFile ) );
00056                 pw.println("This is a compression test");
00057                 pw.close();
00058 
00059                 zt.addFile( new FileInputStream(inFile), "inFile.txt" );
00060                 zt.close();
00061 
00062                 t1.join();
00063 
00064                 logger.info("test10: zipFile: " + zipFile.getAbsolutePath() + "; inFile: " + inFile.getAbsolutePath());
00065 
00066 
00067 
00068 
00069         }
00070 
00071         /*
00072         public void test0() throws Exception {
00073                 System.out.println("test0: start");
00074                 final ZipTool zt = new ZipTool(java.util.zip.Deflater.NO_COMPRESSION);
00075                 Thread t = new Thread() {
00076                         public void run() {
00077                                 try {
00078                                         for (int x = 1; x <= 10; x++) {
00079                                                 System.out.println("Adding file " + x);
00080                                                 zt.addFile( new FileInputStream("/home/kevino/ttt/" + x + ".pdf"), x + ".pdf" );
00081                                         }
00082                                         System.out.println("Closing ZIP");
00083                                         zt.close();
00084                                 }
00085                                 catch (Exception e) { e.printStackTrace(); }
00086                         }
00087                 };
00088                 t.start();
00089 
00090                 InputStream is = zt.getInputStream();
00091                 OutputStream os = new FileOutputStream("ZipToolTest-test0.zip");
00092                 int i;
00093                 byte[] b = new byte[1024];
00094                 try { while ((i = is.read(b)) != -1) { os.write(b); } }
00095                 catch (IOException e) { }
00096                 os.flush();
00097                 os.close();
00098                 System.out.println("test0: done");
00099         }
00100         */
00101 
00102         /*
00103         public void test1() throws Exception {
00104 
00105                 final ZipTool zt = new ZipTool(java.util.zip.Deflater.NO_COMPRESSION);
00106                 Thread t = new Thread() {
00107                         public void run() {
00108                                 try {
00109                                         System.out.println("adding fiel");
00110                                         OutputStream out = zt.addFile("testFile.txt");
00111                                         PrintWriter p = new PrintWriter(out);
00112                                         p.println("test");
00113                                         p.flush();
00114                                         out.close();
00115                                         System.out.println("Done adding file");
00116                                         zt.close();
00117                                 }
00118                                 catch (Exception e) {
00119                                         e.printStackTrace();
00120                                 }
00121                         }
00122                 };
00123                 t.start();
00124 
00125                 InputStream is = zt.getInputStream();
00126                 OutputStream os = new FileOutputStream("ZipToolTest.zip");
00127                 int i;
00128                 byte[] b = new byte[1024];
00129                 try { while ((i = is.read(b)) != -1) { os.write(b); } }
00130                 catch (IOException e) { }
00131                 os.flush();
00132                 os.close();
00133         }
00134         */
00135 
00136 }

Generated on Mon Jul 14 17:19:20 2003 for SOSC by doxygen1.2.15