Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/arranger/jarl/test/CompTest.java


1   package com.arranger.jarl.test;
2   
3   import com.arranger.jarl.io.CompressedOutputStream;
4   import com.arranger.jarl.util.IOUtil;
5   import junit.framework.TestCase;
6   
7   import java.io.*;
8   import java.util.zip.GZIPInputStream;
9   
10  /**
11   * CompTest created on Mar 8, 2003
12   */
13  public class CompTest extends TestCase {
14  
15      protected static String m_inputImageFile = "src/com/arranger/jarl/test/sample.bmp";
16      protected static String m_tempImageFile = "src/com/arranger/jarl/test/sample.compressed";
17      protected static String m_outputImageFile = "src/com/arranger/jarl/test/sample_result.bmp";
18  
19      public void testComp() throws Exception {
20  
21          InputStream inputStream = IOUtil.getInputStream(m_inputImageFile);
22          ByteArrayOutputStream baos = new ByteArrayOutputStream(inputStream.available());
23          IOUtil.copyStream(inputStream, baos);
24          inputStream.close();
25  
26          OutputStream outputStream = new FileOutputStream(new File(m_tempImageFile).getAbsolutePath());
27          CompressedOutputStream compressedOutputStream = new CompressedOutputStream(outputStream);
28  
29          ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
30          IOUtil.copyStream(bais, compressedOutputStream);
31          compressedOutputStream.close();
32  
33  
34          //read it back in (decompress it)
35          inputStream = IOUtil.getInputStream(m_tempImageFile);
36          inputStream = new GZIPInputStream(inputStream);
37          baos = new ByteArrayOutputStream();
38          IOUtil.copyStream(inputStream, baos);
39          inputStream.close();
40  
41          //save it
42          outputStream = new FileOutputStream(new File(m_outputImageFile).getAbsolutePath());
43          bais = new ByteArrayInputStream(baos.toByteArray());
44          IOUtil.copyStream(bais, outputStream);
45          outputStream.close();
46      }
47  }