commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1164626 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib: ZlibDeflateStream.java ZlibInflateStream.java
Date Fri, 02 Sep 2011 16:49:35 GMT
Author: mturk
Date: Fri Sep  2 16:49:35 2011
New Revision: 1164626

URL: http://svn.apache.org/viewvc?rev=1164626&view=rev
Log:
Add zlib inflate/deflate stream classes

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibDeflateStream.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibInflateStream.java
  (with props)

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibDeflateStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibDeflateStream.java?rev=1164626&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibDeflateStream.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibDeflateStream.java
Fri Sep  2 16:49:35 2011
@@ -0,0 +1,172 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.apache.commons.runtime.util.zlib;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import org.apache.commons.runtime.InvalidArgumentException;
+import org.apache.commons.runtime.InvalidDataException;
+import org.apache.commons.runtime.InvalidRangeException;
+import org.apache.commons.runtime.OperationNotPermittedException;
+import org.apache.commons.runtime.OverflowException;
+import org.apache.commons.runtime.Pointer;
+import org.apache.commons.runtime.Limits;
+import org.apache.commons.runtime.io.Stream;
+import org.apache.commons.runtime.io.FilterStream;
+import org.apache.commons.runtime.io.OperationNotSupportedException;
+import org.apache.commons.runtime.util.Deflater;
+import org.apache.commons.runtime.util.DeflateStream;
+
+/**
+ * Zlib compressor stream.
+ *
+ * @author Mladen Turk
+ * @since Runtime 1.0
+ */
+public final class ZlibDeflateStream extends DeflateStream
+{
+
+    /**
+     * Creates a new Zlib compressor stream.
+     */
+    public ZlibDeflateStream(Stream s)
+    {
+        this(s, new ZlibDeflater(6,
+                                 ZlibImpl.DEFAULT_WINDOWBITS, ZlibImpl.DEFAULT_MEMLEVEL,
+                                 ZlibImpl.DEFAULT_STRATEGY, Limits.PAGESIZE, true));
+    }
+
+    /**
+     * Creates a new Zlib decompressor stream with the specified
+     * decompressor.
+     */
+    public ZlibDeflateStream(Stream s, Deflater def)
+    {
+        super(s, def);
+    }
+
+    @Override
+    public boolean canRead()
+    {
+        return true;
+    }
+
+    @Override
+    public boolean canWrite()
+    {
+        return true;
+    }
+
+    @Override
+    public boolean eof()
+        throws IOException
+    {
+        return def.finished();
+    }
+
+    @Override
+    public int read()
+        throws IOException
+    {
+        throw new OperationNotSupportedException();
+    }
+
+    @Override
+    public int read(byte[] buffer, int offset, int count)
+        throws IndexOutOfBoundsException, IOException
+    {
+        def.setInput(stream);
+        return def.deflate(buffer, offset, count);
+    }
+
+    @Override
+    public int read(long address, int count)
+        throws NullPointerException, IndexOutOfBoundsException, IOException
+    {
+        def.setInput(stream);
+        return def.deflate(address, count);
+    }
+
+    @Override
+    public int read(ByteBuffer buffer)
+        throws IndexOutOfBoundsException, IOException
+    {
+        def.setInput(stream);
+        return def.deflate(buffer);
+    }
+
+    // === Writer methods
+
+    @Override
+    public int write(int b)
+        throws IOException
+    {
+        throw new OperationNotSupportedException();
+    }
+
+    @Override
+    public int write(byte[] buffer, int offset, int count)
+        throws IndexOutOfBoundsException, IOException
+    {
+        def.setInput(buffer, offset, count);
+        return def.deflate(stream);
+    }
+
+    @Override
+    public int write(long address, int count)
+        throws IndexOutOfBoundsException, IOException
+    {
+        def.setInput(address, count);
+        return def.deflate(stream);
+    }
+
+    @Override
+    public int write(ByteBuffer buffer)
+        throws IndexOutOfBoundsException, IOException
+    {
+        def.setInput(buffer);
+        return def.deflate(stream);
+    }
+
+    @Override
+    public long write(byte[][] array, int offset, int count)
+        throws IndexOutOfBoundsException, IOException
+    {
+        // Simulate vector write for now
+        long w = 0;
+        for (int i = 0; i < count; i++) {
+            def.setInput(array[offset + i]);
+            w += def.deflate(stream);
+        }
+        return w;
+    }
+
+    @Override
+    public long write(ByteBuffer[] array, int offset, int count)
+        throws IndexOutOfBoundsException, IOException
+    {
+        // Simulate vector write for now
+        long w = 0;
+        for (int i = 0; i < count; i++) {
+            def.setInput(array[offset + i]);
+            w += def.deflate(stream);
+        }
+        return w;
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibDeflateStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibInflateStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibInflateStream.java?rev=1164626&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibInflateStream.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibInflateStream.java
Fri Sep  2 16:49:35 2011
@@ -0,0 +1,170 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.apache.commons.runtime.util.zlib;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import org.apache.commons.runtime.InvalidArgumentException;
+import org.apache.commons.runtime.InvalidDataException;
+import org.apache.commons.runtime.InvalidRangeException;
+import org.apache.commons.runtime.OperationNotPermittedException;
+import org.apache.commons.runtime.OverflowException;
+import org.apache.commons.runtime.Pointer;
+import org.apache.commons.runtime.Limits;
+import org.apache.commons.runtime.io.Stream;
+import org.apache.commons.runtime.io.FilterStream;
+import org.apache.commons.runtime.io.OperationNotSupportedException;
+import org.apache.commons.runtime.util.Inflater;
+import org.apache.commons.runtime.util.InflateStream;
+
+/**
+ * Zlib decompressor stream.
+ *
+ * @author Mladen Turk
+ * @since Runtime 1.0
+ */
+public final class ZlibInflateStream extends InflateStream
+{
+
+    /**
+     * Creates a new Zlib decompressor stream.
+     */
+    public ZlibInflateStream(Stream s)
+    {
+        this(s, new ZlibInflater(ZlibImpl.DEFAULT_WINDOWBITS, Limits.PAGESIZE, true));
+    }
+
+    /**
+     * Creates a new Zlib decompressor stream with the specified
+     * decompressor.
+     */
+    public ZlibInflateStream(Stream s, Inflater inf)
+    {
+        super(s, inf);
+    }
+
+    @Override
+    public boolean canRead()
+    {
+        return true;
+    }
+
+    @Override
+    public boolean canWrite()
+    {
+        return true;
+    }
+
+    @Override
+    public boolean eof()
+        throws IOException
+    {
+        return inf.finished();
+    }
+
+    @Override
+    public int read()
+        throws IOException
+    {
+        throw new OperationNotSupportedException();
+    }
+
+    @Override
+    public int read(byte[] buffer, int offset, int count)
+        throws IndexOutOfBoundsException, IOException
+    {
+        inf.setInput(stream);
+        return inf.inflate(buffer, offset, count);
+    }
+
+    @Override
+    public int read(long address, int count)
+        throws NullPointerException, IndexOutOfBoundsException, IOException
+    {
+        inf.setInput(stream);
+        return inf.inflate(address, count);
+    }
+
+    @Override
+    public int read(ByteBuffer buffer)
+        throws IndexOutOfBoundsException, IOException
+    {
+        inf.setInput(stream);
+        return inf.inflate(buffer);
+    }
+
+    // === Writer methods
+
+    @Override
+    public int write(int b)
+        throws IOException
+    {
+        throw new OperationNotSupportedException();
+    }
+
+    @Override
+    public int write(byte[] buffer, int offset, int count)
+        throws IndexOutOfBoundsException, IOException
+    {
+        inf.setInput(buffer, offset, count);
+        return inf.inflate(stream);
+    }
+
+    @Override
+    public int write(long address, int count)
+        throws IndexOutOfBoundsException, IOException
+    {
+        inf.setInput(address, count);
+        return inf.inflate(stream);
+    }
+
+    @Override
+    public int write(ByteBuffer buffer)
+        throws IndexOutOfBoundsException, IOException
+    {
+        inf.setInput(buffer);
+        return inf.inflate(stream);
+    }
+
+    @Override
+    public long write(byte[][] array, int offset, int count)
+        throws IndexOutOfBoundsException, IOException
+    {
+        // Simulate vector write for now
+        long w = 0;
+        for (int i = 0; i < count; i++) {
+            inf.setInput(array[offset + i]);
+            w += inf.inflate(stream);
+        }
+        return w;
+    }
+
+    @Override
+    public long write(ByteBuffer[] array, int offset, int count)
+        throws IndexOutOfBoundsException, IOException
+    {
+        // Simulate vector write for now
+        long w = 0;
+        for (int i = 0; i < count; i++) {
+            inf.setInput(array[offset + i]);
+            w += inf.inflate(stream);
+        }
+        return w;
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/util/zlib/ZlibInflateStream.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message