Download project zip and unzip it if not exists locally.

@param proj project to download
@return the temp dir where the new project is downloaded to, null if no project is downloaded.
@throws IOException if downloading or unzipping fails.
961844
@VisibleForTesting
  File downloadProjectIfNotExists(final ProjectDirectoryMetadata proj, final int execId)
      throws IOException {
    final String projectDir = generateProjectDirName(proj);
    if (proj.getInstalledDir() == null) {
      proj.setInstalledDir(new File(this.projectCacheDir, projectDir));
    }

    // If directory exists, assume it's prepared and skip.
    if (proj.getInstalledDir().exists()) {
      log.info("Project {} already cached. Skipping download. ExecId: {}", proj, execId);
      // Hit the local cache.
      this.projectCacheHitRatio.markHit();
      // Update last modified time of the file keeping project dir size when the project is
      // accessed. This last modified time will be used to determined least recently used
      // projects when performing project directory clean-up.
      updateLastModifiedTime(
          Paths.get(proj.getInstalledDir().getPath(), PROJECT_DIR_SIZE_FILE_NAME));
      return null;
    }

    this.projectCacheHitRatio.markMiss();

    final long start = System.currentTimeMillis();

    // Download project to a temp dir if not exists in local cache.
    final File tempDir = createTempDir(proj);
    downloadAndUnzipProject(proj, tempDir);

    log.info("Downloading zip file for project {} when preparing execution [execid {}] "
            + "completed in {} second(s)", proj, execId,
        (System.currentTimeMillis() - start) / 1000);

    return tempDir;
  }
194432
public static String getTempDir() {
        synchronized (FileUtil.class) {
            if (TEMP_DIR == null) {
                // Get the 'java.io.tmpdir' property
                String tmpDir = System.getProperty("java.io.tmpdir");

                if (StringUtil.isEmpty(tmpDir)) {
                    // Stupid fallback...
                    // TODO: Delegate to FileSystem?
                    if (new File("/temp").exists()) {
                        tmpDir = "/temp";  // Windows
                    }
                    else {
                        tmpDir = "/tmp";   // Unix
                    }
                }
                TEMP_DIR = tmpDir;
            }
        }
        return TEMP_DIR;
    }
987125
public ProjectFile read() throws MPXJException
   {
      try
      {
         m_project = new ProjectFile();
         m_eventManager = m_project.getEventManager();

         ProjectConfig config = m_project.getProjectConfig();
         config.setAutoTaskID(false);
         config.setAutoTaskUniqueID(false);
         config.setAutoResourceID(false);
         config.setAutoResourceUniqueID(false);
         config.setAutoOutlineLevel(false);
         config.setAutoOutlineNumber(false);
         config.setAutoWBS(false);
         config.setAutoCalendarUniqueID(false);
         config.setAutoAssignmentUniqueID(false);

         m_project.getProjectProperties().setFileApplication("Microsoft");
         m_project.getProjectProperties().setFileType("MPD");

         m_project.getEventManager().addProjectListeners(m_projectListeners);

         processProjectProperties();
         processCalendars();
         processResources();
         processResourceBaselines();
         processTasks();
         processTaskBaselines();
         processLinks();
         processAssignments();
         processAssignmentBaselines();
         processExtendedAttributes();
         processSubProjects();
         postProcessing();

         return (m_project);
      }

      catch (SQLException ex)
      {
         throw new MPXJException(MPXJException.READ_ERROR, ex);
      }

      finally
      {
         reset();

         if (m_allocatedConnection && m_connection != null)
         {
            try
            {
               m_connection.close();
            }

            catch (SQLException ex)
            {
               // silently ignore errors on close
            }

            m_connection = null;
         }
      }
   }
839213
private String getRealPath( String path )
            throws IOException
    {

        URL fileURL = _servletContext.getResource( path );

        File tempDir = (File) _servletContext.getAttribute( "javax.servlet.context.tempdir" );

        // download file into temp dir
        if ( fileURL != null )
        {
            File newFile = File.createTempFile( "temp", ".jar", tempDir );
            if ( download( fileURL, newFile ) )
            {
                String filePath = newFile.getPath();
                return filePath;
            }
        }
        return null;
    }
489177
private File getTempFolder(String tempPath) {
        if (tempPath != null) {
            File folder = new File(tempPath);
            if (folder.exists()) {
                return folder;
            }
        }
        return null;
    }
1185963
public static final File createTempDir() throws IOException
   {
      File dir = File.createTempFile("mpxj", "tmp");
      delete(dir);
      mkdirs(dir);
      return dir;
   }
832677
def download_result(tempfile, destination)
      return tempfile unless destination

      tempfile.close # required for Windows
      FileUtils.mv tempfile.path, destination

      nil
    end
1234597
public static void store(MavenProject project) throws IOException {
        final File output = new File(project.getBasedir(), Constants.DEPENDENCIES_FILE);
        output.getParentFile().mkdirs();
        ProjectDependencies dependencies = new ProjectDependencies(project);
        mapper.writer()
                .withDefaultPrettyPrinter()
                .writeValue(
                        output,
                        dependencies
                );
    }
1191401
public static final ProjectFile setProjectNameAndRead(File directory) throws MPXJException
   {
      List<String> projects = listProjectNames(directory);

      if (!projects.isEmpty())
      {
         P3DatabaseReader reader = new P3DatabaseReader();
         reader.setProjectName(projects.get(0));
         return reader.read(directory);
      }

      return null;
   }
56568
public static File createTempDirectory(String prefix, Path dir) throws IOException {
        if (prefix == null) {
            prefix = "";
        }
        final File file = generatePath(prefix, dir).toFile();
        if (!file.mkdirs()) {
            throw new IOException("Can't create dir " + file.getAbsolutePath());
        }
        return file;
    }
1207450
private void removeTempJavaFolder() throws IOException {
        if (removeJavaDir) {
            FileUtils.forceDelete(new File(rootDirectory + directoryName + this.javaDirPath));
        } else if (removeMainDir) {
            FileUtils.forceDelete(new File(rootDirectory + directoryName + this.mainDirPath));
        } else if (removeSrcDir) {
            FileUtils.forceDelete(new File(rootDirectory + directoryName + this.srcDirPath));
        } else if (removeJavaFile) {
            FileUtils.forceDelete(new File(rootDirectory + directoryName + javaDirPath + fileSeparator + TMP_JAVA_FILE));
        }
    }
783256
Map<String, LocalResource> getResources(
      final ResourceLaunchEvent resourceLaunchEvent)
      throws IOException {

    final Map<String, LocalResource> result = new HashMap<>();
    result.putAll(getGlobalResources());

    final File localStagingFolder = this.tempFileCreator.createTempDirectory(this.fileNames.getEvaluatorFolderPrefix());

    // Write the configuration
    final File configurationFile = new File(localStagingFolder, this.fileNames.getEvaluatorConfigurationName());
    this.configurationSerializer.toFile(makeEvaluatorConfiguration(resourceLaunchEvent), configurationFile);

    // Copy files to the staging folder
    JobJarMaker.copy(resourceLaunchEvent.getFileSet(), localStagingFolder);

    // Make a JAR file out of it
    final File localFile = tempFileCreator.createTempFile(
        this.fileNames.getEvaluatorFolderPrefix(), this.fileNames.getJarFileSuffix());
    new JARFileMaker(localFile).addChildren(localStagingFolder).close();

    // Upload the JAR to the job folder
    final Path pathToEvaluatorJar = this.uploader.uploadToJobFolder(localFile);
    result.put(this.fileNames.getLocalFolderPath(), this.uploader.makeLocalResourceForJarFile(pathToEvaluatorJar));

    if (this.deleteTempFiles) {
      LOG.log(Level.FINE, "Marking [{0}] for deletion at the exit of this JVM and deleting [{1}]",
          new Object[]{localFile.getAbsolutePath(), localStagingFolder.getAbsolutePath()});
      localFile.deleteOnExit();
      if (!localStagingFolder.delete()) {
        LOG.log(Level.WARNING, "Failed to delete [{0}]", localStagingFolder.getAbsolutePath());
      }
    } else {
      LOG.log(Level.FINE, "The evaluator staging folder will be kept at [{0}], the JAR at [{1}]",
          new Object[]{localFile.getAbsolutePath(), localStagingFolder.getAbsolutePath()});
    }
    return result;
  }
1183495
function createProject(zipFile) {
	return cocoonSDK.ProjectAPI.createFromZipUpload(zipFile)
	.catch((error) => {
		console.error("Project couldn't be created.");
		console.trace(error);
		throw error;
	});
}
778080
private String createTempFile(final boolean verbose) throws IOException {
        final File tempFile = File.createTempFile("tempMetadata", ".xml");

        if (!verbose) {
            tempFile.deleteOnExit();
        }

        return tempFile.getAbsolutePath();
    }
377729
static File getSourceFolder(MavenProject project)
  {
    final Properties projectProperties = project.getProperties();

    if (projectProperties.containsKey(XCodeDefaultConfigurationMojo.XCODE_SOURCE_DIRECTORY)) {
      return new File(project.getBasedir(),
            projectProperties.getProperty(XCodeDefaultConfigurationMojo.XCODE_SOURCE_DIRECTORY));
    }
    return new File(project.getBasedir(), XCodeDefaultConfigurationMojo.DEFAULT_XCODE_SOURCE_DIRECTORY);

  }
1176237
public static File getTempDir(){
        String p = System.getProperty(ND4JSystemProperties.ND4J_TEMP_DIR_PROPERTY);
        if(p == null || p.isEmpty()){
            return new File(System.getProperty("java.io.tmpdir"));
        } else {
            return new File(p);
        }
    }
126070
public byte[] getFileArchive(GitlabProject project) throws IOException {
        String tailUrl = GitlabProject.URL + "/" + project.getId() + "/repository/archive";
        return retrieve().to(tailUrl, byte[].class);
    }