Ejemplo n.º 1
0
 /**
  * Copy a file from a source directory to a destination directory (if it is not there already). If
  * <code>overwrite</code> is true and the destination file already exists, overwrite it.
  *
  * @param configuration Holds the error message
  * @param file The name of the file to copy
  * @param source The source directory
  * @param destination The destination directory where the file needs to be copied
  * @param overwrite A flag to indicate whether the file in the destination directory will be
  *     overwritten if it already exists.
  * @param replaceNewLine true if the newline needs to be replaced with platform- specific newline.
  */
 public static void copyFile(
     Configuration configuration,
     String file,
     String source,
     String destination,
     boolean overwrite,
     boolean replaceNewLine) {
   DirectoryManager.createDirectory(configuration, destination);
   File destfile = new File(destination, file);
   if (destfile.exists() && (!overwrite)) return;
   try {
     InputStream in =
         Configuration.class.getResourceAsStream(
             source + DirectoryManager.URL_FILE_SEPARATOR + file);
     if (in == null) return;
     OutputStream out = new FileOutputStream(destfile);
     try {
       if (!replaceNewLine) {
         byte[] buf = new byte[2048];
         int n;
         while ((n = in.read(buf)) > 0) out.write(buf, 0, n);
       } else {
         BufferedReader reader = new BufferedReader(new InputStreamReader(in));
         BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
         try {
           String line;
           while ((line = reader.readLine()) != null) {
             writer.write(line);
             writer.write(DocletConstants.NL);
           }
         } finally {
           reader.close();
           writer.close();
         }
       }
     } finally {
       in.close();
       out.close();
     }
   } catch (IOException ie) {
     ie.printStackTrace(System.err);
     throw new DocletAbortException();
   }
 }
Ejemplo n.º 2
0
  /**
   * Copy a file in the resources directory to the destination directory (if it is not there
   * already). If <code>overwrite</code> is true and the destination file already exists, overwrite
   * it.
   *
   * @param configuration Holds the destination directory and error message
   * @param resourcefile The name of the resource file to copy
   * @param overwrite A flag to indicate whether the file in the destination directory will be
   *     overwritten if it already exists.
   */
  public static void copyResourceFile(
      Configuration configuration, String resourcefile, boolean overwrite) {
    String destdir = configuration.destDirName;
    String destresourcesdir = destdir + "resources";
    DirectoryManager.createDirectory(configuration, destresourcesdir);
    File destfile = new File(destresourcesdir, resourcefile);
    if (destfile.exists() && (!overwrite)) return;
    try {

      InputStream in = Configuration.class.getResourceAsStream("resources/" + resourcefile);

      if (in == null) return;

      OutputStream out = new FileOutputStream(destfile);
      byte[] buf = new byte[2048];
      int n;
      while ((n = in.read(buf)) > 0) out.write(buf, 0, n);

      in.close();
      out.close();
    } catch (Throwable t) {
    }
  }