コード例 #1
0
  public String extractGarArchive(String garPath) throws CarbonException {
    garPath = AppDeployerUtils.formatPath(garPath);
    String fileName = garPath.substring(garPath.lastIndexOf('/') + 1);

    String javaTempDir = System.getProperty("axis2.work.dir");
    String appUnzipDir =
        javaTempDir.endsWith(File.separator)
            ? javaTempDir + AppDeployerConstants.CARBON_APPS
            : javaTempDir + File.separator + AppDeployerConstants.CARBON_APPS;
    String destinationDir =
        appUnzipDir + File.separator + System.currentTimeMillis() + fileName + File.separator;
    AppDeployerUtils.createDir(destinationDir);

    try {
      extract(garPath, destinationDir);
    } catch (IOException e) {
      throw new CarbonException("Error while extracting cApp artifact : " + fileName, e);
    }

    return destinationDir;
  }
コード例 #2
0
  private static void extract(String sourcePath, String destPath) throws IOException {
    Enumeration entries;
    ZipFile zipFile;

    zipFile = new ZipFile(sourcePath);
    entries = zipFile.entries();

    while (entries.hasMoreElements()) {
      ZipEntry entry = (ZipEntry) entries.nextElement();

      // if the entry is a directory, create a new dir
      if (entry.isDirectory()) {
        AppDeployerUtils.createDir(destPath + entry.getName());
        continue;
      }
      // if the entry is a file, write the file
      copyInputStream(
          zipFile.getInputStream(entry),
          new BufferedOutputStream(new FileOutputStream(destPath + entry.getName())));
    }
    zipFile.close();
  }