Author: bodewig
Date: Thu Mar 4 15:54:09 2010
New Revision: 919035
URL: http://svn.apache.org/viewvc?rev=919035&view=rev
Log:
make archive/compressor name constants public.
Modified:
commons/proper/compress/trunk/src/changes/changes.xml
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/compressors/CompressorStreamFactory.java
commons/proper/compress/trunk/src/site/xdoc/examples.xml
Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=919035&r1=919034&r2=919035&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Thu Mar 4 15:54:09
2010
@@ -52,6 +52,10 @@
ZipArchiveEntry, ZipFile and ZipArchiveInputStream are now
more lenient when parsing extra fields.
</action>
+ <action type="add" date="2010-02-12" issue="COMPRESS-97">
+ Added autodetection of compression format to
+ CompressorStreamFactory.
+ </action>
<action type="fix" date="2010-02-12">
Improved exception message if the extra field data in ZIP
archives cannot be parsed.
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=919035&r1=919034&r2=919035&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
Thu Mar 4 15:54:09 2010
@@ -43,7 +43,7 @@
*
* <pre>
* final OutputStream out = new FileOutputStream(output);
- * ArchiveOutputStream os = new
ArchiveStreamFactory().createArchiveOutputStream("zip", out);
+ * ArchiveOutputStream os = new
ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP, out);
*
* os.putArchiveEntry(new ZipArchiveEntry("testdata/test1.xml"));
* IOUtils.copy(new FileInputStream(file1), os);
@@ -59,7 +59,7 @@
*
* <pre>
* final InputStream is = new FileInputStream(input);
- * ArchiveInputStream in = new
ArchiveStreamFactory().createArchiveInputStream("zip", is);
+ * ArchiveInputStream in = new
ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.ZIP, is);
* ZipArchiveEntry entry = (ZipArchiveEntry)in.getNextEntry();
* OutputStream out = new FileOutputStream(new File(dir, entry.getName()));
* IOUtils.copy(in, out);
@@ -71,11 +71,31 @@
*/
public class ArchiveStreamFactory {
- private static final String AR = "ar";
- private static final String CPIO = "cpio";
- private static final String JAR = "jar";
- private static final String TAR = "tar";
- private static final String ZIP = "zip";
+ /**
+ * Constant used to identify the AR archive format.
+ * @since Commons Compress 1.1
+ */
+ public static final String AR = "ar";
+ /**
+ * Constant used to identify the CPIO archive format.
+ * @since Commons Compress 1.1
+ */
+ public static final String CPIO = "cpio";
+ /**
+ * Constant used to identify the JAR archive format.
+ * @since Commons Compress 1.1
+ */
+ public static final String JAR = "jar";
+ /**
+ * Constant used to identify the TAR archive format.
+ * @since Commons Compress 1.1
+ */
+ public static final String TAR = "tar";
+ /**
+ * Constant used to identify the ZIP archive format.
+ * @since Commons Compress 1.1
+ */
+ public static final String ZIP = "zip";
/**
* Create an archive input stream from an archiver name and an input
stream.
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java?rev=919035&r1=919034&r2=919035&view=diff
==============================================================================
---
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
(original)
+++
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
Thu Mar 4 15:54:09 2010
@@ -37,7 +37,7 @@
* <pre>
* final OutputStream out = new FileOutputStream(output);
* CompressorOutputStream cos =
- * new CompressorStreamFactory().createCompressorOutputStream("bzip2",
out);
+ * new
CompressorStreamFactory().createCompressorOutputStream(CompressorStreamFactory.BZIP2,
out);
* IOUtils.copy(new FileInputStream(input), cos);
* cos.close();
* </pre>
@@ -46,7 +46,7 @@
* <pre>
* final InputStream is = new FileInputStream(input);
* CompressorInputStream in =
- * new CompressorStreamFactory().createCompressorInputStream("bzip2", is);
+ * new
CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.BZIP2,
is);
* IOUtils.copy(in, new FileOutputStream(output));
* in.close();
* </pre>
@@ -55,8 +55,16 @@
*/
public class CompressorStreamFactory {
- private static final String BZ = "bzip2";
- private static final String GZ = "gz";
+ /**
+ * Constant used to identify the BZIP2 compression algorithm.
+ * @since Commons Compress 1.1
+ */
+ public static final String BZIP2 = "bzip2";
+ /**
+ * Constant used to identify the GZIP compression algorithm.
+ * @since Commons Compress 1.1
+ */
+ public static final String GZIP = "gz";
/**
* Create an compressor input stream from an input stream, autodetecting
@@ -67,6 +75,7 @@
* @return the compressor input stream
* @throws CompressorException if the compressor name is not known
* @throws IllegalArgumentException if the stream is null or does not
support mark
+ * @since Commons Compress 1.1
*/
public CompressorInputStream createCompressorInputStream(final InputStream
in)
throws CompressorException {
@@ -117,11 +126,11 @@
try {
- if (GZ.equalsIgnoreCase(name)) {
+ if (GZIP.equalsIgnoreCase(name)) {
return new GzipCompressorInputStream(in);
}
- if (BZ.equalsIgnoreCase(name)) {
+ if (BZIP2.equalsIgnoreCase(name)) {
return new BZip2CompressorInputStream(in);
}
@@ -151,11 +160,11 @@
try {
- if (GZ.equalsIgnoreCase(name)) {
+ if (GZIP.equalsIgnoreCase(name)) {
return new GzipCompressorOutputStream(out);
}
- if (BZ.equalsIgnoreCase(name)) {
+ if (BZIP2.equalsIgnoreCase(name)) {
return new BZip2CompressorOutputStream(out);
}
Modified: commons/proper/compress/trunk/src/site/xdoc/examples.xml
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/site/xdoc/examples.xml?rev=919035&r1=919034&r2=919035&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/site/xdoc/examples.xml (original)
+++ commons/proper/compress/trunk/src/site/xdoc/examples.xml Thu Mar 4
15:54:09 2010
@@ -46,7 +46,7 @@
the algorithm name:</p>
<source><![CDATA[
CompressorOutputStream gzippedOut = new CompressorStreamFactory()
- .createCompressorOutputStream("gz", myOutputStream);
+ .createCompressorOutputStream(CompressorStreamFactory.GZIP,
myOutputStream);
]]></source>
<p>Make the factory guess the input format for a given stream:</p>