svn commit: r759958 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 13:27:09 2009
New Revision: 759958

URL: http://svn.apache.org/viewvc?rev=759958view=rev
Log:
Unused imports

Modified:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java?rev=759958r1=759957r2=759958view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
 Mon Mar 30 13:27:09 2009
@@ -22,12 +22,9 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.List;
 
-import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveException;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.ArchiveStreamFactory;




svn commit: r759992 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java

2009-03-30 Thread bodewig
Author: bodewig
Date: Mon Mar 30 14:41:14 2009
New Revision: 759992

URL: http://svn.apache.org/viewvc?rev=759992view=rev
Log:
whitespace

Modified:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java?rev=759992r1=759991r2=759992view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
 Mon Mar 30 14:41:14 2009
@@ -32,146 +32,146 @@
 
 public final class ArTestCase extends AbstractTestCase {
 
-   public void testArArchiveCreation() throws Exception {
-   final File output = new File(dir, bla.ar);
-   
-   final File file1 = getFile(test1.xml);
-   final File file2 = getFile(test2.xml);
-   
-   final OutputStream out = new FileOutputStream(output);
+public void testArArchiveCreation() throws Exception {
+final File output = new File(dir, bla.ar);
+
+final File file1 = getFile(test1.xml);
+final File file2 = getFile(test2.xml);
+
+final OutputStream out = new FileOutputStream(output);
 final ArchiveOutputStream os = new 
ArchiveStreamFactory().createArchiveOutputStream(ar, out);
-   os.putArchiveEntry(new ArArchiveEntry(test1.xml, 
file1.length()));
-   IOUtils.copy(new FileInputStream(file1), os);
-   os.closeArchiveEntry();
-   
-   os.putArchiveEntry(new ArArchiveEntry(test2.xml, 
file2.length()));
-   IOUtils.copy(new FileInputStream(file2), os);
-   os.closeArchiveEntry();
-   
-   os.close();
-   }
-
-   public void testArUnarchive() throws Exception {
-   final File output = new File(dir, bla.ar);
-   {
-   final File file1 = getFile(test1.xml);
-   final File file2 = getFile(test2.xml);
-   
-   final OutputStream out = new FileOutputStream(output);
-   final ArchiveOutputStream os = new 
ArchiveStreamFactory().createArchiveOutputStream(ar, out);
-   os.putArchiveEntry(new ArArchiveEntry(test1.xml, 
file1.length()));
-   IOUtils.copy(new FileInputStream(file1), os);
-   os.closeArchiveEntry();
-   
-   os.putArchiveEntry(new ArArchiveEntry(test2.xml, 
file2.length()));
-   IOUtils.copy(new FileInputStream(file2), os);
-   os.closeArchiveEntry();
-   os.close();
-   out.close();
-   }
-   
-   // UnArArchive Operation
-   final File input = output;
-   final InputStream is = new FileInputStream(input);
-   final ArchiveInputStream in = new 
ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is));
-   final ArArchiveEntry entry = (ArArchiveEntry)in.getNextEntry();
-   
-   File target = new File(dir, entry.getName());
+os.putArchiveEntry(new ArArchiveEntry(test1.xml, file1.length()));
+IOUtils.copy(new FileInputStream(file1), os);
+os.closeArchiveEntry();
+
+os.putArchiveEntry(new ArArchiveEntry(test2.xml, file2.length()));
+IOUtils.copy(new FileInputStream(file2), os);
+os.closeArchiveEntry();
+
+os.close();
+}
+
+public void testArUnarchive() throws Exception {
+final File output = new File(dir, bla.ar);
+{
+final File file1 = getFile(test1.xml);
+final File file2 = getFile(test2.xml);
+
+final OutputStream out = new FileOutputStream(output);
+final ArchiveOutputStream os = new 
ArchiveStreamFactory().createArchiveOutputStream(ar, out);
+os.putArchiveEntry(new ArArchiveEntry(test1.xml, 
file1.length()));
+IOUtils.copy(new FileInputStream(file1), os);
+os.closeArchiveEntry();
+
+os.putArchiveEntry(new ArArchiveEntry(test2.xml, 
file2.length()));
+IOUtils.copy(new FileInputStream(file2), os);
+os.closeArchiveEntry();
+os.close();
+out.close();
+}
+
+// UnArArchive Operation
+final File input = output;
+final InputStream is = new FileInputStream(input);
+final ArchiveInputStream in = new 
ArchiveStreamFactory().createArchiveInputStream(new 

svn commit: r760000 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java test/java/org/apache/commons/compress/archivers/ArTestCase.ja

2009-03-30 Thread bodewig
Author: bodewig
Date: Mon Mar 30 15:07:54 2009
New Revision: 76

URL: http://svn.apache.org/viewvc?rev=76view=rev
Log:
make closeArchiveEntry a NOP if called repeatedly.  This makes ArTestCase fail 
for all platforms consistently 8-)

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java?rev=76r1=75r2=76view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
 Mon Mar 30 15:07:54 2009
@@ -35,6 +35,7 @@
 private long archiveOffset = 0;
 private long entryOffset = 0;
 private ArArchiveEntry prevEntry;
+private boolean haveUnclosedEntry = true;
 
 public ArArchiveOutputStream( final OutputStream pOut ) {
 this.out = pOut;
@@ -47,10 +48,11 @@
 }
 
 public void closeArchiveEntry() throws IOException {
-if ((entryOffset % 2) != 0) {
+if (prevEntry != null  haveUnclosedEntry  (entryOffset % 2) != 0) {
 out.write('\n'); // Pad byte
 archiveOffset++;
 }
+haveUnclosedEntry = false;
 }
 
 public void putArchiveEntry( final ArchiveEntry pEntry ) throws 
IOException {
@@ -70,6 +72,7 @@
 archiveOffset += writeEntryHeader(pArEntry);
 
 entryOffset = 0;
+haveUnclosedEntry = true;
 }
 
 private long fill( final long pOffset, final long pNewOffset, final char 
pFill ) throws IOException { 

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java?rev=76r1=75r2=76view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
 Mon Mar 30 15:07:54 2009
@@ -89,10 +89,10 @@
 public void testArDelete() throws Exception {
 final File output = new File(dir, bla.ar);
 
+final File file1 = getFile(test1.xml);
+final File file2 = getFile(test2.xml);
 {
 // create
-final File file1 = getFile(test1.xml);
-final File file2 = getFile(test2.xml);
 
 final OutputStream out = new FileOutputStream(output);
 final ArchiveOutputStream os = new 
ArchiveStreamFactory().createArchiveOutputStream(ar, out);
@@ -107,7 +107,10 @@
 out.close();
 }
 
-assertEquals(282, output.length());
+assertEquals(8
+ + 60 + file1.length() + (file1.length() % 2)
+ + 60 + file2.length() + (file2.length() % 2),
+ output.length());
 
 final File output2 = new File(dir, bla2.ar);
 




svn commit: r760014 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/MessagesResources_fr.java java/org/apache/commons/math/util/MathUtils.java site/xdoc/changes.xml test/org/apache/c

2009-03-30 Thread luc
Author: luc
Date: Mon Mar 30 15:43:14 2009
New Revision: 760014

URL: http://svn.apache.org/viewvc?rev=760014view=rev
Log:
Added some utility functions to compute powers with integral types (int, long, 
BigInteger)

Modified:

commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java

commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
commons/proper/math/trunk/src/site/xdoc/changes.xml

commons/proper/math/trunk/src/test/org/apache/commons/math/util/MathUtilsTest.java

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java?rev=760014r1=760013r2=760014view=diff
==
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
 Mon Mar 30 15:43:14 2009
@@ -47,6 +47,8 @@
 // org.apache.commons.math.util.MathUtils
 { overflow: gcd({0}, {1}) is 2^31,
   d\u00e9passement de capacit\u00e9 : le PGCD de {0} et {1} vaut 2^31 },
+{ cannot raise an integral value to a negative power ({0}^{1}),
+  impossible d''\u00e9lever une valeur enti\u00e8re \u00e0 une puissance 
n\u00e9gative ({0}^{1}) },
 
 // org.apache.commons.math.FunctionEvaluationException
 { evaluation failed for argument = {0},

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java?rev=760014r1=760013r2=760014view=diff
==
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java 
(original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/util/MathUtils.java 
Mon Mar 30 15:43:14 2009
@@ -18,6 +18,7 @@
 package org.apache.commons.math.util;
 
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.util.Arrays;
 
 import org.apache.commons.math.MathRuntimeException;
@@ -1246,4 +1247,204 @@
 return ret;
 }
 
+/**
+ * Raise an int to an int power.
+ * @param k number to raise
+ * @param e exponent (must be positive or null)
+ * @return ksupe/sup
+ * @exception IllegalArgumentException if e is negative
+ */
+public static int pow(final int k, int e)
+throws IllegalArgumentException {
+
+if (e  0) {
+throw MathRuntimeException.createIllegalArgumentException(
+cannot raise an integral value to a negative power ({0}^{1}),
+k, e);
+}
+
+int result = 1;
+int k2p= k;
+while (e != 0) {
+if ((e  0x1) != 0) {
+result *= k2p;
+}
+k2p *= k2p;
+e = e  1;
+}
+
+return result;
+
+}
+
+/**
+ * Raise an int to a long power.
+ * @param k number to raise
+ * @param e exponent (must be positive or null)
+ * @return ksupe/sup
+ * @exception IllegalArgumentException if e is negative
+ */
+public static int pow(final int k, long e)
+throws IllegalArgumentException {
+
+if (e  0) {
+throw MathRuntimeException.createIllegalArgumentException(
+cannot raise an integral value to a negative power ({0}^{1}),
+k, e);
+}
+
+int result = 1;
+int k2p= k;
+while (e != 0) {
+if ((e  0x1) != 0) {
+result *= k2p;
+}
+k2p *= k2p;
+e = e  1;
+}
+
+return result;
+
+}
+
+/**
+ * Raise a long to an int power.
+ * @param k number to raise
+ * @param e exponent (must be positive or null)
+ * @return ksupe/sup
+ * @exception IllegalArgumentException if e is negative
+ */
+public static long pow(final long k, int e)
+throws IllegalArgumentException {
+
+if (e  0) {
+throw MathRuntimeException.createIllegalArgumentException(
+cannot raise an integral value to a negative power ({0}^{1}),
+k, e);
+}
+
+long result = 1l;
+long k2p= k;
+while (e != 0) {
+if ((e  0x1) != 0) {
+result *= k2p;
+}
+k2p *= k2p;
+e = e  1;
+}
+
+return result;
+
+}
+
+/**
+ * Raise a long to a long power.
+ * @param k number to raise
+ * @param e exponent (must be positive or null)
+ * @return ksupe/sup
+ * @exception IllegalArgumentException if e is negative
+ */
+public static long pow(final long k, long e)
+

svn commit: r760016 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/fraction/BigFraction.java test/org/apache/commons/math/fraction/BigFractionTest.java

2009-03-30 Thread luc
Author: luc
Date: Mon Mar 30 15:48:56 2009
New Revision: 760016

URL: http://svn.apache.org/viewvc?rev=760016view=rev
Log:
optimized some fraction operations (mainly pow)
replaced pow(BigFraction) by pow(double) as it already converted the argument 
to double upon entry
added tests for pow

Modified:

commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/BigFraction.java

commons/proper/math/trunk/src/test/org/apache/commons/math/fraction/BigFractionTest.java

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/BigFraction.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/BigFraction.java?rev=760016r1=760015r2=760016view=diff
==
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/BigFraction.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/fraction/BigFraction.java
 Mon Mar 30 15:48:56 2009
@@ -20,6 +20,7 @@
 import java.math.BigInteger;
 
 import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.util.MathUtils;
 
 /**
  * Representation of a rational number without any overflow. This class is
@@ -457,7 +458,35 @@
  * if the {...@link BigInteger} is codenull/code.
  */
 public BigFraction add(final BigInteger bg) {
-return add(new BigFraction(bg, BigInteger.ONE));
+return new BigFraction(numerator.add(denominator.multiply(bg)), 
denominator);
+}
+
+/**
+ * p
+ * Adds the value of this fraction to the passed ttinteger/tt, 
returning
+ * the result in reduced form.
+ * /p
+ * 
+ * @param i
+ *the ttinteger/tt to add.
+ * @return a codeBigFraction/code instance with the resulting values.
+ */
+public BigFraction add(final int i) {
+return add(BigInteger.valueOf(i));
+}
+
+/**
+ * p
+ * Adds the value of this fraction to the passed ttlong/tt, returning
+ * the result in reduced form.
+ * /p
+ * 
+ * @param l
+ *the ttlong/tt to add.
+ * @return a codeBigFraction/code instance with the resulting values.
+ */
+public BigFraction add(final long l) {
+return add(BigInteger.valueOf(l));
 }
 
 /**
@@ -493,34 +522,6 @@
 
 /**
  * p
- * Adds the value of this fraction to the passed ttinteger/tt, 
returning
- * the result in reduced form.
- * /p
- * 
- * @param i
- *the ttinteger/tt to add.
- * @return a codeBigFraction/code instance with the resulting values.
- */
-public BigFraction add(final int i) {
-return add(new BigFraction(i, 1));
-}
-
-/**
- * p
- * Adds the value of this fraction to the passed ttlong/tt, returning
- * the result in reduced form.
- * /p
- * 
- * @param l
- *the ttlong/tt to add.
- * @return a codeBigFraction/code instance with the resulting values.
- */
-public BigFraction add(final long l) {
-return add(new BigFraction(l, 1L));
-}
-
-/**
- * p
  * Gets the fraction as a codeBigDecimal/code. This calculates the
  * fraction as the numerator divided by denominator.
  * /p
@@ -602,31 +603,14 @@
  * @return a {...@link BigFraction} instance with the resulting values.
  * @throws NullPointerException
  * if the codeBigInteger/code is codenull/code.
- */
-public BigFraction divide(final BigInteger bg) {
-return divide(new BigFraction(bg, BigInteger.ONE));
-}
-
-/**
- * p
- * Divide the value of this fraction by another, returning the result in
- * reduced form.
- * /p
- * 
- * @param fraction
- *the fraction to divide by, must not be codenull/code.
- * @return a {...@link BigFraction} instance with the resulting values.
- * @throws NullPointerException
- * if the fraction is codenull/code.
  * @throws ArithmeticException
  * if the fraction to divide by is zero.
  */
-public BigFraction divide(final BigFraction fraction) {
-if (BigInteger.ZERO.equals(fraction.numerator)) {
+public BigFraction divide(final BigInteger bg) {
+if (BigInteger.ZERO.equals(bg)) {
 throw MathRuntimeException.createArithmeticException(denominator 
must be different from 0);
 }
-
-return multiply(fraction.reciprocal());
+return new BigFraction(numerator, denominator.multiply(bg));
 }
 
 /**
@@ -638,9 +622,11 @@
  * @param i
  *the ttint/tt to divide by.
  * @return a {...@link BigFraction} instance with the resulting values.
+ * @throws ArithmeticException
+ * if the fraction to divide by is zero.
  */
 public BigFraction divide(final int i) {
-return divide(new 

svn commit: r760017 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java

2009-03-30 Thread bodewig
Author: bodewig
Date: Mon Mar 30 15:49:16 2009
New Revision: 760017

URL: http://svn.apache.org/viewvc?rev=760017view=rev
Log:
offset calculation was broken

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java?rev=760017r1=760016r2=760017view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
 Mon Mar 30 15:49:16 2009
@@ -111,19 +111,17 @@
 
 public int read() throws IOException {
 final int ret = input.read();
-offset++;
+offset += (ret  0 ? 1 : 0);
 return ret;
 }
 
 public int read(byte b[]) throws IOException {
-final int ret = read(b, 0, b.length);
-offset = offset + b.length;
-return ret;
+return read(b, 0, b.length);
 }
 
 public int read(byte[] b, int off, int len) throws IOException {
 final int ret = this.input.read(b, off, len);
-offset = offset + off;
+offset += (ret  0 ? ret : 0);
 return ret;
 }
 




svn commit: r760023 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 15:58:01 2009
New Revision: 760023

URL: http://svn.apache.org/viewvc?rev=760023view=rev
Log:
Use generic method

Modified:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java?rev=760023r1=760022r2=760023view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
 Mon Mar 30 15:58:01 2009
@@ -237,7 +237,7 @@
en.limit()));
 }
 
-zos.putNextEntry(ze);
+zos.putArchiveEntry(ze);
 zos.write(Hello, world!.getBytes(US-ASCII));
 zos.closeEntry();
 
@@ -253,7 +253,7 @@
en.limit()));
 }
 
-zos.putNextEntry(ze);
+zos.putArchiveEntry(ze);
 zos.write(Give me your money!.getBytes(US-ASCII));
 zos.closeEntry();
 
@@ -270,7 +270,7 @@
en.limit()));
 }
 
-zos.putNextEntry(ze);
+zos.putArchiveEntry(ze);
 zos.write(ascii.getBytes(US-ASCII));
 zos.closeEntry();
 } finally {




svn commit: r760032 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java

2009-03-30 Thread bodewig
Author: bodewig
Date: Mon Mar 30 16:31:15 2009
New Revision: 760032

URL: http://svn.apache.org/viewvc?rev=760032view=rev
Log:
chunking of input by entries in AR-Input, COMPRESS-11

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java?rev=760032r1=760031r2=760032view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
 Mon Mar 30 16:31:15 2009
@@ -35,13 +35,42 @@
 private final InputStream input;
 private long offset = 0;
 private boolean closed;
+/*
+ * If getNextEnxtry has been called, the entry metadata is stored in
+ * currentEntry.
+ */
+private ArArchiveEntry currentEntry = null;
+/*
+ * The offset where the current entry started. -1 if no entry has been
+ * called
+ */
+private long entryOffset = -1;
 
 public ArArchiveInputStream( final InputStream pInput ) {
 input = pInput;
 closed = false;
 }
 
+/**
+ * Returns the next AR entry in this stream.
+ * 
+ * @return the next AR entry.
+ * @throws IOException
+ * if the entry could not be read
+ */
 public ArArchiveEntry getNextArEntry() throws IOException {
+if (currentEntry != null) {
+final long entryEnd = entryOffset + currentEntry.getLength();
+while (offset  entryEnd) {
+int x = read();
+if (x == -1) {
+// hit EOF before previous entry was complete
+// TODO: throw an exception instead?
+return null;
+}
+}
+currentEntry = null;
+}
 
 if (offset == 0) {
 final byte[] expected = ArArchiveEntry.HEADER.getBytes();
@@ -57,12 +86,15 @@
 }
 }
 
-if (input.available() == 0) {
-return null;
+if (offset % 2 != 0) {
+if (read()  0) {
+// hit eof
+return null;
+}
 }
 
-if (offset % 2 != 0) {
-read();
+if (input.available() == 0) {
+return null;
 }
 
 final byte[] name = new byte[16];
@@ -93,8 +125,11 @@
 }
 }
 
-return new ArArchiveEntry(new String(name).trim(), Long.parseLong(new 
String(length).trim()));
-
+entryOffset = offset;
+currentEntry = new ArArchiveEntry(new String(name).trim(),
+  Long.parseLong(new String(length)
+ .trim()));
+return currentEntry;
 }
 
 
@@ -107,20 +142,30 @@
 closed = true;
 input.close();
 }
+currentEntry = null;
 }
 
 public int read() throws IOException {
-final int ret = input.read();
-offset += (ret  0 ? 1 : 0);
-return ret;
+byte[] single = new byte[1];
+int num = read(single, 0, 1);
+return num == -1 ? -1 : single[0]  0xff;
 }
 
-public int read(byte b[]) throws IOException {
+public int read(byte[] b) throws IOException {
 return read(b, 0, b.length);
 }
 
-public int read(byte[] b, int off, int len) throws IOException {
-final int ret = this.input.read(b, off, len);
+public int read(byte[] b, final int off, final int len) throws IOException 
{
+int toRead = len;
+if (currentEntry != null) {
+final long entryEnd = entryOffset + currentEntry.getLength();
+if (len  0  entryEnd  offset) {
+toRead = (int) Math.min(len, entryEnd - offset);
+} else {
+return -1;
+}
+}
+final int ret = this.input.read(b, off, toRead);
 offset += (ret  0 ? ret : 0);
 return ret;
 }




svn commit: r760033 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java

2009-03-30 Thread bodewig
Author: bodewig
Date: Mon Mar 30 16:33:52 2009
New Revision: 760033

URL: http://svn.apache.org/viewvc?rev=760033view=rev
Log:
make test platform independent

Modified:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java?rev=760033r1=760032r2=760033view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
 Mon Mar 30 16:33:52 2009
@@ -149,7 +149,9 @@
 
 assertEquals(1, copied);
 assertEquals(1, deleted);
-assertEquals(144, output2.length());
+assertEquals(8
+ + 60 + file1.length() + (file1.length() % 2),
+ output2.length());
 
 long files = 0;
 long sum = 0;
@@ -173,7 +175,7 @@
 }
 
 assertEquals(1, files);
-assertEquals(76, sum);
+assertEquals(file1.length(), sum);
 
 }
 




svn commit: r760039 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 16:45:13 2009
New Revision: 760039

URL: http://svn.apache.org/viewvc?rev=760039view=rev
Log:
Use generic methods

Modified:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java?rev=760039r1=760038r2=760039view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
 Mon Mar 30 16:45:13 2009
@@ -50,25 +50,25 @@
 try {
 tout = new TarArchiveOutputStream(new FileOutputStream(f));
 TarArchiveEntry t = new TarArchiveEntry(new File(ROOT));
-tout.putNextEntry(t);
-tout.closeEntry();
+tout.putArchiveEntry(t);
+tout.closeArchiveEntry();
 t = new TarArchiveEntry(new File(new File(ROOT), foo.txt));
 t.setSize(6);
-tout.putNextEntry(t);
+tout.putArchiveEntry(t);
 tout.write(new byte[] {'h', 'e', 'l', 'l', 'o', ' '});
-tout.closeEntry();
+tout.closeArchiveEntry();
 t = new TarArchiveEntry(new File(new File(ROOT), bar.txt)
 .getAbsolutePath());
 t.setSize(5);
-tout.putNextEntry(t);
+tout.putArchiveEntry(t);
 tout.write(new byte[] {'w', 'o', 'r', 'l', 'd'});
-tout.closeEntry();
+tout.closeArchiveEntry();
 t = new TarArchiveEntry(dummy);
 t.setName(new File(new File(ROOT), baz.txt).getAbsolutePath());
 t.setSize(1);
-tout.putNextEntry(t);
+tout.putArchiveEntry(t);
 tout.write(new byte[] {'!'});
-tout.closeEntry();
+tout.closeArchiveEntry();
 tout.close();
 tout = null;
 




svn commit: r760053 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 17:17:58 2009
New Revision: 760053

URL: http://svn.apache.org/viewvc?rev=760053view=rev
Log:
Initial Javadoc
Implement common write(byte) method

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java?rev=760053r1=760052r2=760053view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
 Mon Mar 30 17:17:58 2009
@@ -21,9 +21,46 @@
 import java.io.IOException;
 import java.io.OutputStream;
 
+/**
+ * Archive output stream implementations are expected to override the
+ * {...@link #write(byte[], int, int)} method to improve performance.
+ * They should also override {...@link #close()} to ensure that any necessary
+ * trailers are added.
+ * p
+ * Example usage:br/
+ * TBA
+ */
 public abstract class ArchiveOutputStream extends OutputStream {
+
+/** Temporary buffer used for the {...@link #write(int)} method */
+private final byte[] oneByte = new byte[1];
+static final int BYTE_MASK = 0xFF;
 
 public abstract void putArchiveEntry(ArchiveEntry entry) throws 
IOException;
 
+/**
+ * Closes the archive entry, writing any trailer information that may
+ * be required.
+ * @throws IOException
+ */
 public abstract void closeArchiveEntry() throws IOException;
+
+// Generic implementations of OutputStream methods that may be useful to 
sub-classes
+
+/**
+ * Writes a byte to the current archive entry.
+ *
+ * This method simply calls write( byte[], 0, 1 ).
+ *
+ * MUST be overridden if the {...@link #write(byte[], int, int)} method
+ * is not overridden; may be overridden otherwise.
+ * 
+ * @param b The byte to be written.
+ * @throws IOException on error
+ */
+public void write(int b) throws IOException {
+oneByte[0] = (byte) (b  BYTE_MASK);
+write(oneByte, 0, 1);
+}
+
 }




svn commit: r760054 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 17:18:59 2009
New Revision: 760054

URL: http://svn.apache.org/viewvc?rev=760054view=rev
Log:
Remove methods already provided by superclass

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java?rev=760054r1=760053r2=760054view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
 Mon Mar 30 17:18:59 2009
@@ -145,21 +145,11 @@
 return offset;
 }
 
-public void write(int b) throws IOException {
-out.write(b);
-entryOffset++;
-}
-
 public void write(byte[] b, int off, int len) throws IOException {
 out.write(b, off, len);
 entryOffset += len;
 }
 
-public void write(byte[] b) throws IOException {
-out.write(b);
-entryOffset += b.length;
-}
-
 public void close() throws IOException {
 closeArchiveEntry();
 out.close();




svn commit: r760059 - in /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers: jar/JarArchiveOutputStreamTest.java zip/UTF8ZipFilesTest.java

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 17:27:38 2009
New Revision: 760059

URL: http://svn.apache.org/viewvc?rev=760059view=rev
Log:
Use generic methods

Modified:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java?rev=760059r1=760058r2=760059view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java
 Mon Mar 30 17:27:38 2009
@@ -38,9 +38,9 @@
 
 out = new JarArchiveOutputStream(new 
FileOutputStream(testArchive));
 out.putArchiveEntry(new ZipArchiveEntry(foo/));
-out.closeEntry();
+out.closeArchiveEntry();
 out.putArchiveEntry(new ZipArchiveEntry(bar/));
-out.closeEntry();
+out.closeArchiveEntry();
 out.close();
 out = null;
 

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java?rev=760059r1=760058r2=760059view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
 Mon Mar 30 17:27:38 2009
@@ -239,7 +239,7 @@
 
 zos.putArchiveEntry(ze);
 zos.write(Hello, world!.getBytes(US-ASCII));
-zos.closeEntry();
+zos.closeArchiveEntry();
 
 ze = new ZipArchiveEntry(EURO_FOR_DOLLAR_TXT);
 if (withExplicitUnicodeExtra
@@ -255,7 +255,7 @@
 
 zos.putArchiveEntry(ze);
 zos.write(Give me your money!.getBytes(US-ASCII));
-zos.closeEntry();
+zos.closeArchiveEntry();
 
 ze = new ZipArchiveEntry(ASCII_TXT);
 
@@ -272,7 +272,7 @@
 
 zos.putArchiveEntry(ze);
 zos.write(ascii.getBytes(US-ASCII));
-zos.closeEntry();
+zos.closeArchiveEntry();
 } finally {
 if (zos != null) {
 try {




svn commit: r760062 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers: cpio/CpioArchiveOutputStream.java jar/JarArchiveOutputStream.java tar/TarArchiveOutputStrea

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 17:32:27 2009
New Revision: 760062

URL: http://svn.apache.org/viewvc?rev=760062view=rev
Log:
Replace specific methods with generic ones
Remove code that is provided by the parent class

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStream.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java?rev=760062r1=760061r2=760062view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
 Mon Mar 30 17:32:27 2009
@@ -132,13 +132,15 @@
  * the default header format will be used if no other format is specified 
in
  * the entry.
  * 
- * @param e
+ * @param entry
  *the CPIO cpioEntry to be written
  * @throws IOException
  * if an I/O error has occurred or if a CPIO file error has
  * occurred
+ * @throws ClassCastException if entry is not an instance of 
CpioArchiveEntry
  */
-public void putNextEntry(final CpioArchiveEntry e) throws IOException {
+public void putArchiveEntry(ArchiveEntry entry) throws IOException {
+CpioArchiveEntry e = (CpioArchiveEntry) entry;
 ensureOpen();
 if (this.entry != null) {
 closeArchiveEntry(); // close previous entry
@@ -377,23 +379,4 @@
 out.write('\0');
 }
 
-/*
- * (non-Javadoc)
- * 
- * @see
- * 
org.apache.commons.compress.archivers.ArchiveOutputStream#putArchiveEntry
- * (org.apache.commons.compress.archivers.ArchiveEntry)
- */
-public void putArchiveEntry(ArchiveEntry entry) throws IOException {
-this.putNextEntry((CpioArchiveEntry) entry);
-}
-
-/*
- * (non-Javadoc)
- * 
- * @see java.io.OutputStream#write(int)
- */
-public void write(int b) throws IOException {
-out.write(b);
-}
 }

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStream.java?rev=760062r1=760061r2=760062view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStream.java
 Mon Mar 30 17:32:27 2009
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 
+import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.zip.JarMarker;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
@@ -40,11 +41,12 @@
 super(out);
 }
 
-public void putNextEntry(ZipArchiveEntry ze) throws IOException {
+// @throws ClassCastException if entry is not an instance of 
ZipArchiveEntry
+public void putArchiveEntry(ArchiveEntry ze) throws IOException {
 if (!jarMarkerAdded) {
-ze.addAsFirstExtraField(JarMarker.getInstance());
+
((ZipArchiveEntry)ze).addAsFirstExtraField(JarMarker.getInstance());
 jarMarkerAdded = true;
 }
-super.putNextEntry(ze);
+super.putArchiveEntry(ze);
 }
 }

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java?rev=760062r1=760061r2=760062view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
 Mon Mar 30 17:32:27 2009
@@ -43,7 

svn commit: r760081 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 18:10:45 2009
New Revision: 760081

URL: http://svn.apache.org/viewvc?rev=760081view=rev
Log:
Implement generic read()
Update Javadoc

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java?rev=760081r1=760080r2=760081view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
 Mon Mar 30 18:10:45 2009
@@ -22,11 +22,12 @@
 import java.io.InputStream;
 
 /**
- * Archive input streams are expected to override thebr/
- * {...@link #read()} and {...@link #read(byte[] b, int off, int len)} br/
- * methods so that reading from the stream generates EOF for the end of
- * data in each entry as well as at the end of the file proper. The
- * {...@link #getNextEntry()} method is used to reset the input stream
+ * Archive input streams bMUST/b override the 
+ * {...@link #read(byte[], int, int)} - or {...@link #read()} -
+ * method so that reading from the stream generates EOF for the end of
+ * data in each entry as well as at the end of the file proper.
+ * p
+ * The {...@link #getNextEntry()} method is used to reset the input stream
  * ready for reading the data from the next entry.
  * p
  * The input stream classes must also implement a method with the signature:
@@ -38,6 +39,9 @@
  */
 public abstract class ArchiveInputStream extends InputStream {
 
+private byte[] SINGLE = new byte[1];
+private static final int BYTE_MASK = 0xFF;
+
 /**
  * Returns the next Archive Entry in this Stream.
  * @return the next entry
@@ -45,4 +49,32 @@
  */
 public abstract ArchiveEntry getNextEntry() throws IOException;
 
+/*
+ * Note that subclasses also implement specific get() methods which
+ * return the appropriate class without need for a cast.
+ * See SVN revision r743259
+ * @return
+ * @throws IOException
+ */
+// public abstract XXXArchiveEntry getNextXXXEntry() throws IOException;
+
+
+/**
+ * Reads a byte of data. This method will block until enough input is
+ * available.
+ * 
+ * Simply calls the {...@link #read(byte[], int, int)} method.
+ * 
+ * MUST be overridden if the {...@link #read(byte[], int, int)} method
+ * is not overridden; may be overridden otherwise.
+ * 
+ * @return the byte read, or -1 if end of input is reached
+ * @throws IOException
+ * if an I/O error has occurred or if a CPIO file error has
+ * occurred
+ */
+public int read() throws IOException {
+int num = read(SINGLE, 0, 1);
+return num == -1 ? -1 : SINGLE[0]  BYTE_MASK;
+}
 }




svn commit: r760082 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers: ar/ArArchiveInputStream.java tar/TarArchiveInputStream.java zip/ZipArchiveInputStream.java

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 18:11:46 2009
New Revision: 760082

URL: http://svn.apache.org/viewvc?rev=760082view=rev
Log:
Remove unnecessary override methods

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java?rev=760082r1=760081r2=760082view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
 Mon Mar 30 18:11:46 2009
@@ -145,16 +145,6 @@
 currentEntry = null;
 }
 
-public int read() throws IOException {
-byte[] single = new byte[1];
-int num = read(single, 0, 1);
-return num == -1 ? -1 : single[0]  0xff;
-}
-
-public int read(byte[] b) throws IOException {
-return read(b, 0, b.length);
-}
-
 public int read(byte[] b, final int off, final int len) throws IOException 
{
 int toRead = len;
 if (currentEntry != null) {

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java?rev=760082r1=760081r2=760082view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
 Mon Mar 30 18:11:46 2009
@@ -40,7 +40,6 @@
 private static final int SMALL_BUFFER_SIZE = 256;
 private static final int BUFFER_SIZE = 8 * 1024;
 private static final int LARGE_BUFFER_SIZE = 32 * 1024;
-private static final int BYTE_MASK = 0xFF;
 
 private boolean debug;
 private boolean hasHitEOF;
@@ -51,13 +50,6 @@
 private TarArchiveEntry currEntry;
 
 /**
- * This contents of this array is not used at all in this class,
- * it is only here to avoid repeated object creation during calls
- * to the no-arg read method.
- */
-private final byte[] oneBuf;
-
-/**
  * Constructor for TarInputStream.
  * @param is the input stream to use
  */
@@ -83,7 +75,6 @@
 public TarArchiveInputStream(InputStream is, int blockSize, int 
recordSize) {
 this.buffer = new TarBuffer(is, blockSize, recordSize);
 this.readBuf = null;
-this.oneBuf = new byte[1];
 this.debug = false;
 this.hasHitEOF = false;
 }
@@ -270,19 +261,6 @@
 }
 
 /**
- * Reads a byte from the current tar archive entry.
- *
- * This method simply calls read( byte[], int, int ).
- *
- * @return The byte read, or -1 at EOF.
- * @throws IOException on error
- */
-public int read() throws IOException {
-int num = read(oneBuf, 0, 1);
-return num == -1 ? -1 : oneBuf[0]  BYTE_MASK;
-}
-
-/**
  * Reads bytes from the current tar archive entry.
  *
  * This method is aware of the boundaries of the current

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java?rev=760082r1=760081r2=760082view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
 Mon Mar 30 18:11:46 2009
@@ -54,7 +54,6 @@
 private final Inflater inf = new Inflater(true);
 private final CRC32 crc = new CRC32();
 
-private final byte[] SINGLE = new byte[1];
 private final byte[] buf = new byte[ZipArchiveOutputStream.BUFFER_SIZE];
 
 private ZipArchiveEntry current = null;
@@ -244,11 +243,6 @@
 }
 }
 
-public int read() throws IOException {
-int num = read(SINGLE, 0, 1);
-return num == -1 ? -1 : SINGLE[0]  

svn commit: r760084 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 18:13:02 2009
New Revision: 760084

URL: http://svn.apache.org/viewvc?rev=760084view=rev
Log:
Don't expose close entry method
Remove unnecessary override methods

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java?rev=760084r1=760083r2=760084view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
 Mon Mar 30 18:13:02 2009
@@ -70,8 +70,6 @@
 
 private boolean entryEOF = false;
 
-private final byte[] singleByteBuf = new byte[1];
-
 private final byte tmpbuf[] = new byte[4096];
 
 private long crc = 0;
@@ -129,7 +127,7 @@
  * if an I/O error has occurred or if a CPIO file error has
  * occurred
  */
-public void closeEntry() throws IOException {
+private void closeEntry() throws IOException {
 ensureOpen();
 while (read(this.tmpbuf, 0, this.tmpbuf.length) != -1) {
 // do nothing
@@ -208,20 +206,6 @@
 }
 
 /**
- * Reads a byte of data. This method will block until enough input is
- * available.
- * 
- * @return the byte read, or -1 if end of input is reached
- * @throws IOException
- * if an I/O error has occurred or if a CPIO file error has
- * occurred
- */
-public int read() throws IOException {
-return read(this.singleByteBuf, 0, 1) == -1 ? -1
-: this.singleByteBuf[0]  0xff;
-}
-
-/**
  * Reads from the current CPIO entry into an array of bytes. Blocks until
  * some input is available.
  * 




svn commit: r760116 - in /commons/proper/configuration/branches/configuration2_experimental: src/main/java/org/apache/commons/configuration2/ src/test/java/org/apache/commons/configuration2/ src/test/

2009-03-30 Thread oheger
Author: oheger
Date: Mon Mar 30 19:25:12 2009
New Revision: 760116

URL: http://svn.apache.org/viewvc?rev=760116view=rev
Log:
CONFIGURATION-371, CONFIGURATION-314: Ported changes to configuration2 branch.

Modified:

commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java

commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java

commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertiesConfiguration.java

commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestPropertiesConfigurationLayout.java

commons/proper/configuration/branches/configuration2_experimental/src/test/resources/test.properties

commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml

commons/proper/configuration/branches/configuration2_experimental/xdocs/userguide/howto_properties.xml

Modified: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java?rev=760116r1=760115r2=760116view=diff
==
--- 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
 (original)
+++ 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/PropertiesConfiguration.java
 Mon Mar 30 19:25:12 2009
@@ -179,6 +179,9 @@
 /** Constant for the supported comment characters.*/
 static final String COMMENT_CHARS = #!;
 
+/** Constant for the default properties separator.*/
+static final String DEFAULT_SEPARATOR =  = ;
+
 /**
  * Constant for the default codeIOFactory/code. This instance is used
  * when no specific factory was set.
@@ -600,7 +603,7 @@
 {
 /** The regular expression to parse the key and the value of a 
property. */
 private static final Pattern PROPERTY_PATTERN
-= Pattern.compile((([\\S[^ + new String(SEPARATORS) + 
]]|.)*)\\s*(\\s+|[ + new String(SEPARATORS) +])(.*));
+= Pattern.compile((([\\S[^ + new String(SEPARATORS) + 
]]|.)*)(\\s*(\\s+|[ + new String(SEPARATORS) +])\\s*)(.*));
 
 /** Stores the comment lines for the currently processed property.*/
 private ListString commentLines;
@@ -611,6 +614,9 @@
 /** Stores the value of the last read property.*/
 private String propertyValue;
 
+/** Stores the property separator of the last read property.*/
+private String propertySeparator = DEFAULT_SEPARATOR;
+
 /** Stores the list delimiter character.*/
 private char delimiter;
 
@@ -750,6 +756,19 @@
 }
 
 /**
+ * Returns the separator that was used for the last read property. The
+ * separator can be stored so that it can later be restored when saving
+ * the configuration.
+ *
+ * @return the separator for the last read property
+ * @since 1.7
+ */
+public String getPropertySeparator()
+{
+return propertySeparator;
+}
+
+/**
  * Parses a line read from the properties file. This method is called
  * for each non-comment line read from the source file. Its task is to
  * split the passed in line into the property key and its value. The
@@ -764,6 +783,7 @@
 String[] property = doParseProperty(line);
 initPropertyName(property[0]);
 initPropertyValue(property[1]);
+initPropertySeparator(property[2]);
 }
 
 /**
@@ -795,6 +815,20 @@
 }
 
 /**
+ * Sets the separator of the current property. This method can be 
called
+ * by codeparseProperty()/code. It allows the associated layout
+ * object to keep track of the property separators. When saving the
+ * configuration the separators can be restored.
+ *
+ * @param value the separator used for the current property
+ * @since 1.7
+ */
+protected void initPropertySeparator(String value)
+{
+propertySeparator = value;
+}
+
+/**
  * Checks if the passed in line should be combined with the following.
  * This is true, if the line ends with an odd number of backslashes.
  *
@@ -813,7 +847,7 @@
 }
 
 /**
- * Parse a property line and return the key and 

svn commit: r760159 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 20:35:08 2009
New Revision: 760159

URL: http://svn.apache.org/viewvc?rev=760159view=rev
Log:
Javadoc

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java?rev=760159r1=760158r2=760159view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
 Mon Mar 30 20:35:08 2009
@@ -36,6 +36,16 @@
 private final byte[] oneByte = new byte[1];
 static final int BYTE_MASK = 0xFF;
 
+// Methods specific to ArchiveOutputStream
+
+/**
+ * Writes the headers for an archive entry to the output stream.
+ * The caller must then write the content to the stream and call
+ * {...@link #closeArchiveEntry()} to complete the process.
+ * 
+ * @param entry describes the entry
+ * @throws IOException
+ */
 public abstract void putArchiveEntry(ArchiveEntry entry) throws 
IOException;
 
 /**




svn commit: r760170 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java

2009-03-30 Thread jukka
Author: jukka
Date: Mon Mar 30 21:01:48 2009
New Revision: 760170

URL: http://svn.apache.org/viewvc?rev=760170view=rev
Log:
COMPRESS-66: Document null return value of ArchiveInputStream.getNextEntry

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java?rev=760170r1=760169r2=760170view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
 Mon Mar 30 21:01:48 2009
@@ -44,7 +44,9 @@
 
 /**
  * Returns the next Archive Entry in this Stream.
- * @return the next entry
+ *
+ * @return the next entry,
+ * or codenull/code if there are no more entries
  * @throws IOException if the next entry could not be read
  */
 public abstract ArchiveEntry getNextEntry() throws IOException;




svn commit: r760187 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 21:33:36 2009
New Revision: 760187

URL: http://svn.apache.org/viewvc?rev=760187view=rev
Log:
Fix TODOs

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java?rev=760187r1=760186r2=760187view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
 Mon Mar 30 21:33:36 2009
@@ -249,8 +249,7 @@
 return -1;
 }
 
-int tmpread = this.in.read(b, off, tmplength);
-// TODO - what about EOF or short reads?
+int tmpread = readFully(b, off, tmplength);
 if (this.entry.getFormat() == FORMAT_NEW_CRC) {
 for (int pos = 0; pos  tmpread; pos++) {
 this.crc += b[pos]  0xFF;
@@ -319,8 +318,7 @@
 String name = readCString((int) namesize);
 ret.setName(name);
 if (mode == 0  !name.equals(CPIO_TRAILER)){
-// TODO - change this to throw
-new IOException(Mode 0 only allowed in the trailer. Found: 
+name).printStackTrace();
+throw new IOException(Mode 0 only allowed in the trailer. Found 
entry name: +name);
 }
 skip(ret.getHeaderPadCount());
 
@@ -346,8 +344,7 @@
 final String name = readCString((int) namesize);
 ret.setName(name);
 if (mode == 0  !name.equals(CPIO_TRAILER)){
-// TODO - change this to throw
-new IOException(Mode 0 only allowed in the trailer. Found: 
+name).printStackTrace();
+throw new IOException(Mode 0 only allowed in the trailer. Found 
entry: +name);
 }
 
 return ret;
@@ -373,8 +370,7 @@
 final String name = readCString((int) namesize);
 ret.setName(name);
 if (mode == 0  !name.equals(CPIO_TRAILER)){
-// TODO - change this to throw
-new IOException(Mode 0 only allowed in the trailer. Found: 
+name).printStackTrace();
+throw new IOException(Mode 0 only allowed in the trailer. Found 
entry: +name);
 }
 skip(ret.getHeaderPadCount());
 




svn commit: r760192 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java

2009-03-30 Thread sebb
Author: sebb
Date: Mon Mar 30 21:44:39 2009
New Revision: 760192

URL: http://svn.apache.org/viewvc?rev=760192view=rev
Log:
Re-enable test which is now working.

Modified:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java?rev=760192r1=760191r2=760192view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
 Mon Mar 30 21:44:39 2009
@@ -498,7 +498,7 @@
  * 
  * @throws Exception
  */
-public void XtestDeleteFromAr() throws Exception {
+public void testDeleteFromAr() throws Exception {
 ArchiveOutputStream out = null;
 ArchiveInputStream ais = null;
 File temp = null;
@@ -522,8 +522,6 @@
 ais.close();
 }
 
-// TODO: check ar file. getNextEntry returns null, but ar -t 
tempfile.ar
-// shows still two files
 List expected = new ArrayList();
 expected.add(test1.xml);
 this.checkArchiveContent(temp, expected);




svn commit: r760225 - in /commons/proper/configuration/branches/configuration2_experimental: src/main/java/org/apache/commons/configuration2/tree/ src/test/java/org/apache/commons/configuration2/ src/

2009-03-30 Thread rgoers
Author: rgoers
Date: Mon Mar 30 23:00:32 2009
New Revision: 760225

URL: http://svn.apache.org/viewvc?rev=760225view=rev
Log:
CONFIGURATION-378 Add MergeCombiner

Added:

commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/MergeCombiner.java

commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/tree/TestMergeCombiner.java
Modified:

commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/NodeCombiner.java

commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestDefaultConfigurationBuilder.java

commons/proper/configuration/branches/configuration2_experimental/src/test/resources/testMultiTenentConfigurationBuilder.xml

commons/proper/configuration/branches/configuration2_experimental/src/test/resources/testcombine1.xml

commons/proper/configuration/branches/configuration2_experimental/src/test/resources/testcombine2.xml

commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml

commons/proper/configuration/branches/configuration2_experimental/xdocs/userguide/howto_combinedconfiguration.xml

Added: 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/MergeCombiner.java
URL: 
http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/MergeCombiner.java?rev=760225view=auto
==
--- 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/MergeCombiner.java
 (added)
+++ 
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/tree/MergeCombiner.java
 Mon Mar 30 23:00:32 2009
@@ -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.configuration2.tree;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * p
+ * A specialized implementation of the codeNodeCombiner/code interface
+ * that performs a merge from two passed in node hierarchies.
+ * /p
+ * p
+ * This combiner performs the merge using a few rules:
+ * ol
+ * liNodes can be merged when attributes that appear in both have the same 
value./li
+ * liOnly a single node in the second file is considered a match to the node 
in the first file./li
+ * liAttributes in nodes that match are merged.
+ * liNodes in both files that do not match are added to the result./li
+ * /ol
+ * /p
+ *
+ * @author a
+ * href=http://commons.apache.org/configuration/team-list.html;Commons
+ * Configuration team/a
+ * @version $Id:  $
+ * @since 1.7
+ */
+public class MergeCombiner extends NodeCombiner
+{
+/**
+ * Combines the given nodes to a new union node.
+ *
+ * @param node1 the first source node
+ * @param node2 the second source node
+ * @return the union node
+ */
+
+public ConfigurationNode combine(ConfigurationNode node1, 
ConfigurationNode node2)
+{
+ConfigurationNode result = doCombine(node1, node2);
+printTree(result);
+return result;
+}
+
+public ConfigurationNode doCombine(ConfigurationNode node1, 
ConfigurationNode node2)
+{
+ViewNode result = createViewNode();
+result.setName(node1.getName());
+result.setValue(node1.getValue());
+addAttributes(result, node1, node2);
+
+// Check if nodes can be combined
+List children2 = new LinkedList(node2.getChildren());
+for (Iterator it = node1.getChildren().iterator(); it.hasNext();)
+{
+ConfigurationNode child1 = (ConfigurationNode) it.next();
+ConfigurationNode child2 = canCombine(node1, node2, child1, 
children2);
+if (child2 != null)
+{
+result.addChild(doCombine(child1, child2));
+

svn commit: r760276 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers: ./ ar/ cpio/ tar/ zip/

2009-03-30 Thread sebb
Author: sebb
Date: Tue Mar 31 00:35:56 2009
New Revision: 760276

URL: http://svn.apache.org/viewvc?rev=760276view=rev
Log:
Add generic methods for creating Archive Entries.
This helps with testing, and will make it easier to implement put(File) later

Modified:

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java

commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java?rev=760276r1=760275r2=760276view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java
 Tue Mar 31 00:35:56 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.commons.compress.archivers;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 
@@ -55,6 +56,17 @@
  */
 public abstract void closeArchiveEntry() throws IOException;
 
+/**
+ * Create an archive entry using the inputFile and entryName provided.
+ * 
+ * @param inputFile
+ * @param entryName 
+ * @return the ArchiveEntry set up with details from the file
+ * 
+ * @throws IOException
+ */
+public abstract ArchiveEntry createArchiveEntry(File inputFile, String 
entryName) throws IOException;
+
 // Generic implementations of OutputStream methods that may be useful to 
sub-classes
 
 /**

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java?rev=760276r1=760275r2=760276view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java
 Tue Mar 31 00:35:56 2009
@@ -18,6 +18,8 @@
  */
 package org.apache.commons.compress.archivers.ar;
 
+import java.io.File;
+
 import org.apache.commons.compress.archivers.ArchiveEntry;
 
 /**
@@ -54,7 +56,12 @@
this.lastModified = lastModified;
}
 
-   public long getSize() {
+   public ArArchiveEntry(File inputFile, String entryName) {
+   // TODO sort out mode
+this(entryName, inputFile.length(), 0, 0, 0, inputFile.lastModified());
+}
+
+public long getSize() {
return this.getLength();
}


Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java?rev=760276r1=760275r2=760276view=diff
==
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java
 Tue Mar 31 00:35:56 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.commons.compress.archivers.ar;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.OutputStream;
 
@@ -99,7 +100,7 @@
 
 final String n = pEntry.getName();
 if (n.length()  16) {
-throw new IOException(filename too long);
+throw new IOException(filename too long,  16 chars: +n);
 }
 offset += write(n);
 
@@ -156,4 +157,9 @@
 prevEntry = null;
 }
 

svn commit: r760280 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java

2009-03-30 Thread sebb
Author: sebb
Date: Tue Mar 31 01:01:21 2009
New Revision: 760280

URL: http://svn.apache.org/viewvc?rev=760280view=rev
Log:
Make factory available to test cases
Use generic createArchiveEntry() method so can properly create any archive type
Always check entry size when reading archives

Modified:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java?rev=760280r1=760279r2=760280view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java
 Tue Mar 31 01:01:21 2009
@@ -36,7 +36,6 @@
 import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.ArchiveStreamFactory;
-import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.utils.IOUtils;
 
 public abstract class AbstractTestCase extends TestCase {
@@ -47,7 +46,7 @@
 private File archive; // used to delete the archive in tearDown
 protected List archiveList; // Lists the content of the archive as 
originally created
 
-private ArchiveStreamFactory factory = new ArchiveStreamFactory();
+protected ArchiveStreamFactory factory = new ArchiveStreamFactory();
 
 protected void setUp() throws Exception {
 dir = mkdir(dir);
@@ -168,8 +167,7 @@
  */
 private void addArchiveEntry(ArchiveOutputStream out, String filename, 
final File infile)
 throws IOException, FileNotFoundException {
-ZipArchiveEntry entry = new ZipArchiveEntry(filename);
-entry.setSize(infile.length());
+ArchiveEntry entry = out.createArchiveEntry(infile, filename);
 out.putArchiveEntry(entry);
 IOUtils.copy(new FileInputStream(infile), out);
 out.closeArchiveEntry();
@@ -215,7 +213,8 @@
 archive = File.createTempFile(empty, . + archivename);
 stream = new FileOutputStream(archive);
 out = factory.createArchiveOutputStream(archivename, stream);
-addArchiveEntry(out, testdata/test1.xml, getFile(test1.xml));
+// Use short file name so does not cause problems for ar
+addArchiveEntry(out, test1.xml, getFile(test1.xml));
 } finally {
 if (out != null) {
 out.close();
@@ -247,6 +246,13 @@
 }
 }
 
+/**
+ * Checks that an archive input stream can be read, and that the file data 
matches file sizes.
+ * 
+ * @param in
+ * @param expected list of expected entries or codenull/code if no 
check of names desired
+ * @throws Exception
+ */
 protected void checkArchiveContent(ArchiveInputStream in, List expected)
 throws Exception {
 File result = File.createTempFile(dir-result, );
@@ -267,25 +273,25 @@
 out.close();
 }
 
-if (entry.getSize() != -1) {// some test cases don't set the 
size
-assertEquals(entry.getSize(), copied);
-}
+assertEquals(Entry.size should equal bytes 
read.,entry.getSize(), copied);
 
 if (!outfile.exists()) {
 fail(extraction failed:  + entry.getName());
 }
-if (!expected.remove(entry.getName())) {
+if (expected != null  !expected.remove(entry.getName())) {
 fail(unexpected entry:  + entry.getName());
 }
 }
 in.close();
-if (expected.size()  0) {
+if (expected != null  expected.size()  0) {
 for (Iterator iterator = expected.iterator(); 
iterator.hasNext();) {
 String name = (String) iterator.next();
 fail(Expected entry:  + name);
 }
 }
-assertEquals(0, expected.size());
+if (expected != null) {
+assertEquals(0, expected.size());
+}
 } finally {
 rmdir(result);
 }




svn commit: r760282 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java

2009-03-30 Thread sebb
Author: sebb
Date: Tue Mar 31 01:03:34 2009
New Revision: 760282

URL: http://svn.apache.org/viewvc?rev=760282view=rev
Log:
Use parent factory

Modified:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java?rev=760282r1=760281r2=760282view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/DetectArchiverTestCase.java
 Tue Mar 31 01:03:34 2009
@@ -27,14 +27,12 @@
 
 import org.apache.commons.compress.archivers.ArchiveException;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
-import org.apache.commons.compress.archivers.ArchiveStreamFactory;
 import org.apache.commons.compress.archivers.ar.ArArchiveInputStream;
 import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;
 import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 
 public final class DetectArchiverTestCase extends AbstractTestCase {
-final ArchiveStreamFactory factory = new ArchiveStreamFactory();
 final ClassLoader classLoader = getClass().getClassLoader();
 
 public void testDetection() throws Exception {




svn commit: r760284 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java

2009-03-30 Thread sebb
Author: sebb
Date: Tue Mar 31 01:03:59 2009
New Revision: 760284

URL: http://svn.apache.org/viewvc?rev=760284view=rev
Log:
Add tests of read and write

Added:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java
   (with props)

Added: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java?rev=760284view=auto
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java
 (added)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java
 Tue Mar 31 01:03:59 2009
@@ -0,0 +1,160 @@
+/*
+ * 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.compress;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
+import org.apache.commons.compress.archivers.ar.ArArchiveEntry;
+import org.apache.commons.compress.archivers.cpio.CpioArchiveEntry;
+import org.apache.commons.compress.archivers.jar.JarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+
+/**
+ * Check that the different write methods create the same output.
+ * TODO perform the same checks for reads.
+ */
+public class IOMethodsTest extends AbstractTestCase {
+
+private static final int bytesToTest = 50;
+private static final byte[] byteTest = new byte[bytesToTest];
+static {
+for(int i=0; i  byteTest.length ;) {
+byteTest[i]=(byte) i;
+byteTest[i+1]=(byte) -i;
+i += 2;
+}
+}
+
+public void testWriteAr() throws Exception {
+ArchiveEntry entry = new ArArchiveEntry(dummy, bytesToTest);
+compareWrites(ar, entry);
+}
+public void testWriteCpio() throws Exception {
+ArchiveEntry entry = new CpioArchiveEntry(dummy, bytesToTest);
+compareWrites(cpio, entry);
+}
+public void testWriteJar() throws Exception {
+ArchiveEntry entry = new JarArchiveEntry(dummy);
+compareWrites(jar, entry);
+}
+public void testWriteTar() throws Exception {
+TarArchiveEntry entry = new TarArchiveEntry(dummy);
+entry.setSize(bytesToTest);
+compareWrites(tar, entry);
+}
+public void testWriteZip() throws Exception {
+ArchiveEntry entry = new ZipArchiveEntry(dummy);
+compareWrites(zip, entry);
+}
+
+public void testReadAr() throws Exception {
+compareReads(ar);
+}
+
+public void testReadCpio() throws Exception {
+compareReads(cpio);
+}
+
+public void testReadJar() throws Exception {
+compareReads(jar);
+}
+
+public void testReadTar() throws Exception {
+compareReads(tar);
+}
+
+public void testReadZip() throws Exception {
+compareReads(zip);
+}
+
+private void compareWrites(String archiverName, ArchiveEntry entry) throws 
Exception {
+OutputStream out1 = new ByteArrayOutputStream();
+OutputStream out2 = new ByteArrayOutputStream();
+OutputStream out3 = new ByteArrayOutputStream();
+ArchiveOutputStream aos1 = 
factory.createArchiveOutputStream(archiverName, out1);
+aos1.putArchiveEntry(entry);
+ArchiveOutputStream aos2 = 
factory.createArchiveOutputStream(archiverName, out2);
+aos2.putArchiveEntry(entry);
+ArchiveOutputStream aos3 = 
factory.createArchiveOutputStream(archiverName, out3);
+aos3.putArchiveEntry(entry);
+for (int i=0; ibyteTest.length; i++){
+aos1.write(byteTest[i]);
+}
+aos1.close();
+aos2.write(byteTest);
+aos2.close();
+aos3.write(byteTest, 0, 

svn commit: r760285 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java

2009-03-30 Thread sebb
Author: sebb
Date: Tue Mar 31 01:05:21 2009
New Revision: 760285

URL: http://svn.apache.org/viewvc?rev=760285view=rev
Log:
Allow easy changing of archive type
Change most tests to cpio, because ZipArchiveInputStream fails to set the entry 
size

Modified:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java?rev=760285r1=760284r2=760285view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
 Tue Mar 31 01:05:21 2009
@@ -30,7 +30,6 @@
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
-import org.apache.commons.compress.archivers.ArchiveStreamFactory;
 import org.apache.commons.compress.archivers.ar.ArArchiveEntry;
 import org.apache.commons.compress.archivers.jar.JarArchiveEntry;
 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
@@ -41,8 +40,6 @@
  */
 public final class ChangeSetTestCase extends AbstractTestCase {
 
-private ArchiveStreamFactory factory = new ArchiveStreamFactory();
-
 private void archiveListDelete(String prefix){
 Iterator it = archiveList.iterator();
 while(it.hasNext()){
@@ -54,26 +51,27 @@
 }
 
 /**
- * Tries to delete the folder bla from a zip file. This should result in
+ * Tries to delete the folder bla from an archive file. This should 
result in
  * the deletion of bla/*, which actually means bla/test4.xml should be
- * removed from this zipfile. The file something/bla (without ending, named
+ * removed from the archive. The file something/bla (without ending, named
  * like the folder) should not be deleted.
  * 
  * @throws Exception
  */
 public void testDeleteDir() throws Exception {
-File input = this.createArchive(zip);
+final String archivename = cpio;
+File input = this.createArchive(archivename);
 
 ArchiveOutputStream out = null;
 ArchiveInputStream ais = null;
-File result = File.createTempFile(test, .zip);
+File result = File.createTempFile(test, .+archivename);
 result.deleteOnExit();
 try {
 
 final InputStream is = new FileInputStream(input);
-ais = factory.createArchiveInputStream(zip, is);
+ais = factory.createArchiveInputStream(archivename, is);
 
-out = factory.createArchiveOutputStream(zip,
+out = factory.createArchiveOutputStream(archivename,
 new FileOutputStream(result));
 
 ChangeSet changes = new ChangeSet();
@@ -93,24 +91,25 @@
 }
 
 /**
- * Tries to delete the file bla/test5.xml from a zip file. This should
+ * Tries to delete the file bla/test5.xml from an archive. This should
  * result in the deletion of bla/test5.xml.
  * 
  * @throws Exception
  */
 public void testDeleteFile() throws Exception {
-File input = this.createArchive(zip);
+final String archivename = cpio;
+File input = this.createArchive(archivename);
 
 ArchiveOutputStream out = null;
 ArchiveInputStream ais = null;
-File result = File.createTempFile(test, .zip);
+File result = File.createTempFile(test, .+archivename);
 result.deleteOnExit();
 try {
 
 final InputStream is = new FileInputStream(input);
-ais = factory.createArchiveInputStream(zip, is);
+ais = factory.createArchiveInputStream(archivename, is);
 
-out = factory.createArchiveOutputStream(zip,
+out = factory.createArchiveOutputStream(archivename,
 new FileOutputStream(result));
 
 ChangeSet changes = new ChangeSet();
@@ -137,17 +136,18 @@
  * @throws Exception
  */
 public void testDeletePlusAdd() throws Exception {
-File input = this.createArchive(zip);
+final String archivename = cpio;
+File input = this.createArchive(archivename);
 
 ArchiveOutputStream out = null;
 ArchiveInputStream ais = null;
-File result = File.createTempFile(test, .zip);
+File result = File.createTempFile(test, .+archivename);
 result.deleteOnExit();
 try {
 
 final InputStream is = new FileInputStream(input);
-ais = factory.createArchiveInputStream(zip, is);
-out = 

svn commit: r760294 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java

2009-03-30 Thread sebb
Author: sebb
Date: Tue Mar 31 02:36:04 2009
New Revision: 760294

URL: http://svn.apache.org/viewvc?rev=760294view=rev
Log:
Make sure file is deleted

Modified:

commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java

Modified: 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java?rev=760294r1=760293r2=760294view=diff
==
--- 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java
 (original)
+++ 
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/IOMethodsTest.java
 Tue Mar 31 02:36:04 2009
@@ -117,6 +117,7 @@
 OutputStream out2 = new ByteArrayOutputStream();
 OutputStream out3 = new ByteArrayOutputStream();
 File file = createSingleEntryArchive(archiverName);
+file.deleteOnExit();
 
 InputStream is1 = new FileInputStream(file);
 ArchiveInputStream ais1 = 
factory.createArchiveInputStream(archiverName, is1);