Exemplo n.º 1
0
 public SDKDownloader(PathManager pathManager) {
   this.pathManager = pathManager;
   platformZipPath = pathManager.getRootForDownload() + "/platforms.zip";
   platformToolsZipPath = pathManager.getRootForDownload() + "/platform-tools.zip";
   toolsZipPath = pathManager.getRootForDownload() + "/tools.zip";
   antZipPath = pathManager.getRootForDownload() + "/apache-ant-1.8.0.zip";
 }
Exemplo n.º 2
0
  protected void unzip(String pathToFile, String outputFolder) {
    System.out.println("Start unzipping: " + pathToFile + " to " + outputFolder);
    String pathToUnzip;
    if (outputFolder.equals(pathManager.getPlatformFolderInAndroidSdk())) {
      pathToUnzip = outputFolder;
    } else {
      pathToUnzip = outputFolder + "/" + FileUtil.getNameWithoutExtension(new File(pathToFile));
    }
    if (new File(pathToUnzip).listFiles() != null) {
      System.out.println("File was already unzipped: " + pathToFile);
      return;
    }
    try {
      byte[] buf = new byte[1024];
      ZipInputStream zipinputstream = null;
      ZipEntry zipentry;
      zipinputstream = new ZipInputStream(new FileInputStream(pathToFile));

      zipentry = zipinputstream.getNextEntry();
      try {
        while (zipentry != null) {
          String entryName = zipentry.getName();
          int n;
          File outputFile = new File(outputFolder + "/" + entryName);

          if (zipentry.isDirectory()) {
            outputFile.mkdirs();
            zipinputstream.closeEntry();
            zipentry = zipinputstream.getNextEntry();
            continue;
          } else {
            File parentFile = outputFile.getParentFile();
            if (parentFile != null && !parentFile.exists()) {
              parentFile.mkdirs();
            }
            outputFile.createNewFile();
          }

          FileOutputStream fileoutputstream = new FileOutputStream(outputFile);
          try {
            while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
              fileoutputstream.write(buf, 0, n);
            }
          } finally {
            fileoutputstream.close();
          }
          zipinputstream.closeEntry();
          zipentry = zipinputstream.getNextEntry();
        }

        zipinputstream.close();
      } catch (IOException e) {
        System.err.println("Entry name: " + zipentry.getName());
        e.printStackTrace();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.out.println("Finish unzipping: " + pathToFile + " to " + outputFolder);
  }
Exemplo n.º 3
0
 public void unzipAll() {
   unzip(platformZipPath, pathManager.getPlatformFolderInAndroidSdk());
   unzip(platformToolsZipPath, pathManager.getAndroidSdkRoot());
   unzip(toolsZipPath, pathManager.getAndroidSdkRoot());
   unzip(antZipPath, pathManager.getDependenciesRoot());
 }