Author: bodewig
Date: Tue Jan 7 13:02:31 2014
New Revision: 1556202
URL: http://svn.apache.org/r1556202
Log:
porting the ArArchiveEntry is easy - as expected
Added:
commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/formats/
commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/formats/ar/
commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveEntry.java
- copied, changed from r1556168,
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
Copied:
commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveEntry.java
(from r1556168,
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java)
URL:
http://svn.apache.org/viewvc/commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveEntry.java?p2=commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveEntry.java&p1=commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java&r1=1556168&r2=1556202&rev=1556202&view=diff
==============================================================================
---
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
(original)
+++
commons/proper/compress/branches/compress-2.0/src/main/java/org/apache/commons/compress2/formats/ar/ArArchiveEntry.java
Tue Jan 7 13:02:31 2014
@@ -16,12 +16,10 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.commons.compress.archivers.ar;
+package org.apache.commons.compress2.formats.ar;
-import java.io.File;
-import java.util.Date;
-
-import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress2.archivers.ArchiveEntryParameters;
+import org.apache.commons.compress2.archivers.spi.SimpleArchiveEntry;
/**
* Represents an archive entry in the "ar" format.
@@ -51,7 +49,7 @@ import org.apache.commons.compress.archi
*
* @Immutable
*/
-public class ArArchiveEntry implements ArchiveEntry {
+public class ArArchiveEntry extends SimpleArchiveEntry {
/** The header for each entry */
public static final String HEADER = "!<arch>\n";
@@ -59,125 +57,37 @@ public class ArArchiveEntry implements A
/** The trailer for each entry */
public static final String TRAILER = "`\012";
- /**
- * SVR4/GNU adds a trailing / to names; BSD does not.
- * They also vary in how names longer than 16 characters are represented.
- * (Not yet fully supported by this implementation)
- */
- private final String name;
- private final int userId;
- private final int groupId;
+ // TODO revisit once the permissions stuff is sorted out
private final int mode;
private static final int DEFAULT_MODE = 33188; // = (octal) 0100644
- private final long lastModified;
- private final long length;
/**
- * Create a new instance using a couple of default values.
- *
- * <p>Sets userId and groupId to 0, the octal file mode to 644 and
- * the last modified time to the current time.</p>
- *
- * @param name name of the entry
- * @param length length of the entry in bytes
+ * Creates an ArArchiveEntry from a parameter object.
+ * @param params the parameters describing the archive entry.
*/
- public ArArchiveEntry(String name, long length) {
- this(name, length, 0, 0, DEFAULT_MODE,
- System.currentTimeMillis() / 1000);
+ public ArArchiveEntry(ArchiveEntryParameters params) {
+ this(params, DEFAULT_MODE);
}
/**
- * Create a new instance.
- *
- * @param name name of the entry
- * @param length length of the entry in bytes
- * @param userId numeric user id
- * @param groupId numeric group id
- * @param mode file mode
- * @param lastModified last modified time in seconds since the epoch
+ * Creates an ArArchiveEntry from a parameter object and an octal mode.
+ * @param params the parameters describing the archive entry.
+ * @param mode the file/dir mode of the entry
*/
- public ArArchiveEntry(String name, long length, int userId, int groupId,
- int mode, long lastModified) {
- this.name = name;
- this.length = length;
- this.userId = userId;
- this.groupId = groupId;
+ public ArArchiveEntry(ArchiveEntryParameters params, int mode) {
+ super(params);
this.mode = mode;
- this.lastModified = lastModified;
- }
-
- /**
- * Create a new instance using the attributes of the given file
- */
- public ArArchiveEntry(File inputFile, String entryName) {
- // TODO sort out mode
- this(entryName, inputFile.isFile() ? inputFile.length() : 0,
- 0, 0, DEFAULT_MODE, inputFile.lastModified() / 1000);
- }
-
- public long getSize() {
- return this.getLength();
- }
-
- public String getName() {
- return name;
- }
-
- public int getUserId() {
- return userId;
- }
-
- public int getGroupId() {
- return groupId;
}
+ // TODO revisit once the permissions stuff is sorted out
public int getMode() {
return mode;
}
- /**
- * Last modified time in seconds since the epoch.
- */
- public long getLastModified() {
- return lastModified;
- }
-
- public Date getLastModifiedDate() {
- return new Date(1000 * getLastModified());
- }
-
- public long getLength() {
- return length;
- }
-
- public boolean isDirectory() {
- return false;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + (name == null ? 0 : name.hashCode());
- return result;
- }
-
+ // TODO revisit once the permissions stuff is sorted out
@Override
public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null || getClass() != obj.getClass()) {
- return false;
- }
- ArArchiveEntry other = (ArArchiveEntry) obj;
- if (name == null) {
- if (other.name != null) {
- return false;
- }
- } else if (!name.equals(other.name)) {
- return false;
- }
- return true;
+ return super.equals(obj) && mode == ((ArArchiveEntry) obj).mode;
}
+
}