예제 #1
0
  public static boolean copyJarResourcesRecursively(
      final File destDir, final JarURLConnection jarConnection) throws IOException {

    final JarFile jarFile = jarConnection.getJarFile();

    for (final Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements(); ) {
      final JarEntry entry = e.nextElement();
      if (entry.getName().startsWith(jarConnection.getEntryName())) {
        final String filename = entry.getName();

        final File f = new File(destDir, filename);
        if (!entry.isDirectory()) {
          final InputStream entryInputStream = jarFile.getInputStream(entry);
          if (!FileUtils.copyStream(entryInputStream, f)) {
            return false;
          }
          entryInputStream.close();
        } else {
          if (!FileUtils.ensureDirectoryExists(f)) {
            throw new IOException("Could not create directory: " + f.getAbsolutePath());
          }
        }
      }
    }
    return true;
  }
예제 #2
0
 public static boolean copyResourcesRecursively(final URL originUrl, final File destination) {
   try {
     final URLConnection urlConnection = originUrl.openConnection();
     if (urlConnection instanceof JarURLConnection) {
       return FileUtils.copyJarResourcesRecursively(destination, (JarURLConnection) urlConnection);
     } else {
       return FileUtils.copyFilesRecusively(
           new File(originUrl.getPath().replaceAll("%20", " ")), destination);
     }
   } catch (final IOException e) {
     EmojiTools.submitError(e);
   }
   return false;
 }
예제 #3
0
 public static boolean copyFile(final File toCopy, final File destFile) {
   try {
     return FileUtils.copyStream(new FileInputStream(toCopy), new FileOutputStream(destFile));
   } catch (final FileNotFoundException e) {
     EmojiTools.submitError(e);
   }
   return false;
 }
예제 #4
0
 private static boolean copyStream(final InputStream is, final File f) {
   try {
     return FileUtils.copyStream(is, new FileOutputStream(f));
   } catch (final FileNotFoundException e) {
     EmojiTools.submitError(e);
   }
   return false;
 }
예제 #5
0
  private static boolean copyFilesRecusively(final File toCopy, final File destDir) {
    assert destDir.isDirectory();

    if (!toCopy.isDirectory()) {
      return FileUtils.copyFile(toCopy, new File(destDir, toCopy.getName()));
    } else {
      final File newDestDir = new File(destDir, toCopy.getName());
      if (!newDestDir.exists() && !newDestDir.mkdir()) {
        return false;
      }
      for (final File child : toCopy.listFiles()) {
        if (!FileUtils.copyFilesRecusively(child, newDestDir)) {
          return false;
        }
      }
    }
    return true;
  }