Esempio n. 1
0
  /**
   * Gets and writes the first comments of a file.
   *
   * @param file The selected file to get the comments.
   * @param writer The writer which is going to write the comments.
   * @throws IOException If an error occurred with the file.
   */
  private static void writeFileHeaderComments(final File file, final LDIFEntryWriter writer)
      throws IOException {
    BufferedReader br = null;
    try {
      br = new BufferedReader(new FileReader(file));
      String comment = br.readLine();

      while (comment != null && comment.startsWith("#")) {
        writer.writeComment(comment.replaceAll("# ", "").replaceAll("#", ""));
        comment = br.readLine();
      }
    } catch (IOException ex) {
      throw ex;
    } finally {
      StaticUtils.close(br);
    }
  }
Esempio n. 2
0
  /**
   * Returns the path of the installation of the directory server. Note that this method assumes
   * that this code is being run locally.
   *
   * @param installPath The installation path
   * @return the path of the installation of the directory server.
   */
  static String getInstancePathFromInstallPath(final String installPath) {
    String instancePathFileName = Installation.INSTANCE_LOCATION_PATH;
    final File _svcScriptPath = new File(installPath + File.separator + SVC_SCRIPT_FILE_NAME);

    // look for /etc/opt/opendj/instance.loc
    File f = new File(instancePathFileName);
    if (!_svcScriptPath.exists() || !f.exists()) {
      // look for <installPath>/instance.loc
      instancePathFileName =
          installPath + File.separator + Installation.INSTANCE_LOCATION_PATH_RELATIVE;
      f = new File(instancePathFileName);
      if (!f.exists()) {
        return installPath;
      }
    }

    BufferedReader reader;
    try {
      reader = new BufferedReader(new FileReader(instancePathFileName));
    } catch (Exception e) {
      return installPath;
    }

    // Read the first line and close the file.
    String line;
    try {
      line = reader.readLine();
      File instanceLoc = new File(line.trim());
      if (instanceLoc.isAbsolute()) {
        return instanceLoc.getAbsolutePath();
      } else {
        return new File(installPath + File.separator + instanceLoc.getPath()).getAbsolutePath();
      }
    } catch (Exception e) {
      return installPath;
    } finally {
      StaticUtils.close(reader);
    }
  }