Author: bodewig
Date: Sun Oct 23 12:15:13 2011
New Revision: 1187874
URL: http://svn.apache.org/viewvc?rev=1187874&view=rev
Log:
TarArchiveOutputStream's getBytesWritten doesn't work. COMPRESS-160
Added:
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
(with props)
Modified:
commons/proper/compress/trunk/src/changes/changes.xml
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1187874&r1=1187873&r2=1187874&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Sun Oct 23 12:15:13
2011
@@ -68,6 +68,10 @@ The <action> type attribute can be add,u
ZipArchiveInputStream and ZipArchiveOutputStream could leak
resources on some JDKs.
</action>
+ <action issue="COMPRESS-160" type="fix" date="2011-10-23">
+ TarArchiveOutputStream's getBytesWritten method didn't count
+ correctly.
+ </action>
</release>
<release version="1.2" date="2011-07-31"
description="Release 1.2 - a bugfix release, the last release
expected to be compatible with Java 1.4">
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=1187874&r1=1187873&r2=1187874&view=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
Sun Oct 23 12:15:13 2011
@@ -24,6 +24,7 @@ import java.io.OutputStream;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.utils.ArchiveUtils;
+import org.apache.commons.compress.utils.CountingOutputStream;
/**
* The TarOutputStream writes a UNIX tar archive as an OutputStream.
@@ -84,9 +85,9 @@ public class TarArchiveOutputStream exte
* @param recordSize the record size to use
*/
public TarArchiveOutputStream(OutputStream os, int blockSize, int
recordSize) {
- out = os;
+ out = new CountingOutputStream(os);
- this.buffer = new TarBuffer(os, blockSize, recordSize);
+ this.buffer = new TarBuffer(out, blockSize, recordSize);
this.assemLen = 0;
this.assemBuf = new byte[recordSize];
this.recordBuf = new byte[recordSize];
@@ -104,6 +105,17 @@ public class TarArchiveOutputStream exte
}
+ @Deprecated
+ @Override
+ public int getCount() {
+ return (int) getBytesWritten();
+ }
+
+ @Override
+ public long getBytesWritten() {
+ return ((CountingOutputStream) out).getBytesWritten();
+ }
+
/**
* Ends the TAR archive without closing the underlying OutputStream.
*
@@ -324,8 +336,6 @@ public class TarArchiveOutputStream exte
numToWrite -= num;
wOffset += num;
}
-
- count(numToWrite);
}
/**
Added:
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java?rev=1187874&view=auto
==============================================================================
---
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
(added)
+++
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
Sun Oct 23 12:15:13 2011
@@ -0,0 +1,57 @@
+/*
+ * 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.archivers.tar;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+
+import org.apache.commons.compress.AbstractTestCase;
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
+import org.apache.commons.compress.archivers.ArchiveStreamFactory;
+
+public class TarArchiveOutputStreamTest extends AbstractTestCase {
+
+ public void testCount() throws Exception {
+ File f = File.createTempFile("commons-compress-tarcount", ".tar");
+ f.deleteOnExit();
+ FileOutputStream fos = new FileOutputStream(f);
+
+ ArchiveOutputStream tarOut = new ArchiveStreamFactory()
+ .createArchiveOutputStream(ArchiveStreamFactory.TAR, fos);
+
+ File file1 = getFile("test1.xml");
+ TarArchiveEntry sEntry = new TarArchiveEntry(file1);
+ tarOut.putArchiveEntry(sEntry);
+
+ FileInputStream in = new FileInputStream(file1);
+ byte[] buf = new byte[8192];
+
+ int read = 0;
+ while ((read = in.read(buf)) > 0) {
+ tarOut.write(buf, 0, read);
+ }
+
+ in.close();
+ tarOut.closeArchiveEntry();
+ tarOut.close();
+
+ assertEquals(f.length(), tarOut.getBytesWritten());
+ }
+}
\ No newline at end of file
Propchange:
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
------------------------------------------------------------------------------
svn:eol-style = native