Exemplo n.º 1
0
 private boolean extractLibResources(String libFile, String destDir) {
   Log.d(TAG, "Extract from " + libFile);
   ZipFile zipFile = null;
   try {
     zipFile = new ZipFile(libFile);
     for (String resource : XWALK_LIB_RESOURCES) {
       String entryDir = "";
       if (isNativeLibrary(resource)) {
         if (Build.CPU_ABI.equalsIgnoreCase("armeabi")) {
           // We build armeabi-v7a native lib for both armeabi & armeabi-v7a
           entryDir = "lib" + File.separator + "armeabi-v7a" + File.separator;
         } else {
           entryDir = "lib" + File.separator + Build.CPU_ABI + File.separator;
         }
       } else if (isAsset(resource)) {
         entryDir = "assets" + File.separator;
       }
       Log.d(TAG, "unzip " + entryDir + resource);
       ZipEntry entry = zipFile.getEntry(entryDir + resource);
       saveStreamToFile(zipFile.getInputStream(entry), new File(destDir, resource));
     }
   } catch (IOException | NullPointerException e) {
     Log.d(TAG, e.getLocalizedMessage());
     return false;
   } finally {
     try {
       zipFile.close();
     } catch (IOException | NullPointerException e) {
     }
   }
   return true;
 }
Exemplo n.º 2
0
  /**
   * @param args - First parameter is the destination folder in which to overwrite the files. Second
   *     parameter is the source folder from which to get the new files.
   */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    if (args.length >= 2) {
      String destinationFolder = args[1];
      String sourceFolder = args[0];

      List<Path> sourceFolderFileNames = new ArrayList<Path>();
      List<Path> destidationFolderFileNames = new ArrayList<Path>();

      try {
        Files.walk(Paths.get(destinationFolder))
            .forEach(
                fileName -> {
                  if (Files.isRegularFile(fileName)) {
                    destidationFolderFileNames.add(fileName);
                    Path sourcePath =
                        Paths.get(sourceFolder + "\\" + fileName.getFileName().toString());
                    sourceFolderFileNames.add(sourcePath);
                  }
                });

        if (destinationFolder.length() > 0) {
          Iterator<Path> destinationFiles = destidationFolderFileNames.iterator();

          while (destinationFiles.hasNext()) {
            Path targetFile = destinationFiles.next();
            for (int i = 0; i < sourceFolderFileNames.size(); i++) {
              Path sourceFile = sourceFolderFileNames.get(i);
              if (targetFile.getFileName().equals(sourceFile.getFileName())) {
                System.out.println("Target File: " + targetFile.getFileName().toString());
                Runnable task = new OverwriteFileRunnable(sourceFile, targetFile);

                executor.execute(task);
                break;
              }
            }
          }
        } else {
          System.out.println("Folder to overwrite is empty!");
          throw new FileNotFoundException("Folder Empty!");
        }
      } catch (IOException | NullPointerException e) {
        e.printStackTrace();
      }
    }
  }