FELIX-4764 Add support to GZIP based compact index files

Committed on behalf of Cristiano GaviĆ£o with many thanks!


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1670365 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java
index 9a4d785..aefde53 100644
--- a/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java
+++ b/bundlerepository/src/main/java/org/apache/felix/bundlerepository/impl/DataModelHelperImpl.java
@@ -34,6 +34,7 @@
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
+import java.util.zip.GZIPInputStream;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
@@ -108,6 +109,10 @@
                     entry = zin.getNextEntry();
                 }
             }
+            else if (url.getPath().endsWith(".gz"))
+            {
+                is = new GZIPInputStream(FileUtil.openURL(url));                    
+            }
             else
             {
                 is = FileUtil.openURL(url);
diff --git a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/DataModelHelperTest.java b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/DataModelHelperTest.java
index 3953fd3..758539b 100644
--- a/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/DataModelHelperTest.java
+++ b/bundlerepository/src/test/java/org/apache/felix/bundlerepository/impl/DataModelHelperTest.java
@@ -18,11 +18,14 @@
  */
 package org.apache.felix.bundlerepository.impl;
 
+import java.net.URL;
 import java.util.jar.Attributes;
 
 import junit.framework.TestCase;
 import org.apache.felix.bundlerepository.DataModelHelper;
+import org.apache.felix.bundlerepository.Repository;
 import org.apache.felix.bundlerepository.Resource;
+import static org.junit.Assert.*;
 
 public class DataModelHelperTest extends TestCase
 {
@@ -62,4 +65,16 @@
         r.setFilter("(&(package=javax.transaction)(partial=true)(mandatory:<*partial))");
         assertEquals("(&(package=javax.transaction)(partial=true)(mandatory:<*partial))", r.getFilter());
     }
+    
+    public void testGzipResource() throws Exception {
+        URL urlArchive = getClass().getResource("/spec_repository.gz");
+        assertNotNull("GZ archive was not found", urlArchive);
+        Repository repository1 = dmh.repository(urlArchive);
+
+        URL urlRepo = getClass().getResource("/spec_repository.xml");
+        assertNotNull("Repository file was not found", urlRepo);
+        Repository repository2 = dmh.repository(urlRepo);
+        assertEquals(repository1.getName(), repository2.getName());
+        assertEquals(repository1.getResources().length, repository2.getResources().length);
+    }
 }
diff --git a/bundlerepository/src/test/resources/spec_repository.gz b/bundlerepository/src/test/resources/spec_repository.gz
new file mode 100644
index 0000000..8f065b8
--- /dev/null
+++ b/bundlerepository/src/test/resources/spec_repository.gz
Binary files differ