Author: bodewig
Date: Mon Aug 15 11:14:58 2011
New Revision: 1157779
URL: http://svn.apache.org/viewvc?rev=1157779&view=rev
Log:
add dump to ArchiveStreamFactory
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java?rev=1157779&r1=1157778&r2=1157779&view=diff
==============================================================================
---
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
(original)
+++
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
Mon Aug 15 11:14:58 2011
@@ -27,6 +27,7 @@ import org.apache.commons.compress.archi
import org.apache.commons.compress.archivers.ar.ArArchiveOutputStream;
import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;
import org.apache.commons.compress.archivers.cpio.CpioArchiveOutputStream;
+import org.apache.commons.compress.archivers.dump.DumpArchiveInputStream;
import org.apache.commons.compress.archivers.jar.JarArchiveInputStream;
import org.apache.commons.compress.archivers.jar.JarArchiveOutputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
@@ -83,6 +84,11 @@ public class ArchiveStreamFactory {
*/
public static final String CPIO = "cpio";
/**
+ * Constant used to identify the Unix DUMP archive format.
+ * @since Commons Compress 1.3
+ */
+ public static final String DUMP = "dump";
+ /**
* Constant used to identify the JAR archive format.
* @since Commons Compress 1.1
*/
@@ -101,7 +107,7 @@ public class ArchiveStreamFactory {
/**
* Create an archive input stream from an archiver name and an input
stream.
*
- * @param archiverName the archive name, i.e. "ar", "zip", "tar", "jar" or
"cpio"
+ * @param archiverName the archive name, i.e. "ar", "zip", "tar", "jar",
"dump" or "cpio"
* @param in the input stream
* @return the archive input stream
* @throws ArchiveException if the archiver name is not known
@@ -134,6 +140,9 @@ public class ArchiveStreamFactory {
if (CPIO.equalsIgnoreCase(archiverName)) {
return new CpioArchiveInputStream(in);
}
+ if (DUMP.equalsIgnoreCase(archiverName)) {
+ return new DumpArchiveInputStream(in);
+ }
throw new ArchiveException("Archiver: " + archiverName + " not
found.");
}
@@ -209,7 +218,17 @@ public class ArchiveStreamFactory {
} else if (CpioArchiveInputStream.matches(signature,
signatureLength)) {
return new CpioArchiveInputStream(in);
}
- // Tar needs a bigger buffer to check the signature; read the
first block
+
+ // Dump needs a bigger buffer to check the signature;
+ final byte[] dumpsig = new byte[32];
+ in.mark(dumpsig.length);
+ signatureLength = in.read(dumpsig);
+ in.reset();
+ if (DumpArchiveInputStream.matches(dumpsig, signatureLength)) {
+ return new DumpArchiveInputStream(in);
+ }
+
+ // Tar needs an even bigger buffer to check the signature; read
the first block
final byte[] tarheader = new byte[512];
in.mark(tarheader.length);
signatureLength = in.read(tarheader);
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java?rev=1157779&r1=1157778&r2=1157779&view=diff
==============================================================================
---
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
(original)
+++
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
Mon Aug 15 11:14:58 2011
@@ -18,6 +18,7 @@
*/
package org.apache.commons.compress.archivers.dump;
+import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import java.io.IOException;
@@ -69,10 +70,11 @@ public class DumpArchiveInputStream exte
* @param is
* @throws Exception
*/
- public DumpArchiveInputStream(InputStream is) throws IOException {
+ public DumpArchiveInputStream(InputStream is) throws ArchiveException {
this.raw = new TapeInputStream(is);
this.hasHitEOF = false;
+ try {
// read header, verify it's a dump archive.
byte[] headerBytes = raw.readRecord();
@@ -92,6 +94,9 @@ public class DumpArchiveInputStream exte
// skip past CLRI and BITS segments since we don't handle them yet.
readCLRI();
readBITS();
+ } catch (IOException ex) {
+ throw new ArchiveException(ex.getMessage(), ex);
+ }
// put in a dummy record for the root node.
Dirent root = new Dirent(2, 2, 4, ".");