svn commit: r759143 [1/2] - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
Author: bodewig Date: Fri Mar 27 14:14:07 2009 New Revision: 759143 URL: http://svn.apache.org/viewvc?rev=759143view=rev Log: Improve bzip2 creation speed, submitted by Rodrigo Schmidt to Ant, COMPRESS-58 Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java
svn commit: r759195 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress: archivers/ archivers/ar/ archivers/cpio/ archivers/jar/ archivers/tar/ archivers/zip/ changes/ compre
Author: bodewig Date: Fri Mar 27 16:21:56 2009 New Revision: 759195 URL: http://svn.apache.org/viewvc?rev=759195view=rev Log: minimal package level javadocs Added: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/package.html (with props) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/package.html (with props) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/package.html (with props) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/package.html (with props) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/package.html (with props) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/package.html (with props) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/package.html (with props) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/package.html (with props) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/package.html (with props) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/package.html (with props) commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/utils/package.html (with props) Added: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/package.html URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/package.html?rev=759195view=auto == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/package.html (added) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/package.html Fri Mar 27 16:21:56 2009 @@ -0,0 +1,24 @@ +html +!-- + + 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. + +-- + body +pProvides stream classes for reading and writing archives using + the AR format./p + /body +/html Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/package.html -- svn:eol-style = native Added: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/package.html URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/package.html?rev=759195view=auto == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/package.html (added) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/package.html Fri Mar 27 16:21:56 2009 @@ -0,0 +1,24 @@ +html +!-- + + 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. + +-- + body +pProvides stream classes for reading and writing archives using + the CPIO format./p + /body +/html Propchange: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/package.html -- svn:eol-style = native Added:
svn commit: r759200 - /commons/proper/compress/trunk/src/site/xdoc/index.xml
Author: bodewig Date: Fri Mar 27 16:30:59 2009 New Revision: 759200 URL: http://svn.apache.org/viewvc?rev=759200view=rev Log: remove links to broken examples, update the documentation a little, fix link to svn Modified: commons/proper/compress/trunk/src/site/xdoc/index.xml Modified: commons/proper/compress/trunk/src/site/xdoc/index.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/site/xdoc/index.xml?rev=759200r1=759199r2=759200view=diff == --- commons/proper/compress/trunk/src/site/xdoc/index.xml (original) +++ commons/proper/compress/trunk/src/site/xdoc/index.xml Fri Mar 27 16:30:59 2009 @@ -25,45 +25,47 @@ body section name=Commons Compress p -Commons Compress defines an API for working with tar, zip and bzip2 files. +Commons Compress defines an API for working with ar, +cpio, tar, zip, gzip and bzip2 files. /p p -The code in this component came from Avalon's Excalibur, but originally from Ant, -as far as life in Apache goes. The tar package is originally Tim Endres' public -domain package. The bzip2 package is based on the work done by Keiron Liddle. -It has migrated via:br/ -Ant -gt; Avalon-Excalibur -gt; Commons-IO -gt; Commons-Compress. +The code in this component has many origins: /p +ul + liThe bzip2, tar and zip support came from Avalon's +Excalibur, but originally from Ant, as far as life in +Apache goes. The tar package is originally Tim Endres' +public domain package. The bzip2 package is based on +the work done by Keiron Liddle. It has migrated +via:br/ Ant -gt; Avalon-Excalibur -gt; Commons-IO +-gt; Commons-Compress./li + liThe cpio package has been contributed by Markus Kuss +and +the a href=http://jrpm.sourceforge.net/;jRPM/a +project/li. +/ul subsection name=Status -ul -liThis component has been promoted to Commons proper/li -liThe code is unreleased/li -liMethods and classes can and will appear and disappear without warning/li -liIf you like the code and want to push it towards a release, join the mailing list!/li -/ul + ul +liThis component has been promoted to Commons proper/li +liThe code is unreleased/li +liMethods and classes can and will appear and +disappear without warning/li +liIf you like the code and want to push it towards a +release, join the mailing list!/li + /ul /subsection /section section name=Documentation -ul -liThe a href=apidocs/index.htmlJavadoc/a of the latest SVN/li -liThe a href=http://svn.apache.org/viewvc/commons/compress/;SVN repository/a can be browsed./li -/ul -p -There are also 2 example for the bzip2 API: -/p -ul -li -a href=xref-test/org/apache/commons/compress/bzip2/example/Bzip2Compress.htmlBzip2Compress/a -/li -li -a href=xref-test/org/apache/commons/compress/bzip2/example/Bzip2Uncompress.htmlBzip2UnCompress/a -/li + ul +liThe a href=apidocs/index.htmlJavadoc/a of the latest SVN/li +liThe a href=http://svn.apache.org/viewvc/commons/proper/compress/;SVN +repository/a can be browsed./li /ul /section section name=Releases -p -None. -/p + p +None. + /p /section /body /document
svn commit: r759283 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
Author: sebb Date: Fri Mar 27 17:44:16 2009 New Revision: 759283 URL: http://svn.apache.org/viewvc?rev=759283view=rev Log: Add alignmentBoundary and pad calculation methods to simplify the job for users. Update some Javadoc headerSize can only be an int. Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java?rev=759283r1=759282r2=759283view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java Fri Mar 27 17:44:16 2009 @@ -81,11 +81,16 @@ * FIFOs and directories * * All fields are unsigned short fields with 16-bit integer values + * apart from c_mtime and c_filesize which are 32-bit integer values * /pre * + * pIf necessary, the filename and file data are padded with a NUL byte to an even length/p + * * pSpecial files, directories, and the trailer are recorded with * the h_filesize field equal to 0./p * + * pIn the ASCII version of this format, the 16-bit entries are represented as 6-byte octal numbers, + * and the 32-bit entries are represented as 11-byte octal numbers. No padding is added./p * * h3NEW FORMAT/h3 * @@ -140,12 +145,16 @@ private short fileFormat = 0; // Default chosen so checkNewFormat() and checkOldFormat() both fail /** The number of bytes in each header record; depends on the file format */ -private long headerSize = -1; +private int headerSize = -1; + +/** The boundary to which the header and data elements are aligned: 0, 2 or 4 bytes */ +private int alignmentBoundary; // Header fields private long chksum = 0; +/** Number of bytes in the file */ private long filesize = 0; private long gid = 0; @@ -227,8 +236,10 @@ /** * Get the checksum. + * Only supported for the new formats. * * @return Returns the checksum. + * @throws UnsupportedOperationException if the format is not a new format */ public long getChksum() { checkNewFormat(); @@ -265,6 +276,7 @@ * Get the minor device id * * @return Returns the minor device id. + * @throws UnsupportedOperationException if format is not a new format */ public long getDeviceMin() { checkNewFormat(); @@ -275,10 +287,6 @@ * Get the filesize. * * @return Returns the filesize. - */ -/* - * (non-Javadoc) - * * @see org.apache.commons.compress.archivers.ArchiveEntry#getSize() */ public long getSize() { @@ -304,15 +312,54 @@ } /** - * Get the size of this entry on the stream + * Get the header size for this CPIO format * - * @return Returns the size. + * @return Returns the header size in bytes. */ -public long getHeaderSize() { +public int getHeaderSize() { return this.headerSize; } /** + * Get the alignment boundary for this CPIO format + * + * @return Returns the aligment boundary (0, 2, 4) in bytes + */ +public int getAlignmentBoundary() { +return this.alignmentBoundary; +} + +/** + * Get the number of bytes needed to pad the header to the alignment boundary. + * + * @return the number of bytes needed to pad the header (0,1,2,3) + */ +public int getHeaderPadCount(){ +if (this.alignmentBoundary == 0) return 0; +int size = this.headerSize+this.name.length()+1; // Name has terminating null +int remain = size % this.alignmentBoundary; +if (remain 0){ +return this.alignmentBoundary - remain; +} +return 0; +} + +/** + * Get the number of bytes needed to pad the data to the alignment boundary. + * + * @return the number of bytes needed to pad the data (0,1,2,3) + */ +public int getDataPadCount(){ +if (this.alignmentBoundary == 0) return 0; +long size = this.filesize; +int remain = (int) (size % this.alignmentBoundary); +if (remain 0){ +return this.alignmentBoundary - remain; +} +return 0; +} + +/** * Set the inode. * * @return Returns the inode. @@ -556,15 +603,19 @@ switch (format) { case FORMAT_NEW: this.headerSize = 110; +this.alignmentBoundary = 4; break; case FORMAT_NEW_CRC: this.headerSize = 110; +
svn commit: r759287 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio: CpioArchiveInputStream.java CpioArchiveOutputStream.java
Author: sebb Date: Fri Mar 27 17:51:03 2009 New Revision: 759287 URL: http://svn.apache.org/viewvc?rev=759287view=rev Log: Simplify code by using getXXXPadCount() methods Align variable names (was entry and cpioEntry) Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.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=759287r1=759286r2=759287view=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 Fri Mar 27 17:51:03 2009 @@ -200,13 +200,11 @@ return this.entry; } -private long skip(final long count, final int border) throws IOException { -long skip = count % border; -if (skip 0) { -skip = this.in.skip(border - skip); -// TODO - what if not enough bytes are skipped? +private void skip(int bytes) throws IOException{ +final byte[] buff = new byte[4]; // Cannot be more than 3 bytes +if (bytes 0) { +readFully(buff, 0, bytes); } -return skip; } /** @@ -251,15 +249,10 @@ if (this.entry == null || this.entryEOF) { return -1; } -// N.B. These checks assume format is not 0 - otherwise condition is always true if (this.entryBytesRead == this.entry.getSize()) { -if ((this.entry.getFormat() | FORMAT_NEW_MASK) == FORMAT_NEW_MASK) { -skip(this.entry.getSize(), 4); -} else if ((this.entry.getFormat() | FORMAT_OLD_BINARY) == FORMAT_OLD_BINARY) { -skip(this.entry.getSize(), 2); -} // No need to skip for FORMAT_OLD_ASCII +skip(entry.getDataPadCount()); this.entryEOF = true; -if ((this.entry.getFormat() | FORMAT_NEW_CRC) == FORMAT_NEW_CRC) { +if (this.entry.getFormat() == FORMAT_NEW_CRC) { if (this.crc != this.entry.getChksum()) { throw new IOException(CRC Error); } @@ -345,7 +338,7 @@ // TODO - change this to throw new IOException(Mode 0 only allowed in the trailer. Found: +name).printStackTrace(); } -skip(ret.getHeaderSize() + namesize, 4); +skip(ret.getHeaderPadCount()); return ret; } @@ -383,7 +376,7 @@ long namesize = readBinaryLong(2, swapHalfWord); ret.setSize(readBinaryLong(4, swapHalfWord)); ret.setName(readCString((int) namesize)); -skip(ret.getHeaderSize() + namesize, 2); +skip(ret.getHeaderPadCount()); return ret; } 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=759287r1=759286r2=759287view=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 Fri Mar 27 17:51:03 2009 @@ -60,7 +60,7 @@ public class CpioArchiveOutputStream extends ArchiveOutputStream implements CpioConstants { -private CpioArchiveEntry cpioEntry; +private CpioArchiveEntry entry; private boolean closed = false; @@ -140,7 +140,7 @@ */ public void putNextEntry(final CpioArchiveEntry e) throws IOException { ensureOpen(); -if (this.cpioEntry != null) { +if (this.entry != null) { closeArchiveEntry(); // close previous entry } if (e.getTime() == -1) { @@ -159,7 +159,7 @@ } writeHeader(e); -this.cpioEntry = e; +this.entry = e; this.written = 0; } @@ -200,7 +200,7 @@ writeAsciiLong(entry.getName().length() + 1, 8, 16); writeAsciiLong(entry.getChksum(), 8, 16); writeCString(entry.getName()); -pad(entry.getHeaderSize() + entry.getName().length() + 1, 4); +pad(entry.getHeaderPadCount()); } private void writeOldAsciiEntry(final CpioArchiveEntry entry) @@ -231,7 +231,7 @@
svn commit: r759305 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
Author: sebb Date: Fri Mar 27 18:59:24 2009 New Revision: 759305 URL: http://svn.apache.org/viewvc?rev=759305view=rev Log: unused Modified: 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/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=759305r1=759304r2=759305view=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 Fri Mar 27 18:59:24 2009 @@ -101,7 +101,6 @@ if (current != null) { closeEntry(); } -int x = 0, count = 0; byte[] lfh = new byte[LFH_LEN]; try { readFully(lfh);
svn commit: r759308 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2: BZip2CompressorInputStream.java BZip2CompressorOutputStream.java
Author: sebb Date: Fri Mar 27 19:19:44 2009 New Revision: 759308 URL: http://svn.apache.org/viewvc?rev=759308view=rev Log: Name changed; remove unnecessary casts Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java?rev=759308r1=759307r2=759308view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java Fri Mar 27 19:19:44 2009 @@ -96,7 +96,7 @@ private BZip2CompressorInputStream.Data data; /** - * Constructs a new CBZip2InputStream which decompresses bytes read from the + * Constructs a new BZip2CompressorInputStream which decompresses bytes read from the * specified stream. * * p Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java?rev=759308r1=759307r2=759308view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java Fri Mar 27 19:19:44 2009 @@ -30,7 +30,7 @@ * p * The compression requires large amounts of memory. Thus you should call the * {...@link #close() close()} method as soon as possible, to force - * ttCBZip2OutputStream/tt to release the allocated memory. + * ttBZip2CompressorOutputStream/tt to release the allocated memory. * /p * * p You can shrink the amount of allocated memory and maybe raise @@ -47,7 +47,7 @@ * /pre * * p To get the memory required for decompression by {...@link - * CBZip2InputStream CBZip2InputStream} use /p + * BZip2CompressorInputStream} use /p * * pre * lt;codegt;65k + (5 * blocksize)lt;/codegt;. @@ -112,7 +112,7 @@ * /table * * p - * For decompression ttCBZip2InputStream/tt allocates less memory if the + * For decompression ttBZip2CompressorInputStream/tt allocates less memory if the * bzipped input is smaller than one block. * /p * @@ -1620,7 +1620,7 @@ while (true) { while (unLo = unHi) { -final int n = ((int) block[fmap[unLo] + d1] 0xff) +final int n = (block[fmap[unLo] + d1] 0xff) - med; if (n == 0) { final int temp = fmap[unLo]; @@ -1634,7 +1634,7 @@ } while (unLo = unHi) { -final int n = ((int) block[fmap[unHi] + d1] 0xff) +final int n = (block[fmap[unHi] + d1] 0xff) - med; if (n == 0) { final int temp = fmap[unHi];
svn commit: r759326 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
Author: tcurdt Date: Fri Mar 27 20:09:40 2009 New Revision: 759326 URL: http://svn.apache.org/viewvc?rev=759326view=rev Log: reproduce https://issues.apache.org/jira/browse/COMPRESS-11 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=759326r1=759325r2=759326view=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 Fri Mar 27 20:09:40 2009 @@ -18,18 +18,20 @@ */ package org.apache.commons.compress.archivers; +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; +import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.ar.ArArchiveEntry; import org.apache.commons.compress.utils.IOUtils; -import org.apache.commons.compress.AbstractTestCase; - public final class ArTestCase extends AbstractTestCase { + public void testArArchiveCreation() throws Exception { final File output = new File(dir, bla.ar); @@ -71,7 +73,7 @@ // UnArArchive Operation final File input = output; final InputStream is = new FileInputStream(input); - final ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(ar, is); + final ArchiveInputStream in = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is)); final ArArchiveEntry entry = (ArArchiveEntry)in.getNextEntry(); File target = new File(dir, entry.getName()); @@ -84,4 +86,74 @@ is.close(); } + public void testArDelete() throws Exception { + final File output = new File(dir, bla.ar); + + { + // 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); + 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(); + } + + final File output2 = new File(dir, bla2.ar); + + { + // remove all but one file + final InputStream is = new FileInputStream(output); + final OutputStream os = new FileOutputStream(output2); + final ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream(ar, os); + final ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is)); + while(true) { + final ArArchiveEntry entry = (ArArchiveEntry)ais.getNextEntry(); + if (entry == null) { + break; + } + + if (test1.xml.equals(entry.getName())) { + aos.putArchiveEntry(entry); + } + } + ais.close(); + aos.close(); + is.close(); + os.close(); + } + + + long sum = 0; + + { + final InputStream is = new FileInputStream(output2); + final ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(is); + while(true) { + final ArArchiveEntry entry = (ArArchiveEntry)ais.getNextEntry(); + if
svn commit: r759335 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
Author: tcurdt Date: Fri Mar 27 20:35:23 2009 New Revision: 759335 URL: http://svn.apache.org/viewvc?rev=759335view=rev Log: fixed the testcase 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=759335r1=759334r2=759335view=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 Fri Mar 27 20:35:23 2009 @@ -123,7 +123,11 @@ if (test1.xml.equals(entry.getName())) { aos.putArchiveEntry(entry); + IOUtils.copy(ais, aos); + } else { + IOUtils.copy(ais, new ByteArrayOutputStream()); } + } ais.close(); aos.close(); @@ -136,15 +140,14 @@ { final InputStream is = new FileInputStream(output2); - final ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(is); + final ArchiveInputStream ais = new ArchiveStreamFactory().createArchiveInputStream(new BufferedInputStream(is)); while(true) { final ArArchiveEntry entry = (ArArchiveEntry)ais.getNextEntry(); if (entry == null) { break; } - final ByteArrayOutputStream os = new ByteArrayOutputStream(); - IOUtils.copy(ais, os); + IOUtils.copy(ais, new ByteArrayOutputStream()); sum += entry.getLength(); } @@ -152,7 +155,7 @@ is.close(); } - assertEquals(0, sum); + assertEquals(76, sum); }
svn commit: r759338 - in /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers: JarTestCase.java ZipTestCase.java
Author: sebb Date: Fri Mar 27 20:44:59 2009 New Revision: 759338 URL: http://svn.apache.org/viewvc?rev=759338view=rev Log: Close files Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java?rev=759338r1=759337r2=759338view=diff == --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java Fri Mar 27 20:44:59 2009 @@ -79,6 +79,7 @@ out.close(); in.close(); +is.close(); } public void testJarUnarchiveAll() throws Exception { @@ -102,6 +103,7 @@ } in.close(); + is.close(); } } Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java?rev=759338r1=759337r2=759338view=diff == --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java Fri Mar 27 20:44:59 2009 @@ -57,10 +57,9 @@ } finally { if (os != null) { os.close(); -} else { -out.close(); } } +out.close(); // Unarchive the same List results = new ArrayList(); @@ -86,10 +85,9 @@ } finally { if (in != null) { in.close(); -} else { -is.close(); } } +is.close(); assertEquals(results.size(), 2); File result = (File)results.get(0);
svn commit: r759339 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java
Author: sebb Date: Fri Mar 27 20:45:58 2009 New Revision: 759339 URL: http://svn.apache.org/viewvc?rev=759339view=rev Log: Recursive delete of temporary directories 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=759339r1=759338r2=759339view=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 Fri Mar 27 20:45:58 2009 @@ -76,10 +76,19 @@ String[] s = f.list(); if (s != null) { for (int i = 0; i s.length; i++) { -new File(f, s[i]).delete(); +final File file = new File(f, s[i]); +if (file.isDirectory()){ +rmdir(file); +} +boolean ok = file.delete(); +if (!ok file.exists()){ +System.out.println(Failed to delete +s[i]+ in +f.getPath()); +} } } -f.delete(); +if (!f.delete()){ +throw new Error(Failed to delete +f.getPath()); +} } /** @@ -240,5 +249,6 @@ } } assertEquals(0, expected.size()); +rmdir(result); } }
svn commit: r759343 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
Author: sebb Date: Fri Mar 27 20:47:04 2009 New Revision: 759343 URL: http://svn.apache.org/viewvc?rev=759343view=rev Log: Caller must already have set the entry format Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.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=759343r1=759342r2=759343view=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 Fri Mar 27 20:47:04 2009 @@ -148,9 +148,7 @@ } final short format = e.getFormat(); -if (format == 0) {// Not yet initialised -e.setFormat(this.entryFormat); -} else if (format != this.entryFormat){ +if (format != this.entryFormat){ throw new IOException(Header format: +format+ does not match existing format: +this.entryFormat); }
svn commit: r759344 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
Author: sebb Date: Fri Mar 27 20:47:56 2009 New Revision: 759344 URL: http://svn.apache.org/viewvc?rev=759344view=rev Log: Make entry constants final Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java?rev=759344r1=759343r2=759344view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java Fri Mar 27 20:47:56 2009 @@ -134,6 +134,8 @@ * * pThe MAGIC numbers and other constants are defined in {...@link CpioConstants} * @see http://people.freebsd.org/~kientzle/libarchive/man/cpio.5.txt; + * + * @NotThreadSafe */ public class CpioArchiveEntry implements CpioConstants, ArchiveEntry { @@ -142,13 +144,13 @@ /** * See {...@link CpioArchiveEntry#setFormat(short)} for possible values. */ -private short fileFormat = 0; // Default chosen so checkNewFormat() and checkOldFormat() both fail +private final short fileFormat; /** The number of bytes in each header record; depends on the file format */ -private int headerSize = -1; +private final int headerSize; /** The boundary to which the header and data elements are aligned: 0, 2 or 4 bytes */ -private int alignmentBoundary; +private final int alignmentBoundary; // Header fields @@ -184,9 +186,37 @@ * * @param format *The cpio format for this entry. + * br/ + * Possible format values are: + * p + * CpioConstants.FORMAT_NEWbr/ + * CpioConstants.FORMAT_NEW_CRCbr/ + * CpioConstants.FORMAT_OLD_BINARYbr/ + * CpioConstants.FORMAT_OLD_ASCIIbr/ + * */ public CpioArchiveEntry(final short format) { -setFormat(format); +switch (format) { +case FORMAT_NEW: +this.headerSize = 110; +this.alignmentBoundary = 4; +break; +case FORMAT_NEW_CRC: +this.headerSize = 110; +this.alignmentBoundary = 4; +break; +case FORMAT_OLD_ASCII: +this.headerSize = 76; +this.alignmentBoundary = 0; +break; +case FORMAT_OLD_BINARY: +this.headerSize = 26; +this.alignmentBoundary = 2; +break; +default: +throw new IllegalArgumentException(Unknown header type); +} +this.fileFormat = format; } /** @@ -587,43 +617,6 @@ } /** - * Set the header format for this entry. - * br/ - * Possible values are: - * p - * {...@link CpioConstants.FORMAT_NEW}br/ - * {...@link CpioConstants.FORMAT_NEW_CRC}br/ - * {...@link CpioConstants.FORMAT_OLD_BINARY}br/ - * {...@link CpioConstants.FORMAT_OLD_ASCII}br/ - * - * @param format - *The format to set. - */ -final void setFormat(final short format) { -switch (format) { -case FORMAT_NEW: -this.headerSize = 110; -this.alignmentBoundary = 4; -break; -case FORMAT_NEW_CRC: -this.headerSize = 110; -this.alignmentBoundary = 4; -break; -case FORMAT_OLD_ASCII: -this.headerSize = 76; -this.alignmentBoundary = 0; -break; -case FORMAT_OLD_BINARY: -this.headerSize = 26; -this.alignmentBoundary = 2; -break; -default: -throw new IllegalArgumentException(Unknown header type); -} -this.fileFormat = format; -} - -/** * Set the group id. * * @param gid
svn commit: r759346 - in /commons/proper/configuration/trunk: conf/ src/java/org/apache/commons/configuration/ src/java/org/apache/commons/configuration/tree/ src/test/org/apache/commons/configuration
Author: rgoers Date: Fri Mar 27 20:53:16 2009 New Revision: 759346 URL: http://svn.apache.org/viewvc?rev=759346view=rev Log: CONFIGURATION-378 Add MergeCombiner Added: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/tree/MergeCombiner.java - copied, changed from r757541, commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/tree/OverrideCombiner.java commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestMergeCombiner.java - copied, changed from r757541, commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestOverrideCombiner.java Modified: commons/proper/configuration/trunk/conf/testMultiTenentConfigurationBuilder.xml commons/proper/configuration/trunk/conf/testcombine1.xml commons/proper/configuration/trunk/conf/testcombine2.xml commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/tree/NodeCombiner.java commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java commons/proper/configuration/trunk/xdocs/changes.xml commons/proper/configuration/trunk/xdocs/userguide/howto_combinedconfiguration.xml Modified: commons/proper/configuration/trunk/conf/testMultiTenentConfigurationBuilder.xml URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/testMultiTenentConfigurationBuilder.xml?rev=759346r1=759345r2=759346view=diff == --- commons/proper/configuration/trunk/conf/testMultiTenentConfigurationBuilder.xml (original) +++ commons/proper/configuration/trunk/conf/testMultiTenentConfigurationBuilder.xml Fri Mar 27 20:53:16 2009 @@ -5,6 +5,7 @@ result delimiterParsingDisabled=true forceReloadCheck=true config-class=org.apache.commons.configuration.DynamicCombinedConfiguration keyPattern=$${sys:Id} + nodeCombiner config-class=org.apache.commons.configuration.tree.MergeCombiner/ expressionEngine config-class=org.apache.commons.configuration.tree.xpath.XPathExpressionEngine/ /result Modified: commons/proper/configuration/trunk/conf/testcombine1.xml URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/testcombine1.xml?rev=759346r1=759345r2=759346view=diff == --- commons/proper/configuration/trunk/conf/testcombine1.xml (original) +++ commons/proper/configuration/trunk/conf/testcombine1.xml Fri Mar 27 20:53:16 2009 @@ -49,4 +49,15 @@ /table /tables /database + Channels +Channel id=1 type=half + NameMy Channel/Name +/Channel +Channel id=2 + MoreChannelDatamore test 2 data/MoreChannelData +/Channel +Channel id=3 type=half + NameTest Channel/Name +/Channel + /Channels /config Modified: commons/proper/configuration/trunk/conf/testcombine2.xml URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/testcombine2.xml?rev=759346r1=759345r2=759346view=diff == --- commons/proper/configuration/trunk/conf/testcombine2.xml (original) +++ commons/proper/configuration/trunk/conf/testcombine2.xml Fri Mar 27 20:53:16 2009 @@ -45,4 +45,18 @@ /table /tables /database + Channels +Channel id=1 + NameChannel 1/Name + ChannelDatatest 1 data/ChannelData +/Channel +Channel id=2 type=full + NameChannel 2/Name + ChannelDatatest 2 data/ChannelData +/Channel +Channel id=3 type=full + NameChannel 3/Name + ChannelDatatest 3 data/ChannelData +/Channel + /Channels /config Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java?rev=759346r1=759345r2=759346view=diff == --- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java (original) +++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java Fri Mar 27 20:53:16 2009 @@ -36,6 +36,7 @@ import org.apache.commons.configuration.tree.DefaultExpressionEngine; import org.apache.commons.configuration.tree.ExpressionEngine; import org.apache.commons.configuration.tree.NodeAddData; +import org.apache.commons.configuration.tree.ViewNode; import org.apache.commons.lang.StringUtils; /** @@ -1331,12 +1332,28 @@ for (Iterator it = getChildren().iterator(); it.hasNext()
svn commit: r759349 - /commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestMergeCombiner.java
Author: rgoers Date: Fri Mar 27 20:58:25 2009 New Revision: 759349 URL: http://svn.apache.org/viewvc?rev=759349view=rev Log: Don't print the xml during the unit test Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestMergeCombiner.java Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestMergeCombiner.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestMergeCombiner.java?rev=759349r1=759348r2=759349view=diff == --- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestMergeCombiner.java (original) +++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/tree/TestMergeCombiner.java Fri Mar 27 20:58:25 2009 @@ -125,7 +125,7 @@ public void testMerge() throws ConfigurationException { -combiner.setDebugStream(System.out); +//combiner.setDebugStream(System.out); HierarchicalConfiguration config = createCombinedConfiguration(); config.setExpressionEngine(new XPathExpressionEngine()); assertEquals(Wrong number of Channels, 3, config.getMaxIndex(Channels/Channel));
svn commit: r759352 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/ArTestCase.java
Author: tcurdt Date: Fri Mar 27 21:08:27 2009 New Revision: 759352 URL: http://svn.apache.org/viewvc?rev=759352view=rev Log: tracked down the problem of https://issues.apache.org/jira/browse/COMPRESS-11 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=759352r1=759351r2=759352view=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 Fri Mar 27 21:08:27 2009 @@ -107,10 +107,16 @@ out.close(); } + assertEquals(282, output.length()); + final File output2 = new File(dir, bla2.ar); + int copied = 0; + int deleted = 0; + { // remove all but one file + final InputStream is = new FileInputStream(output); final OutputStream os = new FileOutputStream(output2); final ArchiveOutputStream aos = new ArchiveStreamFactory().createArchiveOutputStream(ar, os); @@ -124,8 +130,11 @@ if (test1.xml.equals(entry.getName())) { aos.putArchiveEntry(entry); IOUtils.copy(ais, aos); + aos.closeArchiveEntry(); + copied++; } else { IOUtils.copy(ais, new ByteArrayOutputStream()); + deleted++; } } @@ -135,7 +144,11 @@ os.close(); } + assertEquals(1, copied); + assertEquals(1, deleted); + assertEquals(144, output2.length()); + long files = 0; long sum = 0; { @@ -150,11 +163,13 @@ IOUtils.copy(ais, new ByteArrayOutputStream()); sum += entry.getLength(); + files++; } ais.close(); is.close(); } + assertEquals(1, files); assertEquals(76, sum); }
svn commit: r759355 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar: ArArchiveEntry.java ArArchiveInputStream.java ArArchiveOutputStream.java
Author: sebb Date: Fri Mar 27 21:13:51 2009 New Revision: 759355 URL: http://svn.apache.org/viewvc?rev=759355view=rev Log: Javadoc - thread safety Modified: 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/ArArchiveInputStream.java 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/ArArchiveEntry.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveEntry.java?rev=759355r1=759354r2=759355view=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 Fri Mar 27 21:13:51 2009 @@ -22,6 +22,8 @@ /** * Represents an archive entry in the ar format. + * + * @Immutable */ public class ArArchiveEntry implements ArchiveEntry { 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=759355r1=759354r2=759355view=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 Fri Mar 27 21:13:51 2009 @@ -25,7 +25,10 @@ import org.apache.commons.compress.archivers.ArchiveInputStream; /** - * Implements the ar archive format as an input stream + * Implements the ar archive format as an input stream. + * + * This class is thread-safe if the InputStream is thread-safe. + * */ public class ArArchiveInputStream extends ArchiveInputStream { 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=759355r1=759354r2=759355view=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 Fri Mar 27 21:13:51 2009 @@ -25,7 +25,9 @@ import org.apache.commons.compress.archivers.ArchiveOutputStream; /** - * Implements the ar archive format as an output stream + * Implements the ar archive format as an output stream. + * + * @NotThreadSafe */ public class ArArchiveOutputStream extends ArchiveOutputStream {
svn commit: r759359 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java
Author: sebb Date: Fri Mar 27 21:37:14 2009 New Revision: 759359 URL: http://svn.apache.org/viewvc?rev=759359view=rev Log: Class was not thread-safe: - external byte array was stored directly - List was created and then modified via the final variable Fixed by copying byte array and storing List once as unmodifiable List Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java?rev=759359r1=759358r2=759359view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Simple8BitZipEncoding.java Fri Mar 27 21:37:14 2009 @@ -42,6 +42,7 @@ * implementation, Cp437 and Cp850./p * * pThe methods of this class are reentrant./p + * @Immutable */ class Simple8BitZipEncoding implements ZipEncoding { @@ -88,17 +89,17 @@ * stored as an array of 128 chars. */ public Simple8BitZipEncoding(char[] highChars) { -this.highChars = highChars; -this.reverseMapping = new ArrayList(this.highChars.length); +this.highChars = (char[]) highChars.clone(); +List temp = new ArrayList(this.highChars.length); byte code = 127; for (int i = 0; i this.highChars.length; ++i) { -this.reverseMapping.add(new Simple8BitChar(++code, - this.highChars[i])); +temp.add(new Simple8BitChar(++code, this.highChars[i])); } -Collections.sort(this.reverseMapping); +Collections.sort(temp); +this.reverseMapping = Collections.unmodifiableList(temp); } /**
svn commit: r759371 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java
Author: sebb Date: Fri Mar 27 22:02:20 2009 New Revision: 759371 URL: http://svn.apache.org/viewvc?rev=759371view=rev Log: Fix malicious code / thread-safety bug Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java?rev=759371r1=759370r2=759371view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipUtil.java Fri Mar 27 22:02:20 2009 @@ -22,6 +22,10 @@ import java.util.Date; import java.util.zip.CRC32; +/** + * Utility class for handling DOS and Java time conversions. + * @Immutable + */ public abstract class ZipUtil { /** * Smallest date/time ZIP can handle. @@ -50,7 +54,7 @@ // here will improve the readablity int year = time.getYear() + 1900; if (year 1980) { -return DOS_TIME_MIN; +return (byte[]) DOS_TIME_MIN.clone(); // stop callers from changing the array } int month = time.getMonth() + 1; long value = ((year - 1980) 25) Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java?rev=759371r1=759370r2=759371view=diff == --- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java (original) +++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipUtilTest.java Fri Mar 27 22:02:20 2009 @@ -74,4 +74,11 @@ ZipUtil.adjustToLong(2 * Integer.MAX_VALUE)); } +public void testMinTime(){ +byte[] b1 = ZipUtil.toDosTime(0); +byte b10 = b1[0]; // Save the first byte +b1[0]++; // change it +byte[] b2 = ZipUtil.toDosTime(0); // get the same time +assertEquals(b10,b2[0]); // first byte should still be the same +} }
svn commit: r759392 - /commons/proper/cli/trunk/pom.xml
Author: sebb Date: Fri Mar 27 23:37:56 2009 New Revision: 759392 URL: http://svn.apache.org/viewvc?rev=759392view=rev Log: JUnit 3.8.2 is best for Java 1.4 Modified: commons/proper/cli/trunk/pom.xml Modified: commons/proper/cli/trunk/pom.xml URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/pom.xml?rev=759392r1=759391r2=759392view=diff == --- commons/proper/cli/trunk/pom.xml (original) +++ commons/proper/cli/trunk/pom.xml Fri Mar 27 23:37:56 2009 @@ -122,7 +122,7 @@ dependency groupIdjunit/groupId artifactIdjunit/artifactId - version3.8.1/version + version3.8.2/version scopetest/scope /dependency /dependencies
svn commit: r759399 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress: archivers/jar/ archivers/tar/ archivers/zip/ compressors/bzip2/
Author: sebb Date: Sat Mar 28 00:04:36 2009 New Revision: 759399 URL: http://svn.apache.org/viewvc?rev=759399view=rev Log: Not thread-safe Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveEntry.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveInputStream.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/TarArchiveEntry.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/tar/TarArchiveOutputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/AbstractUnicodeExtraField.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/AsiExtraField.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnicodeCommentExtraField.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnicodePathExtraField.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnrecognizedExtraField.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/ZipArchiveInputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorInputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2CompressorOutputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/CRC.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveEntry.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveEntry.java?rev=759399r1=759398r2=759399view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveEntry.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveEntry.java Sat Mar 28 00:04:36 2009 @@ -27,6 +27,10 @@ import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; +/** + * + * @NotThreadSafe + */ public class JarArchiveEntry extends ZipArchiveEntry implements ArchiveEntry { private Attributes manifestAttributes = null; Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveInputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveInputStream.java?rev=759399r1=759398r2=759399view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveInputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveInputStream.java Sat Mar 28 00:04:36 2009 @@ -25,6 +25,11 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; +/** + * Implements an input stream that can read entries from jar files. + * + * @NotThreadSafe + */ public class JarArchiveInputStream extends ZipArchiveInputStream { public JarArchiveInputStream( final InputStream inputStream ) { 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=759399r1=759398r2=759399view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStream.java (original) +++
svn commit: r759403 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java
Author: sebb Date: Sat Mar 28 00:07:58 2009 New Revision: 759403 URL: http://svn.apache.org/viewvc?rev=759403view=rev Log: Oops, did not mean to commit that change to the file Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java?rev=759403r1=759402r2=759403view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java Sat Mar 28 00:07:58 2009 @@ -46,7 +46,7 @@ * * @see Simple8BitZipEncoding#Simple8BitZipEncoding(char[]) */ -SimpleEncodingHolderxx(char [] highChars) { +SimpleEncodingHolder(char [] highChars) { this.highChars = highChars; }
svn commit: r759415 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
Author: sebb Date: Sat Mar 28 01:26:22 2009 New Revision: 759415 URL: http://svn.apache.org/viewvc?rev=759415view=rev Log: Not thread-safe 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=759415r1=759414r2=759415view=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 Sat Mar 28 01:26:22 2009 @@ -27,7 +27,7 @@ /** * Implements the ar archive format as an input stream. * - * This class is thread-safe if the InputStream is thread-safe. + * @NotThreadSafe * */ public class ArArchiveInputStream extends ArchiveInputStream {
svn commit: r759421 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
Author: sebb Date: Sat Mar 28 02:39:01 2009 New Revision: 759421 URL: http://svn.apache.org/viewvc?rev=759421view=rev Log: Not needed, as it duplicates the code in InputStream Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java 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=759421r1=759420r2=759421view=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 Sat Mar 28 02:39:01 2009 @@ -399,12 +399,6 @@ hasHitEOF = b; } - -// used to be implemented via FilterInputStream -public int read(byte[] b) throws IOException { -return read(b, 0, b.length); -} - // ArchiveInputStream public static boolean matches(byte[] signature, int length) {
svn commit: r759425 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers: cpio/CpioArchiveInputStream.java zip/ZipLong.java
Author: sebb Date: Sat Mar 28 03:18:42 2009 New Revision: 759425 URL: http://svn.apache.org/viewvc?rev=759425view=rev Log: DOcument and simplify Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.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=759425r1=759424r2=759425view=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 Sat Mar 28 03:18:42 2009 @@ -257,7 +257,7 @@ throw new IOException(CRC Error); } } -return -1; +return -1; // EOF for this entry } int tmplength = (int) Math.min(len, this.entry.getSize() - this.entryBytesRead); @@ -267,7 +267,7 @@ int tmpread = this.in.read(b, off, tmplength); // TODO - what about EOF or short reads? -if ((this.entry.getFormat() | FORMAT_NEW_CRC) == FORMAT_NEW_CRC) { +if (this.entry.getFormat() == FORMAT_NEW_CRC) { for (int pos = 0; pos tmpread; pos++) { this.crc += b[pos] 0xFF; } Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java?rev=759425r1=759424r2=759425view=diff == --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipLong.java Sat Mar 28 03:18:42 2009 @@ -42,7 +42,10 @@ private final long value; +/** Central File Header Signature */ public static final ZipLong CFH_SIG = new ZipLong(0X02014B50L); + +/** Local File Header Signature */ public static final ZipLong LFH_SIG = new ZipLong(0X04034B50L); /**
svn commit: r759426 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java
Author: sebb Date: Sat Mar 28 03:31:42 2009 New Revision: 759426 URL: http://svn.apache.org/viewvc?rev=759426view=rev Log: 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=759426r1=759425r2=759426view=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 Sat Mar 28 03:31:42 2009 @@ -21,6 +21,21 @@ import java.io.IOException; 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 + * ready for reading the data from the next entry. + * p + * The input stream classes must also implement a method with the signature: + * pre + * public static boolean matches(byte[] signature, int length) + * /pre + * which is used by the {...@link ArchiveStreamFactory} to autodetect + * the archive type from the first few bytes of a stream. + */ public abstract class ArchiveInputStream extends InputStream { /**
svn commit: r759045 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/optimization/linear/SimplexTableau.java test/org/apache/commons/math/optimization/linear/SimplexSolverTest.java
Author: luc Date: Fri Mar 27 07:56:04 2009 New Revision: 759045 URL: http://svn.apache.org/viewvc?rev=759045view=rev Log: fixed an error in Simplex algorithm when several ambiguous solutions exist Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/linear/SimplexSolverTest.java Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java?rev=759045r1=759044r2=759045view=diff == --- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java (original) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/SimplexTableau.java Fri Mar 27 07:56:04 2009 @@ -327,9 +327,20 @@ * @return The value of the given decision variable. */ protected double getDecisionVariableValue(final int decisionVariable) { -Integer basicRow = getBasicRow(getNumObjectiveFunctions() + decisionVariable); -return basicRow == null ? 0 : getEntry(basicRow, getRhsOffset()); -} + int col = getNumObjectiveFunctions() + decisionVariable; + Integer basicRow = getBasicRow(col); + if (basicRow == null) { + return 0; + } + // if there are multiple variables that can take the value on the RHS + // then we'll give the first variable that value + for (int i = getNumObjectiveFunctions(); i col; i++) { + if (tableau.getEntry(basicRow, i) == 1) { + return 0; + } + } + return getEntry(basicRow, getRhsOffset()); + } /** * Subtracts a multiple of one row from another. Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/linear/SimplexSolverTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/linear/SimplexSolverTest.java?rev=759045r1=759044r2=759045view=diff == --- commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/linear/SimplexSolverTest.java (original) +++ commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/linear/SimplexSolverTest.java Fri Mar 27 07:56:04 2009 @@ -143,7 +143,7 @@ assertEquals(1438556.7491409, solution.getValue(), .001); } -public void testSomething() throws OptimizationException { +public void testTrivialModel() throws OptimizationException { LinearObjectiveFunction f = new LinearObjectiveFunction(new double[] { 1, 1 }, 0); CollectionLinearConstraint constraints = new ArrayListLinearConstraint(); constraints.add(new LinearConstraint(new double[] { 1, 1 }, Relationship.EQ, 0)); @@ -276,8 +276,7 @@ SimplexSolver solver = new SimplexSolver(); RealPointValuePair solution = solver.optimize(f, constraints, GoalType.MINIMIZE, true); -assertEquals(13366.0, solution.getValue(), .001); -//assertEquals(7518.0, solution.getValue(), .001); +assertEquals(7518.0, solution.getValue(), .001); } /**