Copy required resources for the report.

@param workDir Report work directory.

@throws IOException exception5
499069
protected void copyReportResources(File workDir) throws IOException {
        FileUtils.copyResource(TEMPLATE_FOLDER + CSS_FILE, new File(workDir, CSS_FILE));
    }
1087701
public static void copyResource(Resource.Readable readable,
                                    Resource.Writable writable) throws IOException {
        readable.useReader(reader -> writable.useWriter(writer -> IOUtils.copy(reader, writer)));
    }
368553
public static void copyFile(File copyFrom, File copyTo) throws IOException {

		InputStream from = new FileInputStream(copyFrom);
		OutputStream to = new FileOutputStream(copyTo);

		copyStream(from, to);
	}
44265
public static void copyDirectories(String[] directories, String[] destinationDirectories) throws IOException {
        copyDirectories(getFiles(directories), getFiles(destinationDirectories));
    }
989420
public static void setupWorkDir(JobConf conf) throws IOException {
    File workDir = new File(".").getAbsoluteFile();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Fully deleting contents of " + workDir);
    }

    /** delete only the contents of workDir leaving the directory empty. We
     * can't delete the workDir as it is the current working directory.
     */
    deleteDirContents(conf, workDir);

    if (DistributedCache.getSymlink(conf)) {
      URI[] archives = DistributedCache.getCacheArchives(conf);
      URI[] files = DistributedCache.getCacheFiles(conf);
      URI[] sharedArchives = DistributedCache.getSharedCacheArchives(conf);
      URI[] sharedFiles = DistributedCache.getSharedCacheFiles(conf);

      Path[] localArchives = DistributedCache.getLocalCacheArchives(conf);
      Path[] localFiles = DistributedCache.getLocalCacheFiles(conf);
      Path[] localSharedArchives = DistributedCache.getLocalSharedCacheArchives(conf);
      Path[] localSharedFiles = DistributedCache.getLocalSharedCacheFiles(conf);

      if (archives != null) {
        for (int i = 0; i < archives.length; i++) {
          String link = archives[i].getFragment();
          if (link != null) {
            link = workDir.toString() + Path.SEPARATOR + link;
            File flink = new File(link);
            if (!flink.exists()) {
              FileUtil.symLink(localArchives[i].toString(), link);
            }
          }
        }
      }
      if (sharedArchives != null) {
        for (int i = 0; i < sharedArchives.length; i++) {
          String link = sharedArchives[i].getFragment();
          if (link != null) {
            // Remove md5 prefix: 2 chars per byte of MD5, plus 1 underscore
            link = link.substring(MD5Hash.MD5_LEN * 2 + 1);
            link = workDir.toString() + Path.SEPARATOR + link;
            File flink = new File(link);
            if (!flink.exists()) {
              FileUtil.symLink(localSharedArchives[i].toString(), link);
            }
          }
        }
      }
      if (files != null) {
        for (int i = 0; i < files.length; i++) {
          String link = files[i].getFragment();
          if (link != null) {
            link = workDir.toString() + Path.SEPARATOR + link;
            File flink = new File(link);
            if (!flink.exists()) {
              FileUtil.symLink(localFiles[i].toString(), link);
            }
          }
        }
      }
      if (sharedFiles != null) {
        for (int i = 0; i < sharedFiles.length; i++) {
          String link = sharedFiles[i].getFragment();
          if (link != null) {
            // Remove md5 prefix: 2 chars per byte of MD5, plus 1 underscore
            link = link.substring(MD5Hash.MD5_LEN * 2 + 1);
            link = workDir.toString() + Path.SEPARATOR + link;
            File flink = new File(link);
            if (!flink.exists()) {
              FileUtil.symLink(localSharedFiles[i].toString(), link);
            }
          }
        }
      }
    }
    File jobCacheDir = null;
    if (conf.getJar() != null) {
      jobCacheDir = new File(
          new Path(conf.getJar()).getParent().toString());
    }

    // create symlinks for all the files in job cache dir in current
    // workingdir for streaming
    try{
      DistributedCache.createAllSymlink(conf, jobCacheDir,
          workDir);
    } catch(IOException ie){
      // Do not exit even if symlinks have not been created.
      LOG.warn(StringUtils.stringifyException(ie));
    }
    // add java.io.tmpdir given by mapred.child.tmp
    String tmp = conf.get("mapred.child.tmp", "./tmp");
    Path tmpDir = new Path(tmp);

    // if temp directory path is not absolute
    // prepend it with workDir.
    if (!tmpDir.isAbsolute()) {
      tmpDir = new Path(workDir.toString(), tmp);
      FileSystem localFs = FileSystem.getLocal(conf);
      if (!localFs.mkdirs(tmpDir) && !localFs.getFileStatus(tmpDir).isDir()){
        throw new IOException("Mkdirs failed to create " + tmpDir.toString());
      }
    }
  }
962052
public void copyResourceToDir(String path, String filename, String dir) {
		String fullpath = path + ProcessorConstants.SEPARATORCHAR + filename;
		messager.printMessage(Diagnostic.Kind.MANDATORY_WARNING, " javascript copy js : " + fullpath + " to : "+dir);
		try (Writer writer = getFileObjectWriter(dir, "org.ocelotds."+filename)) {
			bodyWriter.write(writer, OcelotProcessor.class.getResourceAsStream(fullpath));
		} catch (IOException ex) {
			messager.printMessage(Diagnostic.Kind.MANDATORY_WARNING, " FAILED TO CREATE : " + filename);
		}
	}
189336
public void copy(Node dest) throws NodeNotFoundException, CopyException {
        try {
            if (isDirectory()) {
                dest.mkdirOpt();
                copyDirectory(dest);
            } else {
                copyFile(dest);
            }
        } catch (FileNotFoundException | CopyException e) {
            throw e;
        } catch (IOException e) {
            throw new CopyException(this, dest, e);
        }
    }
897496
public static void copyFiles(String[] files, String storageFolder) throws IOException {
        copyFiles(getFiles(files), storageFolder);
    }
653391
public static void recursivelyCopyDirectory(final File sourceDir, final File destDir,
      final StandardCopyOption copyOption)
      throws IOException {
    checkNotNull(sourceDir);
    checkNotNull(destDir);
    checkArgument(sourceDir.isDirectory(), "Source directory does not exist");
    java.nio.file.Files.createDirectories(destDir.toPath());
    walkFileTree(sourceDir.toPath(), new CopyFileVisitor(sourceDir.toPath(), destDir.toPath(),
        copyOption));
  }
684518
private void copyResources(File outputDirectory) throws IOException
    {
        copyClasspathResource(outputDirectory, "reportng.css", "reportng.css");
        copyClasspathResource(outputDirectory, "reportng.js", "reportng.js");
        // If there is a custom stylesheet, copy that.
        File customStylesheet = META.getStylesheetPath();

        if (customStylesheet != null)
        {
            if (customStylesheet.exists())
            {
                copyFile(outputDirectory, customStylesheet, CUSTOM_STYLE_FILE);
            }
            else
            {
                // If not found, try to read the file as a resource on the classpath
                // useful when reportng is called by a jarred up library
                InputStream stream = ClassLoader.getSystemClassLoader().getResourceAsStream(customStylesheet.getPath());
                if (stream != null)
                {
                    copyStream(outputDirectory, stream, CUSTOM_STYLE_FILE);
                }
            }
        }
    }
572831
static void copyFileFromResources(String sourcePath, String destPath) throws IOException {
        LOGGER.entering(new Object[] { sourcePath, destPath });

        File downloadFile = new File(destPath);

        if (!downloadFile.exists()) {
            InputStream stream = JarSpawner.class.getResourceAsStream(sourcePath);
            FileUtils.copyInputStreamToFile(stream, downloadFile);
            LOGGER.fine("File copied to " + destPath);
        }
        LOGGER.exiting();
    }
264504
private static void formatWorkerDataFolder(String folder) throws IOException {
    Path path = Paths.get(folder);
    FileUtils.deletePathRecursively(folder);
    Files.createDirectory(path);
    // For short-circuit read/write to work, others needs to be able to access this directory.
    // Therefore, default is 777 but if the user specifies the permissions, respect those instead.
    String permissions = ServerConfiguration.get(PropertyKey.WORKER_DATA_FOLDER_PERMISSIONS);
    Set<PosixFilePermission> perms = PosixFilePermissions.fromString(permissions);
    Files.setPosixFilePermissions(path, perms);
    FileUtils.setLocalDirStickyBit(path.toAbsolutePath().toString());
  }
916893
static void createFileFromResource(String resource, Resource file) throws IOException {
	createFileFromResource(resource, file, null);
    }
846026
private File getWorkDir() throws IOException
    {
        if (_workDir == null)
        {    
            File   dummy   = File.createTempFile("dummy", ".log");
            String workDir = dummy.getPath().substring(0, dummy.getPath().lastIndexOf(File.separatorChar));
    
            if ((workDir == null) || (workDir.length() == 0))
            {
                workDir = ".";
            }
            dummy.delete();
            _workDir = new File(workDir);
        }
        return _workDir;
    }
828888
private void createLibFolder() throws IOException {
        if(!Files.exists(libLocation.toPath()))
            Files.createDirectories(libLocation.toPath());
    }
1329472
private void copyAndConfigureFiles(JobConf job, Path uploadFileDir,
      boolean shared)
    throws IOException {

    if (!(job.getBoolean("mapred.used.genericoptionsparser", false))) {
      LOG.warn("Use GenericOptionsParser for parsing the arguments. " +
               "Applications should implement Tool for the same.");
    }

    // get all the command line arguments into the
    // jobconf passed in by the user conf
    String files = job.get("tmpfiles");
    String libjars = job.get("tmpjars");
    String archives = job.get("tmparchives");

    //
    // Figure out what fs the JobTracker is using.  Copy the
    // job to it, under a temporary name.  This allows DFS to work,
    // and under the local fs also provides UNIX-like object loading
    // semantics.  (that is, if the job file is deleted right after
    // submission, we can still run the submission to completion)
    //

    // Create a number of filenames in the JobTracker's fs namespace
    FileSystem fs = getFs();
    LOG.debug("default FileSystem: " + fs.getUri());

    // We know file system of distributed cache, initialize index
    if (filesInCache == null) {
      filesInCache = new DistributedCacheIndex(fs);
    }

    uploadFileDir = fs.makeQualified(uploadFileDir);
    uploadFileDir = new Path(uploadFileDir.toUri().getPath());
    FsPermission mapredSysPerms = new FsPermission(JOB_DIR_PERMISSION);

    if (!fs.exists(uploadFileDir)) {
      FileSystem.mkdirs(fs, uploadFileDir, mapredSysPerms);
    }
    Path filesDir = new Path(uploadFileDir, "files");
    Path archivesDir = new Path(uploadFileDir, "archives");
    Path libjarsDir = new Path(uploadFileDir, "libjars");
    short replication = (short)job.getInt("mapred.submit.replication", 10);

    fileInfo = new HashMap<URI, FileInfo>();

    String originalJar = job.getJar();

    if (originalJar != null) {
      // use jar name if job is not named.
      if ("".equals(job.getJobName())) {
        job.setJobName(new Path(originalJar).getName());
      }

      Path uploadJarPath;

      Path originalJarPath = new Path(originalJar);
      originalJarPath =
        originalJarPath.makeQualified(FileSystem.getLocal(job));

      try {
        // If sharing is turned on, we load the job jar into the distributed
        // cache

        if (shared) {
          if (!fs.exists(libjarsDir)) {
            FileSystem.mkdirs(fs, libjarsDir, mapredSysPerms);
          }

          MD5Hash md5hash = MD5Hash.digest(new
              FileInputStream(originalJarPath.toUri().getPath()));
          uploadJarPath = copyRemoteFiles(fs, libjarsDir, originalJarPath, job,
              replication, md5hash.toString());
          URI pathURI = new URI(uploadJarPath.toUri().toString());

          DistributedCache.addSharedArchiveToClassPath(uploadJarPath, job);
          fileInfo.put(pathURI, new FileInfo(md5hash.toString(),
                md5hash.getFileLength(), 0));
        } else {
          // Otherwise we copy jar to JT's filesystem
          uploadJarPath = new Path(uploadFileDir, "job.jar");
          fs.copyFromLocalFile(originalJarPath, uploadJarPath);
        }
      } catch (URISyntaxException ue) {
        // should not throw an uri exception
        throw new IOException("Failed to create uri for " + originalJar);
      }

      job.setJar(uploadJarPath.toString());
      fs.setReplication(uploadJarPath, replication);

      try {
        fs.setPermission(uploadJarPath, new FsPermission(JOB_FILE_PERMISSION));
      } catch (IOException ioe) {
        LOG.warn("Unable to set job jar permission");
      }
    } else {
      LOG.warn("No job jar file set. User classes may not be found. "+
          "See JobConf(Class) or JobConf#setJar(String).");
    }

    // add all the command line files/ jars and archive
    // first copy them to jobtrackers filesystem

    if (files != null) {
      if (!fs.exists(filesDir)) {
        FileSystem.mkdirs(fs, filesDir, mapredSysPerms);
      }

      String[] fileArr = files.split(",");
      for (String tmpFile: fileArr) {
        Path tmp = new Path(tmpFile);

        Path newPath;
        FileStatus fStatus = null;
        MD5Hash md5hash = null;
        try {
          if (shared) {
            md5hash
              = MD5Hash.digest(new FileInputStream(tmp.toUri().getPath()));
            newPath = copyRemoteFiles(fs, filesDir, tmp, job, replication,
                md5hash.toString());

            URI pathURI = new URI(newPath.toUri().toString() + "#" +
                newPath.getName());

            DistributedCache.addSharedCacheFile(pathURI, job);
            fileInfo.put(pathURI, new FileInfo(md5hash.toString(),
                  md5hash.getFileLength(),
                  0));

          } else {
            newPath = copyRemoteFiles(fs, filesDir, tmp, job, replication);
            fStatus = DistributedCache.getFileStatus(job, newPath.toUri());

            URI pathURI = new URI(newPath.toUri().toString() + "#" +
                newPath.getName());

            DistributedCache.addCacheFile(pathURI, job);
            fileInfo.put(pathURI, new FileInfo(null,
                  fStatus.getLen(),
                  fStatus.getModificationTime()));
          }

        } catch(URISyntaxException ue) {
          //should not throw a uri exception
          throw new IOException("Failed to create uri for " + tmpFile);
        }
        DistributedCache.createSymlink(job);
      }
    }

    if (libjars != null) {
      if (!fs.exists(libjarsDir)) {
        FileSystem.mkdirs(fs, libjarsDir, mapredSysPerms);
      }

      String[] libjarsArr = libjars.split(",");
      for (String tmpjars: libjarsArr) {
        Path tmp = new Path(tmpjars);

        Path newPath;
        if (shared) {
          MD5Hash md5hash
            = MD5Hash.digest(new FileInputStream(tmp.toUri().getPath()));
          newPath = copyRemoteFiles(fs, libjarsDir, tmp, job, replication,
              md5hash.toString());
          DistributedCache.addSharedArchiveToClassPath(newPath, job);

          fileInfo.put(newPath.makeQualified(newPath.getFileSystem(job)).toUri(),
                       new FileInfo(md5hash.toString(),
                                    md5hash.getFileLength(),
                                    0));
        } else {
          newPath = copyRemoteFiles(fs, libjarsDir, tmp, job, replication);
          DistributedCache.addArchiveToClassPath(newPath, job);

          FileStatus fStatus = DistributedCache.getFileStatus(job,
              newPath.toUri());
          fileInfo.put(newPath.makeQualified(newPath.getFileSystem(job)).toUri(),
                       new FileInfo(null,
                                    fStatus.getLen(),
                                    fStatus.getModificationTime()));
        }
      }
    }

    if (archives != null) {
      if (!fs.exists(archivesDir)) {
        FileSystem.mkdirs(fs, archivesDir, mapredSysPerms);
      }

     String[] archivesArr = archives.split(",");
     for (String tmpArchives: archivesArr) {
       Path tmp = new Path(tmpArchives);

       Path newPath;
       MD5Hash md5hash = null;
       FileStatus fStatus = null;
       try {
         if (shared) {
           md5hash
             = MD5Hash.digest(new FileInputStream(tmp.toUri().getPath()));
           newPath = copyRemoteFiles(fs, archivesDir, tmp, job, replication,
               md5hash.toString());
           URI pathURI = new URI(newPath.toUri().toString() + "#" +
               newPath.getName());

           DistributedCache.addSharedCacheArchive(pathURI, job);
           fileInfo.put(pathURI, new FileInfo(md5hash.toString(),
                 md5hash.getFileLength(),
                 0));

         } else {
           newPath = copyRemoteFiles(fs, archivesDir, tmp, job, replication);
           fStatus = DistributedCache.getFileStatus(job, newPath.toUri());

           URI pathURI = new URI(newPath.toUri().toString() + "#" +
               newPath.getName());

           DistributedCache.addCacheArchive(pathURI, job);
           fileInfo.put(pathURI, new FileInfo(null,
                 fStatus.getLen(),
                 fStatus.getModificationTime()));
         }
       } catch(URISyntaxException ue) {
         //should not throw an uri excpetion
         throw new IOException("Failed to create uri for " + tmpArchives);
       }
       DistributedCache.createSymlink(job);
     }
    }

    // set the timestamps and md5 of the archives and files
    URI[] tarchives = DistributedCache.getSharedCacheArchives(job);
    if (tarchives != null) {
      StringBuffer archiveLength = new StringBuffer();
      FileStatus fStatus;
      FileInfo info;
      long fileLength;

      for (int i = 0; i < tarchives.length; i++) {
        if (i != 0) archiveLength.append(',');

        info = fileInfo.get(tarchives[i]);
        if (info == null) {
          fStatus = DistributedCache.getFileStatus(job, tarchives[i]);
          fileLength = fStatus.getLen();
        } else {
          fileLength = info.fileLength;
        }

        archiveLength.append(fileLength);
      }

      DistributedCache.setSharedArchiveLength(job, archiveLength.toString());
    }

    URI[] tfiles = DistributedCache.getSharedCacheFiles(job);
    if (tfiles != null) {
      StringBuffer fileLength = new StringBuffer();
      FileStatus fStatus;
      FileInfo info;
      long len;

      for (int i = 0; i < tfiles.length; i++) {
        if (i != 0) fileLength.append(',');

        info = fileInfo.get(tfiles[i]);
        if (info == null) {
          fStatus = DistributedCache.getFileStatus(job, tfiles[i]);
          len = fStatus.getLen();
        } else {
          len = info.fileLength;
        }

        fileLength.append(len);
      }

      DistributedCache.setSharedFileLength(job, fileLength.toString());
    }

    tarchives = DistributedCache.getCacheArchives(job);
    if (tarchives != null) {
      StringBuffer archiveTimestamps = new StringBuffer();
      FileInfo info;
      long timeStamp;

      for (int i = 0; i < tarchives.length; i++) {
        if (i != 0) archiveTimestamps.append(',');

        info = fileInfo.get(tarchives[i]);
        if (info == null) {
          timeStamp = DistributedCache.getTimestamp(job, tarchives[i]);
        } else {
          timeStamp = info.timeStamp;
        }
        archiveTimestamps.append(timeStamp);
      }

      DistributedCache.setArchiveTimestamps(job, archiveTimestamps.toString());
    }

    tfiles = DistributedCache.getCacheFiles(job);
    if (tfiles != null) {
      StringBuffer fileTimestamps = new StringBuffer();
      FileInfo info;
      long timeStamp;

      for (int i = 0; i < tfiles.length; i++) {
        if (i != 0) fileTimestamps.append(',');

        info = fileInfo.get(tfiles[i]);
        if (info == null) {
          timeStamp = DistributedCache.getTimestamp(job, tfiles[i]);
        } else {
          timeStamp = info.timeStamp;
        }
        fileTimestamps.append(timeStamp);
      }

      DistributedCache.setFileTimestamps(job, fileTimestamps.toString());
    }

    configureUserName(job);

  }
1281079
public static void copyDirToDir(File source, File dest, FilenameFilter filter) throws IOException {
        if (!source.isDirectory() || !dest.isDirectory()) {
            return;
        }

        List<File> files = listFiles(source, filter, true);
        String sourcePath = source.getAbsolutePath();
        String destPath = dest.getAbsolutePath();
        for (File file : files) {
            String filePath = file.getAbsolutePath();
            if (sourcePath.equals(filePath)) {
                continue;
            }
            String newPath = destPath + File.separator + filePath.substring(sourcePath.length());
            File destFile = new File(newPath);
            if (file.isDirectory()) {
                destFile.mkdirs();
            } else {
                copy(file, destFile);
            }
        }
    }