[mule-scm] [mule][25309] branches/mule-3.1.x: Reverted commit 25308.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[mule-scm] [mule][25309] branches/mule-3.1.x: Reverted commit 25308.

damian.bakarcic
[mule][25309] branches/mule-3.1.x: Reverted commit 25308.

Diff

Modified: branches/mule-3.1.x/core/src/main/java/org/mule/transformer/compression/GZipCompressTransformer.java (25308 => 25309)


--- branches/mule-3.1.x/core/src/main/java/org/mule/transformer/compression/GZipCompressTransformer.java	2013-02-26 15:56:35 UTC (rev 25308)
+++ branches/mule-3.1.x/core/src/main/java/org/mule/transformer/compression/GZipCompressTransformer.java	2013-02-26 19:03:37 UTC (rev 25309)
@@ -12,6 +12,7 @@
 
 import org.mule.api.transformer.TransformerException;
 import org.mule.transformer.types.DataTypeFactory;
+import org.mule.util.IOUtils;
 import org.mule.util.SerializationUtils;
 import org.mule.util.compression.GZipCompression;
 
@@ -32,8 +33,7 @@
         this.registerSourceType(DataTypeFactory.create(Serializable.class));
         this.registerSourceType(DataTypeFactory.BYTE_ARRAY);
         this.registerSourceType(DataTypeFactory.INPUT_STREAM);
-        // No type checking for the return type by default. It could either be a byte array or an input stream.
-        this.setReturnDataType(DataTypeFactory.OBJECT);
+        this.setReturnDataType(DataTypeFactory.BYTE_ARRAY);
     }
 
     @Override
@@ -41,23 +41,28 @@
     {
         try
         {
-            if (src instanceof InputStream)
+            byte[] data = null;
+            if (src instanceof byte[])
             {
-                return getStrategy().compressInputStream((InputStream) src);
+                data = (byte[]) src;
             }
-            else
+            else if (src instanceof InputStream)
             {
-                byte[] data;
-                if (src instanceof byte[])
+                InputStream input = (InputStream)src;
+                try
                 {
-                    data = (byte[]) src;
+                    data = IOUtils.toByteArray(input);
                 }
-                else
+                finally
                 {
-                    data = SerializationUtils.serialize((Serializable) src);
+                    input.close();
                 }
-                return getStrategy().compressByteArray(data);
             }
+            else
+            {
+                data = SerializationUtils.serialize((Serializable) src);
+            }
+            return this.getStrategy().compressByteArray(data);
         }
         catch (IOException ioex)
         {

Modified: branches/mule-3.1.x/core/src/main/java/org/mule/transformer/compression/GZipUncompressTransformer.java (25308 => 25309)


--- branches/mule-3.1.x/core/src/main/java/org/mule/transformer/compression/GZipUncompressTransformer.java	2013-02-26 15:56:35 UTC (rev 25308)
+++ branches/mule-3.1.x/core/src/main/java/org/mule/transformer/compression/GZipUncompressTransformer.java	2013-02-26 19:03:37 UTC (rev 25309)
@@ -10,10 +10,10 @@
 
 package org.mule.transformer.compression;
 
-import org.mule.api.transformer.DataType;
 import org.mule.api.transformer.TransformerException;
 import org.mule.config.i18n.MessageFactory;
 import org.mule.transformer.types.DataTypeFactory;
+import org.mule.util.IOUtils;
 import org.mule.util.SerializationUtils;
 import org.mule.util.compression.GZipCompression;
 
@@ -31,37 +31,47 @@
         this.setStrategy(new GZipCompression());
         this.registerSourceType(DataTypeFactory.BYTE_ARRAY);
         this.registerSourceType(DataTypeFactory.INPUT_STREAM);
-        // No type checking for the return type by default. It could either be a byte array or an input stream.
-        this.setReturnDataType(DataTypeFactory.OBJECT);
+        this.setReturnDataType(DataTypeFactory.BYTE_ARRAY);
     }
 
     @Override
     public Object doTransform(Object src, String outputEncoding) throws TransformerException
     {
+        byte[] buffer;
+
         try
         {
+            byte[] input = null;
             if (src instanceof InputStream)
             {
-                return getStrategy().uncompressInputStream((InputStream) src);
-            }
-            else
-            {
-                byte[] buffer = getStrategy().uncompressByteArray((byte[]) src);
-                DataType<?> returnDataType = getReturnDataType();
-                if (!DataTypeFactory.OBJECT.equals(returnDataType) && !DataTypeFactory.BYTE_ARRAY.equals(getReturnDataType()))
+                InputStream inputStream = (InputStream) src;
+                try
                 {
-                    return SerializationUtils.deserialize(buffer, muleContext);
+                    input = IOUtils.toByteArray(inputStream);
                 }
-                else
+                finally
                 {
-                    return buffer;
+                    inputStream.close();
                 }
             }
+            else
+            {
+                input = (byte[]) src;
+            }
+
+            buffer = getStrategy().uncompressByteArray(input);
         }
         catch (IOException e)
         {
             throw new TransformerException(
                     MessageFactory.createStaticMessage("Failed to uncompress message."), this, e);
         }
+
+        if (!DataTypeFactory.BYTE_ARRAY.equals(getReturnDataType()))
+        {
+            return SerializationUtils.deserialize(buffer, muleContext);
+        }
+
+        return buffer;
     }
 }

Modified: branches/mule-3.1.x/core/src/main/java/org/mule/util/compression/CompressionStrategy.java (25308 => 25309)


--- branches/mule-3.1.x/core/src/main/java/org/mule/util/compression/CompressionStrategy.java	2013-02-26 15:56:35 UTC (rev 25308)
+++ branches/mule-3.1.x/core/src/main/java/org/mule/util/compression/CompressionStrategy.java	2013-02-26 19:03:37 UTC (rev 25309)
@@ -11,7 +11,6 @@
 package org.mule.util.compression;
 
 import java.io.IOException;
-import java.io.InputStream;
 
 /**
  * <code>CompressionStrategy</code> is a base interface for Different compression
@@ -33,48 +32,9 @@
      */
     String SERVICE_ID = "META-INF/services/org.mule.util.compression.CompressionStrategy";
 
-    /**
-     * Compresses a byte array.
-     *
-     * @param bytes The byte array to compress.
-     * @return The compressed byte array.
-     * @throws IOException If an I/O error has occurred.
-     */
     byte[] compressByteArray(byte[] bytes) throws IOException;
 
-    /**
-     * Compresses an {@link InputStream}.
-     *
-     * @param is The {@link InputStream} to compress.
-     * @return The compressed {@link InputStream}.
-     * @throws IOException If an I/O error has occurred.
-     */
-    InputStream compressInputStream(InputStream is) throws IOException;
-
-    /**
-     * Uncompresses a compressed byte array.
-     *
-     * @param bytes The byte array to uncompress.
-     * @return The uncompressed byte array.
-     * @throws IOException If an I/O error has occurred.
-     */
     byte[] uncompressByteArray(byte[] bytes) throws IOException;
 
-    /**
-     * Uncompresses a compressed {@link InputStream}.
-     *
-     * @param is The compressed {@link InputStream}.
-     * @return The uncompressed {@link InputStream}.
-     * @throws IOException If an I/O error has occurred.
-     */
-    InputStream uncompressInputStream(InputStream is) throws IOException;
-
-    /**
-     * Checks whether a byte array has been compressed or not.
-     *
-     * @param bytes The byte array.
-     * @return True if the byte array is compressed, false otherwise.
-     * @throws IOException If an I/O error has occurred.
-     */
     boolean isCompressed(byte[] bytes) throws IOException;
 }

Deleted: branches/mule-3.1.x/core/src/main/java/org/mule/util/compression/GZIPCompressorInputStream.java (25308 => 25309)


--- branches/mule-3.1.x/core/src/main/java/org/mule/util/compression/GZIPCompressorInputStream.java	2013-02-26 15:56:35 UTC (rev 25308)
+++ branches/mule-3.1.x/core/src/main/java/org/mule/util/compression/GZIPCompressorInputStream.java	2013-02-26 19:03:37 UTC (rev 25309)
@@ -1,177 +0,0 @@
-/*
- * $Id$
- * --------------------------------------------------------------------------------------
- * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
- *
- * The software in this package is published under the terms of the CPAL v1.0
- * license, a copy of which has been included with this distribution in the
- * LICENSE.txt file.
- */
-
-package org.mule.util.compression;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.CRC32;
-import java.util.zip.CheckedInputStream;
-import java.util.zip.Deflater;
-import java.util.zip.DeflaterInputStream;
-
-/**
- * Implements an input stream for compressing input data in the GZIP compression format.
- */
-public class GZIPCompressorInputStream extends DeflaterInputStream
-{
-    // GZIP header magic number.
-    private final static int GZIP_MAGIC = 0x8b1f;
-
-    // Writes GZIP member header.
-    private final static byte[] HEADER = {
-        (byte) GZIP_MAGIC,                // Magic number (short)
-        (byte)(GZIP_MAGIC >> 8),          // Magic number (short)
-        Deflater.DEFLATED,                // Compression method (CM)
-        0,                                // Flags (FLG)
-        0,                                // Modification time MTIME (int)
-        0,                                // Modification time MTIME (int)
-        0,                                // Modification time MTIME (int)
-        0,                                // Modification time MTIME (int)
-        0,                                // Extra flags (XFLG)
-        0                                 // Operating system (OS)
-    };
-
-    // Trailer length in bytes.
-    private final static int TRAILER_LENGTH = 8;
-
-    // If true, the GZIP trailer has been written.
-    private boolean trailerWritten = false;
-
-    // Internal buffer for GZIP header and trailer.
-    private Buffer buffer;
-
-    /**
-     * Helper inner class containing the length and position of the internal buffer.
-     */
-    private class Buffer
-    {
-        public byte[] data;
-        public int position;
-        public int length;
-
-        /**
-         * Creates a new buffer initializing it with the GZIP header content.
-         */
-        public Buffer()
-        {
-            data = new byte[Math.max(HEADER.length, TRAILER_LENGTH)];
-            System.arraycopy(HEADER, 0, data, 0, HEADER.length);
-            position = 0;
-            length = HEADER.length;
-        }
-
-        /**
-         * Returns the amount of bytes that are left to be read from the buffer.
-         *
-         * @return The byte counts to be read.
-         */
-        int getByteCountRemainder()
-        {
-            return length - position;
-        }
-    }
-
-    /**
-     * Creates a new {@link GZIPCompressorInputStream} from an uncompressed {@link InputStream}.
-     *
-     * @param in The uncompressed {@link InputStream}.
-     */
-    public GZIPCompressorInputStream(InputStream in)
-    {
-        super(new CheckedInputStream(in, new CRC32()), new Deflater(Deflater.DEFAULT_COMPRESSION, true));
-        buffer = new Buffer();
-    }
-
-    public int read(byte b[], int off, int len) throws IOException
-    {
-        // Check if there are bytes left to be read from the internal buffer. This is used to provide the header
-        // or trailer, and always takes precedence.
-        int count;
-        if (buffer.getByteCountRemainder() > 0)
-        {
-            // Write data from the internal buffer into b.
-            count = Math.min(len, buffer.getByteCountRemainder());
-            System.arraycopy(buffer.data, buffer.position, b, off, count);
-
-            // Advance the internal buffer position as "count" bytes have already been read.
-            buffer.position += count;
-            return count;
-        }
-
-        // Attempt to read compressed input data.
-        count = super.read(b, off, len);
-        if (count > 0)
-        {
-            return count;
-        }
-
-        /* If the stream has reached completion, write out the GZIP trailer and re-attempt
-         * the read */
-        if (count <= 0 && !trailerWritten)
-        {
-            buffer.position = 0;
-            buffer.length = writeTrailer(buffer.data, buffer.position);
-            trailerWritten = true;
-            return read(b, off, len);
-        }
-        else
-        {
-            return count;
-        }
-    }
-
-    /**
-     * Writes GZIP member trailer to a byte array, starting at a given offset.
-     *
-     * @param buf The buffer to write the trailer to.
-     * @param offset The offset from which to start writing.
-     * @return The amount of bytes that were written.
-     * @throws IOException If an I/O error is produced.
-     */
-    private int writeTrailer(byte[] buf, int offset) throws IOException
-    {
-        int count = writeInt((int) ((CheckedInputStream) this.in).getChecksum().getValue(), buf, offset); // CRC-32 of uncompr. data
-        count += writeInt(def.getTotalIn(), buf, offset + 4); // Number of uncompr. bytes
-        return count;
-    }
-
-    /**
-     * Writes integer in Intel byte order to a byte array, starting at a given offset.
-     *
-     * @param i The integer to write.
-     * @param buf The buffer to write the integer to.
-     * @param offset The offset from which to start writing.
-     * @return The amount of bytes written.
-     * @throws IOException If an I/O error is produced.
-     */
-    private int writeInt(int i, byte[] buf, int offset) throws IOException
-    {
-        int count = writeShort(i & 0xffff, buf, offset);
-        count += writeShort((i >> 16) & 0xffff, buf, offset + 2);
-        return count;
-    }
-
-    /**
-     * Writes short integer in Intel byte order to a byte array, starting at a given offset.
-     *
-     * @param s The short to write.
-     * @param buf The buffer to write the integer to.
-     * @param offset The offset from which to start writing.
-     * @return The amount of bytes written.
-     * @throws IOException If an I/O error is produced.
-     */
-    private int writeShort(int s, byte[] buf, int offset) throws IOException
-    {
-        buf[offset] = (byte)(s & 0xff);
-        buf[offset + 1] = (byte)((s >> 8) & 0xff);
-        return 2;
-    }
-}

Modified: branches/mule-3.1.x/core/src/main/java/org/mule/util/compression/GZipCompression.java (25308 => 25309)


--- branches/mule-3.1.x/core/src/main/java/org/mule/util/compression/GZipCompression.java	2013-02-26 15:56:35 UTC (rev 25308)
+++ branches/mule-3.1.x/core/src/main/java/org/mule/util/compression/GZipCompression.java	2013-02-26 19:03:37 UTC (rev 25309)
@@ -12,7 +12,6 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.zip.GZIPInputStream;
 import java.util.zip.GZIPOutputStream;
 
@@ -116,11 +115,6 @@
         }
     }
 
-    public InputStream compressInputStream(InputStream is) throws IOException
-    {
-        return new GZIPCompressorInputStream(is);
-    }
-
     /**
      * Used for uncompressing a byte array into a uncompressed byte array using GZIP
      * 
@@ -191,9 +185,4 @@
         }
     }
 
-    public InputStream uncompressInputStream(InputStream is) throws IOException
-    {
-        return new GZIPInputStream(is);
-    }
-
 }

Modified: branches/mule-3.1.x/core/src/test/java/org/mule/transformer/compression/GZipTransformerStreamTestCase.java (25308 => 25309)


--- branches/mule-3.1.x/core/src/test/java/org/mule/transformer/compression/GZipTransformerStreamTestCase.java	2013-02-26 15:56:35 UTC (rev 25308)
+++ branches/mule-3.1.x/core/src/test/java/org/mule/transformer/compression/GZipTransformerStreamTestCase.java	2013-02-26 19:03:37 UTC (rev 25309)
@@ -10,11 +10,7 @@
 
 package org.mule.transformer.compression;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
 import org.mule.api.transformer.TransformerException;
-import org.mule.util.IOUtils;
 import org.mule.util.SerializationUtils;
 
 import java.io.ByteArrayInputStream;
@@ -23,24 +19,23 @@
 
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 public class GZipTransformerStreamTestCase extends GZipTransformerTestCase
 {
     
     @Test
     public void testStreamingCompression() throws TransformerException
     {
-        GZipCompressTransformer transformer = (GZipCompressTransformer) super.getTransformer();
+        GZipCompressTransformer transformer = new GZipCompressTransformer();
         
-        InputStream uncompressedInputStream = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
+        InputStream input = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
 
-        // Compress input data.
-        InputStream compressedInputStream = (InputStream) transformer.transform(uncompressedInputStream);
-
-        byte[] compressedBytes = (byte[]) getResultData();
-        assertTrue(Arrays.equals(compressedBytes, IOUtils.toByteArray(compressedInputStream)));
-
-        IOUtils.closeQuietly(uncompressedInputStream);
-        IOUtils.closeQuietly(compressedInputStream);
+        byte[] expected = (byte[]) this.getResultData();
+        byte[] result = (byte[]) transformer.transform(input);
+        
+        assertTrue(Arrays.equals(expected, result));
     }
 
     @Test
@@ -48,37 +43,12 @@
     {
         GZipUncompressTransformer transformer = new GZipUncompressTransformer();
         transformer.setMuleContext(muleContext);
-
-        InputStream compressedInputStream = new ByteArrayInputStream((byte[]) getResultData());
-
-        // Decompress the input data.
-        InputStream decompressedInputStream = (InputStream) transformer.transform(compressedInputStream);
-
-        assertEquals(TEST_DATA, SerializationUtils.deserialize(IOUtils.toByteArray(decompressedInputStream)));
-
-        IOUtils.closeQuietly(compressedInputStream);
-        IOUtils.closeQuietly(decompressedInputStream);
+        
+        InputStream input = new ByteArrayInputStream((byte[]) this.getResultData());
+        byte[] resultBytes = (byte[]) transformer.transform(input);
+        assertEquals(TEST_DATA, SerializationUtils.deserialize(resultBytes));
     }
 
-    @Test
-    public void testStreamingCompressionDecompression() throws TransformerException
-    {
-        GZipCompressTransformer compressTransformer = (GZipCompressTransformer) super.getTransformer();
-        GZipUncompressTransformer decompressTransformer = new GZipUncompressTransformer();
-        decompressTransformer.setMuleContext(muleContext);
-
-        InputStream input = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
-
-        // Compress the input data.
-        InputStream compressedInputStream = (InputStream) compressTransformer.transform(input);
-        // Decompress the input data.
-        InputStream decompressedInputStream = (InputStream) decompressTransformer.transform(compressedInputStream);
-
-        assertEquals(SerializationUtils.deserialize(IOUtils.toByteArray(decompressedInputStream)), TEST_DATA);
-
-        IOUtils.closeQuietly(compressedInputStream);
-        IOUtils.closeQuietly(decompressedInputStream);
-    }
 }
 
 

Deleted: branches/mule-3.1.x/tests/integration/src/test/java/org/mule/test/transformers/GZipTransformerFunctionalTestCase.java (25308 => 25309)


--- branches/mule-3.1.x/tests/integration/src/test/java/org/mule/test/transformers/GZipTransformerFunctionalTestCase.java	2013-02-26 15:56:35 UTC (rev 25308)
+++ branches/mule-3.1.x/tests/integration/src/test/java/org/mule/test/transformers/GZipTransformerFunctionalTestCase.java	2013-02-26 19:03:37 UTC (rev 25309)
@@ -1,81 +0,0 @@
-/*
- * $Id$
- * --------------------------------------------------------------------------------------
- * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
- *
- * The software in this package is published under the terms of the CPAL v1.0
- * license, a copy of which has been included with this distribution in the
- * LICENSE.txt file.
- */
-
-package org.mule.test.transformers;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import org.mule.api.MuleMessage;
-import org.mule.module.client.MuleClient;
-import org.mule.tck.junit4.FunctionalTestCase;
-import org.mule.util.IOUtils;
-import org.mule.util.SerializationUtils;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
-import org.junit.Test;
-
-/**
- * Functional test case for the GZipCompressTransformer and GZipUncompressTransformer.
- */
-public class GZipTransformerFunctionalTestCase extends FunctionalTestCase
-{
-    private static final String TEST_DATA = "the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog";
-
-    @Override
-    protected String getConfigResources()
-    {
-        return "org/mule/test/transformers/gzip-transformer-functional-test.xml";
-    }
-
-    @Test
-    public void testCompressDecompressByteArray() throws Exception
-    {
-        byte[] testDataByteArray = SerializationUtils.serialize(TEST_DATA);
-        MuleClient client = new MuleClient(muleContext);
-
-        // Compress input.
-        MuleMessage compressedResponse = client.send("vm://compressInput", testDataByteArray, null);
-        assertNotNull(compressedResponse);
-        assertTrue(compressedResponse.getPayload() instanceof byte[]);
-
-        // Decompress response.
-        MuleMessage uncompressedResponse = client.send("vm://decompressInput", compressedResponse.getPayload(), null);
-        assertNotNull(uncompressedResponse);
-        assertTrue(uncompressedResponse.getPayload() instanceof byte[]);
-
-        String uncompressedStr = (String) SerializationUtils.deserialize((byte[]) uncompressedResponse.getPayload());
-        assertEquals(TEST_DATA, uncompressedStr);
-    }
-
-    @Test
-    public void testCompressDecompressInputStream() throws Exception
-    {
-        ByteArrayInputStream bis = new ByteArrayInputStream(SerializationUtils.serialize(TEST_DATA));
-        MuleClient client = new MuleClient(muleContext);
-
-        // Compress input.
-        MuleMessage compressedResponse = client.send("vm://compressInput", bis, null);
-        assertNotNull(compressedResponse);
-        assertTrue(compressedResponse.getPayload() instanceof InputStream);
-
-        // Decompress response.
-        MuleMessage uncompressedResponse = client.send("vm://decompressInput", compressedResponse.getPayload(), null);
-        assertNotNull(uncompressedResponse);
-        assertTrue(uncompressedResponse.getPayload() instanceof InputStream);
-
-        byte[] uncompressedByteArray = IOUtils.toByteArray((InputStream) uncompressedResponse.getPayload());
-        String uncompressedStr = (String) SerializationUtils.deserialize(uncompressedByteArray);
-        assertEquals(TEST_DATA, uncompressedStr);
-    }
-}

Deleted: branches/mule-3.1.x/tests/integration/src/test/resources/org/mule/test/transformers/gzip-transformer-functional-test.xml (25308 => 25309)


--- branches/mule-3.1.x/tests/integration/src/test/resources/org/mule/test/transformers/gzip-transformer-functional-test.xml	2013-02-26 15:56:35 UTC (rev 25308)
+++ branches/mule-3.1.x/tests/integration/src/test/resources/org/mule/test/transformers/gzip-transformer-functional-test.xml	2013-02-26 19:03:37 UTC (rev 25309)
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<mule xmlns="http://www.mulesoft.org/schema/mule/core"
-      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-      xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
-      xsi:schemaLocation="
-          http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd
-          http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/3.1/mule-vm.xsd">
-
-    <flow name="compressInput">
-        <vm:inbound-endpoint path="compressInput" exchange-pattern="request-response"/>
-        <gzip-compress-transformer/>
-    </flow>
-
-    <flow name="decompressInput">
-        <vm:inbound-endpoint path="decompressInput" exchange-pattern="request-response"/>
-        <gzip-uncompress-transformer/>
-    </flow>
-
-</mule>

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Loading...