Commits

Sebastian Sdorra  committed 78fce63

added workaround for java 7 ZipInputStream constructor

  • Participants
  • Parent commits 22ef264
  • Branches issue-505

Comments (0)

Files changed (1)

File scm-test/src/main/java/sonia/scm/repository/spi/ZippedRepositoryTestBase.java

 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
+import java.lang.reflect.Constructor;
+
 import java.net.URL;
 
+import java.nio.charset.Charset;
+
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
    *
    *
    * @return
-   *
-   * @throws IOException
    */
   protected File createRepositoryDirectory()
   {
    * Method description
    *
    *
+   * @param url
+   * @param charset
+   *
+   * @return
+   *
+   * @throws IOException
+   */
+  protected ZipInputStream open(URL url, Charset charset) throws IOException
+  {
+    ZipInputStream zis = null;
+
+    // try to use java 7 method to create ZipInputStream
+    try
+    {
+      Constructor<ZipInputStream> constructor =
+        ZipInputStream.class.getConstructor(InputStream.class, Charset.class);
+
+      zis = constructor.newInstance(url.openStream(), charset);
+    }
+    catch (NoSuchMethodException ex) {}
+    catch (Exception ex)
+    {
+      ex.printStackTrace(System.err);
+    }
+
+    // fall back to java 6 method to create ZipInputStream
+    if (zis == null)
+    {
+      zis = new ZipInputStream(url.openStream());
+    }
+
+    return zis;
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @param url
+   *
+   * @return
+   *
+   * @throws IOException
+   */
+  protected ZipInputStream open(URL url) throws IOException
+  {
+    return new ZipInputStream(url.openStream());
+  }
+
+  /**
+   * Method description
+   *
+   *
    * @param folder
    *
    * @throws IOException
 
     try
     {
-      zip = new ZipInputStream(url.openStream());
+      zip = open(url);
 
       ZipEntry entry = zip.getNextEntry();