Ticket #15565

ZipInputStreamでエントリのダンプが上手くいかない

Open Date: 2009-03-16 22:47 Last Update: 2009-03-18 10:10

Reporter:
Owner:
Type:
Status:
Closed
Component:
(None)
MileStone:
(None)
Priority:
5 - Medium
Severity:
7
Resolution:
Fixed
File:
None

Details

以下のコードを実行すると、

commons-net-2.0-src/ size=508433
だけ出力されて処理が終了する。

  • コード
    ZipInputStream zis = new ZipInputStream(new FileInputStream("commons-net-2.0-src.zip"));
    try {
        while (true) {
            ZipEntry entry = zis.getNextEntry();
            if (entry == null) {
                break;
            }
            SizeDetectionOutputStream detector = new SizeDetectionOutputStream();
            long transferred = IOUtilities.transferAll(zis, detector);
            System.out.println(entry.getName() + " size=" + transferred);
            zis.closeEntry();
        }
    } finally {
        zis.close();
    }
    
    

Ticket History (3/3 Histories)

2009-03-16 22:47 Updated by: argius
  • New Ticket "ZipInputStreamでエントリのダンプが上手くいかない" created
2009-03-17 20:36 Updated by: None
Comment

無駄なオーバーライド&スーパークラスの実装にミス。

パッチ。

Index: src/jp/sourceforge/armadillo/zip/ZipInputStream.java
===================================================================
--- src/jp/sourceforge/armadillo/zip/ZipInputStream.java	(revision 16)
+++ src/jp/sourceforge/armadillo/zip/ZipInputStream.java	(working copy)
@@ -113,47 +113,6 @@
     }
 
     /* (overridden)
-     * @see java.io.FilterInputStream#read()
-     */
-    public int read() throws IOException {
-        ensureOpen();
-        int read = frontStream.read();
-        if (read != -1) {
-            --remaining;
-        }
-        return read;
-    }
-
-    /* (overridden)
-     * @see java.util.zip.InflaterInputStream#read(byte[], int, int)
-     */
-    public int read(byte[] b, int off, int len) throws IOException {
-        ensureOpen();
-        int readLength = frontStream.read(b, off, len);
-        if (readLength > 0) {
-            remaining -= readLength;
-        }
-        return readLength;
-    }
-
-    /* (overridden)
-     * @see java.io.FilterInputStream#skip(long)
-     */
-    public long skip(long n) throws IOException {
-        ensureOpen();
-        long skipped;
-        if (frontStream == null) {
-            skipped = in.skip(n);
-        } else {
-            skipped = frontStream.skip(n);
-        }
-        if (skipped > 0) {
-            remaining -= skipped;
-        }
-        return skipped;
-    }
-
-    /* (overridden)
      * @see java.io.FilterInputStream#close()
      */
     public void close() throws IOException {
Index: src/jp/sourceforge/armadillo/io/ArchiveInputStream.java
===================================================================
--- src/jp/sourceforge/armadillo/io/ArchiveInputStream.java	(revision 16)
+++ src/jp/sourceforge/armadillo/io/ArchiveInputStream.java	(working copy)
@@ -37,7 +37,8 @@
      */
     public int read() throws IOException {
         ensureOpen();
-        if (remaining <= 0) {
+        if (frontStream != null && remaining <= 0) {
+            assert remaining == 0;
             return -1;
         }
         InputStream is = (frontStream == null) ? in : frontStream;
@@ -54,7 +55,7 @@
      */
     public int read(byte[] b, int off, int len) throws IOException {
         ensureOpen();
-        if (remaining < 1) {
+        if (frontStream != null && remaining <= 0) {
             assert remaining == 0;
             return -1;
         }
@@ -71,6 +72,10 @@
      */
     public long skip(long n) throws IOException {
         ensureOpen();
+        if (frontStream != null && remaining <= 0) {
+            assert remaining == 0;
+            return -1;
+        }
         long skipped;
         InputStream is = (frontStream == null) ? in : frontStream;
         skipped = is.skip(n);

2009-03-18 10:10 Updated by: argius
  • Resolution Update from None to Fixed
  • Status Update from Open to Closed
  • Ticket Close date is changed to 2009-03-18 10:10

Attachment File List

No attachments

Edit

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Login