commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1556196 - in /commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers: ./ spi/
Date Tue, 07 Jan 2014 12:40:13 GMT
Author: bodewig
Date: Tue Jan  7 12:40:12 2014
New Revision: 1556196

URL: http://svn.apache.org/r1556196
Log:
Initial design idea for IO of archives, absolutely a WIP.

I'll try to port over the AR archiver to see how much effort the
switch from a stream based API to a channel based one would take.

Added:
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveInput.java
  (with props)
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveOutput.java
  (with props)
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveInput.java
  (with props)
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveOutput.java
  (with props)
    commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/SimpleArchiveEntry.java
  (with props)

Added: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveInput.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveInput.java?rev=1556196&view=auto
==============================================================================
--- commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveInput.java
(added)
+++ commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveInput.java
Tue Jan  7 12:40:12 2014
@@ -0,0 +1,45 @@
+/*
+ * 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.compress2.archivers;
+
+import java.nio.channels.ReadableByteChannel;
+
+/**
+ * A channel that reads {@link ArchiveEntry}s.
+ * @NotThreadSafe
+ */
+public interface ArchiveInput<A extends ArchiveEntry> extends ReadableByteChannel,
Iterable<A> {
+
+    /**
+     * Whether this channel is able to read the contents of the given entry.
+     * 
+     * <p>Some archive formats support variants or details that are not supported (yet).</p>
+     * 
+     * @param entry
+     *            the entry to test
+     * @return whether the entry's content can be read
+     */
+    boolean canReadEntryData(A entry);
+
+    /**
+     * Returns the current number of bytes read from this channel.
+     * @return the number of read bytes
+     */
+    long getBytesRead();
+}

Propchange: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveInput.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveOutput.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveOutput.java?rev=1556196&view=auto
==============================================================================
--- commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveOutput.java
(added)
+++ commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveOutput.java
Tue Jan  7 12:40:12 2014
@@ -0,0 +1,79 @@
+/*
+ * 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.compress2.archivers;
+
+import java.io.IOException;
+import java.nio.channels.WritableByteChannel;
+
+/**
+ * A channel that writes {@link ArchiveEntry}s.
+ * @NotThreadSafe
+ */
+public interface ArchiveOutput<A extends ArchiveEntry> extends WritableByteChannel
{
+
+    /**
+     * Creates an ArchiveEntry for the given parameters.
+     * @param params the parameters describing the archive entry.
+     * @return a new archive entry.
+     */
+    A createEntry(ArchiveEntryParameters params);
+
+    /**
+     * Whether this channel is able to write the contents of the given entry.
+     *
+     * <p>Some archive formats support variants or details that are not supported (yet).</p>
+     *
+     * @param archiveEntry
+     *            the entry to test
+     * @return whether the entry's content can be read
+     */
+    boolean canWriteEntryData(A archiveEntry);
+
+    /**
+     * Initializes the channel for writing a new {@link ArchiveEntry}.
+     *
+     * <p>The caller must then write the content to the channel and call {@link #closeEntry()}
to complete the
+     * process.</p>
+     * 
+     * @param entry describes the entry
+     * @throws IOException
+     */
+    void putEntry(A entry) throws IOException;
+    
+    /**
+     * Closes the archive entry, writing any trailer information that may be required.
+     * @throws IOException
+     */
+    void closeEntry() throws IOException;
+
+    /**
+     * Finishes the addition of entries to this stream, without closing it.
+     *
+     * <p>Additional data can be written, if the format supports it.<p>
+     * 
+     * @throws IOException if the user forgets to close the last entry.
+     */
+    void finish() throws IOException;
+
+    /**
+     * Returns the current number of bytes written to this channel.
+     * @return the number of written bytes
+     */
+    long getBytesWritten();
+}

Propchange: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/ArchiveOutput.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveInput.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveInput.java?rev=1556196&view=auto
==============================================================================
--- commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveInput.java
(added)
+++ commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveInput.java
Tue Jan  7 12:40:12 2014
@@ -0,0 +1,68 @@
+/*
+ * 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.compress2.archivers.spi;
+
+import org.apache.commons.compress2.archivers.ArchiveInput;
+import org.apache.commons.compress2.archivers.ArchiveEntry;
+
+/**
+ * Base class implementations may use.
+ * @NotThreadSafe
+ */
+public abstract class AbstractArchiveInput<A extends ArchiveEntry> implements ArchiveInput<A>
{
+
+    /** holds the number of bytes read from this channel */
+    private long bytesRead = 0;
+
+    @Override
+    public long getBytesRead() {
+        return bytesRead;
+    }
+    
+    /**
+     * {@inheritDoc}
+     * <p>This implementation always returns true.</p>
+     */
+    @Override
+    public boolean canReadEntryData(A archiveEntry) {
+        return true;
+    }
+
+    /**
+     * Increments the counter of already read bytes.
+     * Doesn't increment if the EOF has been hit (read == -1)
+     * 
+     * @param read the number of bytes read
+     */
+    protected void count(long read) {
+        if (read != -1) {
+            bytesRead = bytesRead + read;
+        }
+    }
+
+    /**
+     * Decrements the counter of already read bytes.
+     * 
+     * @param pushedBack the number of bytes pushed back.
+     */
+    protected void pushedBackBytes(long pushedBack) {
+        bytesRead -= pushedBack;
+    }
+
+}

Propchange: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveInput.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveOutput.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveOutput.java?rev=1556196&view=auto
==============================================================================
--- commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveOutput.java
(added)
+++ commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveOutput.java
Tue Jan  7 12:40:12 2014
@@ -0,0 +1,56 @@
+/*
+ * 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.compress2.archivers.spi;
+
+import org.apache.commons.compress2.archivers.ArchiveOutput;
+import org.apache.commons.compress2.archivers.ArchiveEntry;
+
+/**
+ * Base class implementations may use.
+ * @NotThreadSafe
+ */
+public abstract class AbstractArchiveOutput<A extends ArchiveEntry> implements ArchiveOutput<A>
{
+
+    /** holds the number of bytes written to this channel */
+    private long bytesWritten = 0;
+
+    @Override
+    public long getBytesWritten() {
+        return bytesWritten;
+    }
+    
+    /**
+     * {@inheritDoc}
+     * <p>This implementation always returns true.</p>
+     */
+    @Override
+    public boolean canWriteEntryData(A archiveEntry) {
+        return true;
+    }
+
+    /**
+     * Increments the counter of written bytes.
+     * 
+     * @param written the number of bytes written
+     */
+    protected void count(long written) {
+        bytesWritten += written;
+    }
+
+}

Propchange: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/AbstractArchiveOutput.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/SimpleArchiveEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/SimpleArchiveEntry.java?rev=1556196&view=auto
==============================================================================
--- commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/SimpleArchiveEntry.java
(added)
+++ commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/SimpleArchiveEntry.java
Tue Jan  7 12:40:12 2014
@@ -0,0 +1,79 @@
+/*
+ * 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.compress2.archivers.spi;
+
+import java.util.Date;
+
+import org.apache.commons.compress2.archivers.ArchiveEntry;
+import org.apache.commons.compress2.archivers.ArchiveEntryParameters;
+import org.apache.commons.compress2.archivers.OwnerInformation;
+
+/**
+ * Container for the basic information of an {@link ArchiveEntry}.
+ * @Immutable
+ */
+public class SimpleArchiveEntry implements ArchiveEntry {
+    private final String name;
+    private final long size;
+    private final boolean dirFlag;
+    private final Date lastModified;
+    private final OwnerInformation owner;
+
+    /**
+     * Creates a SimpleArchiveEntry from a parameter object.
+     * @param params the parameters describing the archive entry.
+     */
+    public SimpleArchiveEntry(ArchiveEntryParameters params) {
+        this.name = params.getName();
+        this.size = params.getSize();
+        this.dirFlag = params.isDirectory();
+        this.lastModified = params.getLastModifiedDate();
+        this.owner = params.getOwnerInformation();
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public long getSize() {
+        return size;
+    }
+
+    @Override
+    public boolean isDirectory() {
+        return dirFlag;
+    }
+
+    @Override
+    public Date getLastModifiedDate() {
+        return clone(lastModified);
+    }
+
+    @Override
+    public OwnerInformation getOwnerInformation() {
+        return owner;
+    }
+
+    // TODO second instance (after ArchiveEntryParameters)
+    private static Date clone(Date d) {
+        return d == null ? null : (Date) d.clone();
+    }
+}

Propchange: commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/archivers/spi/SimpleArchiveEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message