コード例 #1
0
ファイル: OpenDJUpgrader.java プロジェクト: kir-dev/openam
  private void copyFileFromWAR(final String fileName) throws IOException {
    message("Copying file " + fileName + " from WAR...");
    InputStream is = null;
    OutputStream os = null;

    try {
      is = AMSetupServlet.getResourceAsStream(servletCtx, "/WEB-INF/" + fileName);
      os = new FileOutputStream(new File(installRoot + "/" + fileName));
      copy(is, os);
      message("done");
    } catch (final IOException ioe) {
      message("failed: " + ioe.getMessage());
      throw ioe;
    } finally {
      closeIfNotNull(is);
      closeIfNotNull(os);
    }
  }
コード例 #2
0
ファイル: OpenDJUpgrader.java プロジェクト: kir-dev/openam
  private void unpackZipFile() throws IOException {
    message("Unzipping " + ZIP_FILE + "...");
    InputStream is = null;
    ZipInputStream zis = null;
    FileOutputStream fos = null;

    try {
      is = AMSetupServlet.getResourceAsStream(servletCtx, ZIP_FILE);
      zis = new ZipInputStream(is);

      for (ZipEntry zipEntry = zis.getNextEntry();
          zipEntry != null;
          zipEntry = zis.getNextEntry()) {
        final File outputFileName = new File(installRoot + "/" + zipEntry.getName());

        if (zipEntry.isDirectory()) {
          outputFileName.mkdir();
        } else {
          // Copy the file.
          fos = new FileOutputStream(outputFileName);
          copy(zis, fos);
          fos.close();

          // Set permissions.
          if (zipEntry.getName().endsWith(".sh") || zipEntry.getName().startsWith("bin")) {
            outputFileName.setExecutable(true);
          }
        }

        zis.closeEntry();
      }

      message("done");
    } catch (final IOException ioe) {
      error("failed: ", ioe);
      throw ioe;
    } finally {
      closeIfNotNull(fos);
      closeIfNotNull(zis);
      closeIfNotNull(is);
    }
  }
コード例 #3
0
ファイル: OpenDJUpgrader.java プロジェクト: kir-dev/openam
  private int readNewVersion() {
    final String pattern = "config/upgrade/config.ldif.";

    InputStream is = null;
    ZipInputStream zis = null;

    try {
      is = AMSetupServlet.getResourceAsStream(servletCtx, ZIP_FILE);
      zis = new ZipInputStream(is);

      for (ZipEntry zipEntry = zis.getNextEntry();
          zipEntry != null;
          zipEntry = zis.getNextEntry()) {
        final String fileName = zipEntry.getName();

        if (fileName.startsWith(pattern)) {
          final String version = fileName.substring(pattern.length());

          try {
            return Integer.parseInt(version);
          } catch (final NumberFormatException nfe) {
            // TODO: log something?
          }
        }

        zis.closeEntry();
      }
    } catch (final IOException ioe) {
      // TODO: log something?
      return 0;
    } finally {
      closeIfNotNull(zis);
      closeIfNotNull(is);
    }

    // TODO: No version found, log something?
    return 0;
  }