[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [ernie/master 1/2] Enable directory-archive reader to parse bz2 files.



Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Mon, 29 Mar 2010 11:55:13 +0200
Subject: Enable directory-archive reader to parse bz2 files.
Commit: 5b107c990652caabfedb6ba27863622f71595b1f

---
 src/ArchiveReader.java |   18 ++++++++++++++++--
 src/ArchiveWriter.java |    3 ++-
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/ArchiveReader.java b/src/ArchiveReader.java
index 346d870..cebf919 100644
--- a/src/ArchiveReader.java
+++ b/src/ArchiveReader.java
@@ -1,6 +1,7 @@
 import java.io.*;
 import java.util.*;
 import java.util.logging.*;
+import org.apache.commons.compress.compressors.bzip2.*;
 
 /**
  * Read in all files in a given directory and pass buffered readers of
@@ -24,8 +25,21 @@ public class ArchiveReader {
         } else {
           if (rdp != null) {
             try {
-              BufferedInputStream bis =
-                  new BufferedInputStream(new FileInputStream(pop));
+              BufferedInputStream bis = null;
+              System.out.println(pop.getName());
+              if (pop.getName().endsWith("\\.tar\\.bz2")) {
+                logger.warning("Cannot parse compressed tarball "
+                    + pop.getAbsolutePath() + ". Skipping.");
+                continue;
+              } else if (pop.getName().endsWith(".bz2")) {
+                FileInputStream fis = new FileInputStream(pop);
+                BZip2CompressorInputStream bcis =
+                    new BZip2CompressorInputStream(fis);
+                bis = new BufferedInputStream(bcis);
+              } else {
+                FileInputStream fis = new FileInputStream(pop);
+                bis = new BufferedInputStream(fis);
+              }
               ByteArrayOutputStream baos = new ByteArrayOutputStream();
               int len;
               byte[] data = new byte[1024];
diff --git a/src/ArchiveWriter.java b/src/ArchiveWriter.java
index 7af8b22..c4374fd 100644
--- a/src/ArchiveWriter.java
+++ b/src/ArchiveWriter.java
@@ -23,7 +23,8 @@ public class ArchiveWriter {
         bos.close();
       }
     } catch (IOException e) {
-      // TODO handle
+      this.logger.log(Level.WARNING, "Could not store relay descriptor "
+          + filename, e);
     }
   }
 
-- 
1.6.5