[hornetq-commits] JBoss hornetq SVN: r9961 - in branches/Branch_Large_Message_Compression: src/main/org/hornetq/utils and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Dec 1 09:30:18 EST 2010


Author: gaohoward
Date: 2010-12-01 09:30:17 -0500 (Wed, 01 Dec 2010)
New Revision: 9961

Removed:
   branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/GZipUtil.java
   branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/unit/util/GZipUtilTest.java
Modified:
   branches/Branch_Large_Message_Compression/src/main/org/hornetq/core/client/impl/ClientMessageImpl.java
Log:
removed unused classes


Modified: branches/Branch_Large_Message_Compression/src/main/org/hornetq/core/client/impl/ClientMessageImpl.java
===================================================================
--- branches/Branch_Large_Message_Compression/src/main/org/hornetq/core/client/impl/ClientMessageImpl.java	2010-12-01 14:25:42 UTC (rev 9960)
+++ branches/Branch_Large_Message_Compression/src/main/org/hornetq/core/client/impl/ClientMessageImpl.java	2010-12-01 14:30:17 UTC (rev 9961)
@@ -26,7 +26,6 @@
 import org.hornetq.core.logging.Logger;
 import org.hornetq.core.message.BodyEncoder;
 import org.hornetq.core.message.impl.MessageImpl;
-import org.hornetq.utils.GZipUtil;
 import org.hornetq.utils.HornetQBufferInputStream;
 
 /**

Deleted: branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/GZipUtil.java
===================================================================
--- branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/GZipUtil.java	2010-12-01 14:25:42 UTC (rev 9960)
+++ branches/Branch_Large_Message_Compression/src/main/org/hornetq/utils/GZipUtil.java	2010-12-01 14:30:17 UTC (rev 9961)
@@ -1,418 +0,0 @@
-/*
- * Copyright 2010 Red Hat, Inc.
- * Red Hat licenses this file to you under the Apache License, version
- * 2.0 (the "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *    http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.  See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package org.hornetq.utils;
-
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
-
-import org.hornetq.api.core.HornetQException;
-
-/**
- * A GZipUtil
- *
- * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- * @author <a href="mailto:hgao at redhat.com">Howard Gao</a>
- *
- */
-public class GZipUtil
-{
-   
-   public static InputStream createZipInputStream(InputStream input) throws HornetQException
-   {
-      try
-      {
-         return new GZipPipe(input, 1024);
-      }
-      catch (IOException e)
-      {
-         throw new HornetQException(HornetQException.LARGE_MESSAGE_ERROR_BODY, e.getMessage(), e);
-      }
-   }
-   
-   public static InputStream createUnZipInputStream(InputStream input) throws HornetQException
-   {
-      try
-      {
-         return new GZIPInputStream(input);
-      }
-      catch (IOException e)
-      {
-         throw new HornetQException(HornetQException.LARGE_MESSAGE_ERROR_BODY, e.getMessage(), e);
-      }
-   }
-   
-   public static OutputStream createZipOutputStream(OutputStream out) throws HornetQException
-   {
-      try
-      {
-         return new GZipOutput(out);
-      }
-      catch (IOException e)
-      {
-         throw new HornetQException(HornetQException.LARGE_MESSAGE_ERROR_BODY, e.getMessage(), e);
-      }      
-   }
-
-   public static class GZipOutput extends OutputStream
-   {
-      private OutputStream target;
-      private GZIPInputStream zipIn;
-      private DynamicInputStream receiver;
-
-      public GZipOutput(OutputStream out) throws IOException
-      {
-         target = out;
-         receiver = new DynamicInputStream(1024, 50);
-      }
-
-      public void write(int b) throws IOException
-      {
-         receiver.writeBuffer(b);
-      }
-      
-      public void close() throws IOException
-      {
-         zipIn = new GZIPInputStream(receiver);
-         byte[] buffer = new byte[1024];
-         int n = zipIn.read(buffer);
-         while (n != -1)
-         {
-            if (n > 0)
-            {
-               target.write(buffer, 0, n);
-            }
-            n = zipIn.read(buffer);
-         }
-         target.close();
-      }
-      
-   }
-   
-   public static class DynamicInputStream extends InputStream
-   {
-      private List<byte[]> writeBuffer;
-      private int bufferSize;
-      private int counter, index;
-      private int readIndex, readCounter;
-      
-      public DynamicInputStream(int size, int cache)
-      {
-         bufferSize = size;
-         writeBuffer = new ArrayList<byte[]>(cache);
-         for (int i = 0; i < cache; i++)
-         {
-            writeBuffer.add(new byte[size]);
-         }
-         counter = 0;
-         index = 0;
-         readIndex = 0;
-         readCounter = 0;
-      }
-
-      //read the buffer. If buffer is empty, return -1
-      public int read() throws IOException
-      {
-         int result = -1;
-         
-         if (index > readIndex)
-         {
-            result = writeBuffer.get(readIndex)[readCounter++] & 0xFF;
-            if (readCounter == bufferSize)
-            {
-               readCounter = 0;
-               readIndex ++;
-            }
-         }
-         else if (index == readIndex)
-         {
-            if (counter > readCounter)
-            {
-               result = writeBuffer.get(readIndex)[readCounter++] & 0xFF;
-            }
-         }
-         return result;
-      }
-      
-      public void writeBuffer(int b)
-      {
-         writeBuffer.get(index)[counter++] = (byte)b;
-         if (counter == bufferSize)
-         {
-            index++;
-            if (index == writeBuffer.size())
-            {
-               writeBuffer.add(new byte[bufferSize]);
-            }
-            counter = 0;
-         }
-      }
-      
-   }
-   
-   /*
-    * we keep a list of byte arrays. when writing, we start with the first array.
-    * when getBuffer() is called, the returned value is subject to the following rules:
-    * 
-    * 1. if not closed, return the last full array. then update flags and pointers.
-    * 2. if closed, return all the remaining.
-    */
-   public static class DynamicOutputStream extends OutputStream
-   {
-
-      private List<byte[]> writeBuffer;
-      private int bufferSize;
-      private int counter, index;
-      private int readIndex;
-      private boolean closed;
-      
-      public DynamicOutputStream(int size, int cache)
-      {
-         bufferSize = size;
-         writeBuffer = new ArrayList<byte[]>(cache);
-         for (int i = 0; i < cache; i++)
-         {
-            writeBuffer.add(new byte[size]);
-         }
-         counter = 0;
-         index = 0;
-         readIndex = 0;
-         closed = false;
-      }
-
-      public void write(int b) throws IOException
-      {
-         writeBuffer.get(index)[counter++] = (byte)b;
-         if (counter == bufferSize)
-         {
-            index++;
-            if (index == writeBuffer.size())
-            {
-               writeBuffer.add(new byte[bufferSize]);
-            }
-            counter = 0;
-         }
-      }
-      
-      public void close() throws IOException
-      {
-         closed = true;
-      }
-
-      /*
-       * logic: 
-       * if index > readIndex, return readIndex, then readIndex++
-       * if index == readIndex, then return zero length byte[]; if closed, return the remaining.
-       * 
-       * if closed and no more data, returns null.
-       */
-      public byte[] getBuffer()
-      {
-         byte[] result = new byte[0];
-         if (index > readIndex)
-         {
-            result = writeBuffer.get(readIndex);
-            writeBuffer.set(readIndex, null);
-            readIndex++;
-         }
-         else if (index == readIndex)
-         {
-            if (closed)
-            {
-               if (counter == 0)
-               {
-                  result = null;
-               }
-               else
-               {
-                  result = new byte[counter];
-                  System.arraycopy(writeBuffer.get(index), 0, result, 0, result.length);
-                  counter = 0;
-               }
-            }
-         }
-         return result;
-      }
-   }
-   
-   public static class GZipPipe extends InputStream
-   {
-      private InputStream input;
-      private byte[] readBuffer;
-      private GZIPOutputStream zipOut;
-      private DynamicOutputStream receiver;
-      private int readPointer;
-      private byte[] buffer;
-      
-      public GZipPipe(InputStream raw, int size) throws IOException
-      {
-         input = raw;
-         readBuffer = new byte[size];
-         receiver = new DynamicOutputStream(size, 50);
-         zipOut = new GZIPOutputStream(receiver);
-         readPointer = 0;
-         buffer = read1();
-      }
-      
-      public int read() throws IOException
-      {
-         if (buffer == null)
-         {
-            return -1;
-         }
-         
-         int val = buffer[readPointer] & 0xFF;
-         readPointer++;
-         if (readPointer == buffer.length)
-         {
-            buffer = read1();
-            readPointer = 0;
-         }
-
-         return val;
-      }
-      
-      public byte[] read1() throws IOException
-      {
-         byte[] result = receiver.getBuffer();
-         if (result == null)
-         {
-            return null;
-         }
-         else if (result.length > 0)
-         {
-            return result;
-         }
-         
-         int n = input.read(readBuffer);
-         while (true)
-         {
-            if (n > 0)
-            {
-               zipOut.write(readBuffer, 0, n);
-               result = receiver.getBuffer();
-               if ((result != null) && (result.length > 0))
-               {
-                  break;
-               }
-               n = input.read(readBuffer);
-            }
-            else
-            {
-               zipOut.close();
-               result = receiver.getBuffer();
-               break;
-            }
-         }
-         return result;
-      }
-   }
-
-   public static void main(String[] args) throws HornetQException, IOException
-   {
-      long begin = System.currentTimeMillis();
-/*
-      FileInputStream input = new FileInputStream("/home/howard/tmp/jbm.log.1");
-      FileOutputStream output = new FileOutputStream("/home/howard/tmp/output3.zip");
-      GZIPOutputStream zipOut = new GZIPOutputStream(output);
-      
-      byte[] buffer = new byte[1024];
-      
-      int n = input.read(buffer);
-      
-      int counter = 0;
-      
-      while (n > 0)
-      {
-         zipOut.write(buffer, 0, n);
-         counter += n;
-         n = input.read(buffer);
-      }
-      zipOut.close();
-      
-      System.out.println("----total output: " + counter);
-*/
-      zip();
-/*
-      FileInputStream input = new FileInputStream("/home/howard/tmp/jbm.log.1");
-      FileOutputStream output = new FileOutputStream("/home/howard/tmp/output.zip");
-      ExecutorService service = Executors.newCachedThreadPool();
-      InputStream result = GZipUtil.pipeGZip(input, true, service);
-      
-      byte[] buffer = new byte[2048];
-      int n = result.read(buffer);
-      System.out.println("got first data");
-      
-      while (n > 0)
-      {
-         output.write(buffer);
-         n = result.read(buffer);
-      }
-*/
-      long end = System.currentTimeMillis();
-      
-      
-      System.out.println("done. time: " + (end - begin));
-   }
-   
-   public static void zip() throws IOException
-   {
-      FileInputStream input = new FileInputStream("/home/howard/tmp/jbm.log.1");
-      FileOutputStream output = new FileOutputStream("/home/howard/tmp/myzip.zip");
-      GZipPipe pipe = new GZipPipe(input, 2048);
-      
-      byte[] buffer = new byte[2048];
-      
-      int n = pipe.read(buffer);
-      
-      while (n != -1)
-      {
-         if (n > 0)
-         {
-            output.write(buffer, 0, n);
-         }
-         n = pipe.read(buffer);
-      }
-
-      output.close();
-   }
-
-   public static void unzip() throws IOException
-   {
-      FileInputStream input = new FileInputStream("/home/howard/tmp/myzip.zip");
-      FileOutputStream output = new FileOutputStream("/home/howard/tmp/myzip.out");
-
-      GZIPInputStream zipIn = new GZIPInputStream(input);
-      
-      byte[] buffer = new byte[1024];
-      
-      int n = zipIn.read(buffer);
-      
-      while (n > 0)
-      {
-         //System.out.println("buffer size: " + buffer.length);
-         output.write(buffer, 0, n);
-         n = zipIn.read(buffer);
-      }
-
-      output.close();
-   }
-
-}

Deleted: branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/unit/util/GZipUtilTest.java
===================================================================
--- branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/unit/util/GZipUtilTest.java	2010-12-01 14:25:42 UTC (rev 9960)
+++ branches/Branch_Large_Message_Compression/tests/src/org/hornetq/tests/unit/util/GZipUtilTest.java	2010-12-01 14:30:17 UTC (rev 9961)
@@ -1,242 +0,0 @@
-/*
- * Copyright 2010 Red Hat, Inc.
- * Red Hat licenses this file to you under the Apache License, version
- * 2.0 (the "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *    http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied.  See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package org.hornetq.tests.unit.util;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Random;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
-
-import org.hornetq.core.logging.Logger;
-import org.hornetq.tests.util.UnitTestCase;
-import org.hornetq.utils.GZipUtil;
-import org.hornetq.utils.GZipUtil.GZipPipe;
-
-/**
- * A GZipUtilTest
- *
- * @author Howard Gao
- *
- *
- */
-public class GZipUtilTest extends UnitTestCase
-{
-   private static final Logger log = Logger.getLogger(GZipUtilTest.class);
-
-   //create a 10M file, zip it into another file
-   //then unzip it and compare the result with original file
-   public void testZipFunction() throws Exception
-   {
-      this.recreateDirectory(this.getTestDir());
-      
-      File originalFile = new File(this.getTestDir(), "gzipUtilTest_file.txt");
-      File zippedFile = new File(this.getTestDir(), "gzipUtilTest_file.zip");
-      
-      FileOutputStream originalOut = new FileOutputStream(originalFile);
-      FileOutputStream zippedOut = new FileOutputStream(zippedFile);
-      
-      //now create the file
-      Random r = new Random();
-      final int size = 1024 * 10;
-      byte[] writeBuffer = new byte[1024];
-      
-      for (int i = 0; i < size; i++)
-      {
-         int b = r.nextInt(256);
-         for (int j = 0; j < 1024; j++)
-         {
-            writeBuffer[j] = (byte)b;
-         }
-         originalOut.write(writeBuffer);       
-      }
-      originalOut.close();
-      
-      //now zip it
-      GZipPipe pipe = new GZipPipe(new FileInputStream(originalFile), 2048);
-      byte[] buffer = new byte[2048];
-      
-      int n = pipe.read(buffer);
-      while (n != -1)
-      {
-         if (n > 0)
-         {
-            zippedOut.write(buffer, 0, n);
-         }
-         n = pipe.read(buffer);
-      }
-      zippedOut.close();
-
-      //now unzip it and compare
-      log.debug("zipped file Size: " + zippedFile.length());
-      GZIPInputStream zippedInput = new GZIPInputStream(new FileInputStream(zippedFile));
-      FileInputStream originalInput = new FileInputStream(originalFile);
-      
-      ArrayList<Integer> fromZip = new ArrayList<Integer>();
-      ArrayList<Integer> original = new ArrayList<Integer>();
-      
-      byte[] readBuffer = new byte[2048];
-      int count = zippedInput.read(readBuffer);
-      
-      while (count != -1)
-      {
-         for (int i = 0; i < count; i++)
-         {
-            fromZip.add(readBuffer[i] & 0xFF);
-         }
-         count = zippedInput.read(readBuffer);
-      }
-      zippedInput.close();
-
-      count = originalInput.read(readBuffer);
-      while (count != -1)
-      {
-         for (int i = 0; i < count; i++)
-         {
-            original.add(readBuffer[i] & 0xFF);
-         }
-         count = originalInput.read(readBuffer);
-      }      
-      originalInput.close();
-      
-      log.debug("fromZip: " + fromZip.size());
-      compareByteArray(fromZip, original);
-      
-      originalFile.delete();
-      zippedFile.delete();
-   }
-   
-   //create a 10M file, zip it into another file
-   //load it into an input stream and feed to the 
-   //GZipOutput. Then compare the result
-   public void testUnzipFunction() throws Exception
-   {
-      this.recreateDirectory(this.getTestDir());
-      
-      File originalFile = new File(this.getTestDir(), "gzipUtilTest_file1.txt");
-      File zippedFile = new File(this.getTestDir(), "gzipUtilTest_file1.zip");
-      File unzippedFile = new File(this.getTestDir(), "gzipUtilTest_unzipped.txt");
-      
-      FileOutputStream originalOut = new FileOutputStream(originalFile);
-      FileOutputStream zippedOut = new FileOutputStream(zippedFile);
-      
-      //now create the file
-      Random r = new Random();
-      final int size = 1024 * 10;
-      byte[] writeBuffer = new byte[1024];
-      
-      for (int i = 0; i < size; i++)
-      {
-         int b = r.nextInt(256);
-         for (int j = 0; j < 1024; j++)
-         {
-            writeBuffer[j] = (byte)b;
-         }
-         originalOut.write(writeBuffer);       
-      }
-      originalOut.close();
-      
-      log.info("file created.");
-      
-      //now zip it
-      GZIPOutputStream gzipOut = new GZIPOutputStream(zippedOut);
-      FileInputStream originalIn = new FileInputStream(originalFile);
-      
-      byte[] buffer = new byte[2048];
-      
-      int n = originalIn.read(buffer);
-      while (n != -1)
-      {
-         if (n > 0)
-         {
-            gzipOut.write(buffer, 0, n);
-         }
-         n = originalIn.read(buffer);
-      }
-      gzipOut.close();
-
-      log.info("file zipped.");
-
-      //get a zipped input stream
-      FileInputStream zippedInput = new FileInputStream(zippedFile);
-      
-      FileOutputStream unzipOut = new FileOutputStream(unzippedFile);
-      
-      OutputStream newOut = GZipUtil.createZipOutputStream(unzipOut);
-      
-      n = zippedInput.read(buffer);
-      while (n != -1)
-      {
-         if (n > 0)
-         {
-            newOut.write(buffer, 0, n);
-         }
-         n = zippedInput.read(buffer);
-      }
-      newOut.close();
-      
-      log.info("file unzipped");
-      
-      //compare original and unzipped
-      FileInputStream originalInput = new FileInputStream(originalFile);
-      FileInputStream unzippedInput = new FileInputStream(unzippedFile);
-      
-      ArrayList<Integer> fromZip = new ArrayList<Integer>();
-      ArrayList<Integer> original = new ArrayList<Integer>();
-      
-      byte[] readBuffer = new byte[2048];
-      int count = originalInput.read(readBuffer);
-      
-      while (count != -1)
-      {
-         for (int i = 0; i < count; i++)
-         {
-            original.add(readBuffer[i] & 0xFF);
-         }
-         count = originalInput.read(readBuffer);
-      }
-      originalInput.close();
-
-      count = unzippedInput.read(readBuffer);
-      
-      while (count != -1)
-      {
-         for (int i = 0; i < count; i++)
-         {
-            fromZip.add(readBuffer[i] & 0xFF);
-         }
-         count = unzippedInput.read(readBuffer);
-      }
-      unzippedInput.close();
-
-      compareByteArray(fromZip, original);
-      
-      originalFile.delete();
-      zippedFile.delete();
-      unzippedFile.delete();
-   }
-   
-   private void compareByteArray(ArrayList<Integer> b1, ArrayList<Integer> b2)
-   {
-      assertEquals(b1.size(), b2.size());
-      
-      for (int i = 0; i < b1.size(); i++)
-      {
-         assertEquals(b1.get(i), b2.get(i));
-      }
-   }
-}



More information about the hornetq-commits mailing list