Creates a new {@link FileIOChannel.ID} in one of the temp directories. Multiple
invocations of this method spread the channels evenly across the different directories.

@return A channel to a temporary directory.
16615
public FileIOChannel.ID createChannel() {
		final int num = getNextPathNum();
		return new FileIOChannel.ID(this.paths[num], num, this.random);
	}
221902
public static File getTempDir() {
        final String str = System.getProperty(TEMP_DIR_KEY);
        if (str == null) {
            throw new IllegalStateException("System property '" + TEMP_DIR_KEY + "' not found!");
        }
        final String tempDirStr = str.trim();
        if (tempDirStr.length() == 0) {
            throw new IllegalStateException("System property '" + TEMP_DIR_KEY + "' is empty!");
        }
        final File dir = new File(tempDirStr);
        try {
            checkValidDir(dir);
        } catch (final IllegalArgumentException ex) {
            throw new IllegalStateException("System property '" + TEMP_DIR_KEY + "' is not valid! [" + ex.getMessage() + "]");
        }
        return dir;
    }
758489
public static File createTempDir() throws IllegalStateException
   {
      File baseDir = getTempDirectory();
      try
      {
         return Files.createTempDirectory(baseDir.toPath(), "tmpdir").toFile();
      }
      catch (IOException e)
      {
         throw new IllegalStateException("Error while creating temporary directory", e);
      }
   }
1009101
public static File createTempDirectory(String prefix) {
	File temp = null;
	
	try {
	  temp = File.createTempFile(prefix != null ? prefix : "temp", Long.toString(System.nanoTime()));
	
	  if (!(temp.delete())) {
	    throw new IOException("Could not delete temp file: "
		  + temp.getAbsolutePath());
	  }
	
	  if (!(temp.mkdir())) {
	    throw new IOException("Could not create temp directory: "
	      + temp.getAbsolutePath());
	  }
	} catch (IOException e) {
	  throw new DukeException("Unable to create temporary directory with prefix " + prefix, e);
	}
	
	return temp;
  }
1335385
public File getDir() {
		if (this.dir == null) {
			synchronized (this) {
				byte[] hash = generateHash(this.sourceClass);
				this.dir = new File(getTempDirectory(), toHexString(hash));
				this.dir.mkdirs();
				Assert.state(this.dir.exists(),
						() -> "Unable to create temp directory " + this.dir);
			}
		}
		return this.dir;
	}
28331
public static File createTempFile(String prefix, String suffix, File dir, boolean isReCreat) throws IORuntimeException {
		int exceptionsCount = 0;
		while (true) {
			try {
				File file = File.createTempFile(prefix, suffix, dir).getCanonicalFile();
				if (isReCreat) {
					file.delete();
					file.createNewFile();
				}
				return file;
			} catch (IOException ioex) { // fixes java.io.WinNTFileSystem.createFileExclusively access denied
				if (++exceptionsCount >= 50) {
					throw new IORuntimeException(ioex);
				}
			}
		}
	}
649647
public synchronized File getTempDirectory() throws IOException {
        if (tempDirectory == null) {
            final File baseTemp = new File(getString(Settings.KEYS.TEMP_DIRECTORY, System.getProperty("java.io.tmpdir")));
            tempDirectory = FileUtils.createTempDirectory(baseTemp);
        }
        return tempDirectory;
    }
953746
private FileChannel getChannel(final boolean append) throws IOException {

		if (this.privateFileChannel == null) {

			java.io.File fileOnDisk = file.getFileOnDisk();

			fileOnDisk.getParentFile().mkdirs();

			this.privateFileChannel = new FileOutputStream(fileOnDisk, append).getChannel();
		}

		return this.privateFileChannel;
	}
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;
    }
655060
private FileWriter createTempFile(File tempfile) throws IOException,
            JournalException {
        boolean created = tempfile.createNewFile();
        if (!created) {
            throw new JournalException("Unable to create file '"
                    + tempfile.getPath() + "'.");
        }
        return new FileWriter(tempfile);
    }
1056470
WritableByteChannel createInternal(URI path, CreateFileOptions options)
      throws IOException {

    // Validate the given path. false == do not allow empty object name.
    StorageResourceId resourceId = pathCodec.validatePathAndGetId(path, false);
    if (options.getExistingGenerationId() != StorageResourceId.UNKNOWN_GENERATION_ID) {
      resourceId = new StorageResourceId(
          resourceId.getBucketName(),
          resourceId.getObjectName(),
          options.getExistingGenerationId());
    }
    WritableByteChannel channel = gcs.create(resourceId, objectOptionsFromFileOptions(options));
    tryUpdateTimestampsForParentDirectories(ImmutableList.of(path), ImmutableList.<URI>of());
    return channel;
  }
172103
public File createDirectorySync(String prefix) throws IOException {
		Path path = Files.createTempDirectory(tempDir.toPath(), this.prefix + prefix);
		File dir = path.toFile();
		/*
		app.toClose(new Closeable() {
			@Override
			public void close() {
				new RemoveDirectoryTask(dir, null, 0, null, Task.PRIORITY_NORMAL, false).start();
			}
		});*/
		return dir;
	}
335494
public static File getTempDirectory() {
	if (tempFile != null) return tempFile;

	final String tmpStr = System.getProperty("java.io.tmpdir");
	if (tmpStr != null) {
	    tempFile = new File(tmpStr);
	    if (tempFile.exists()) {
		tempFile = getCanonicalFileEL(tempFile);
		return tempFile;
	    }
	}
	try {
	    final File tmp = File.createTempFile("a", "a");
	    tempFile = tmp.getParentFile();
	    tempFile = getCanonicalFileEL(tempFile);
	    tmp.delete();
	}
	catch (final IOException ioe) {}

	return tempFile;
    }
77874
public static File createTmpFile(InputStream inputStream, String name, String ext, File tmpDirFile) throws IOException {
    FileOutputStream fos = null;
    try {
      File tmpFile;
      if (tmpDirFile == null) {
    	  tmpFile = File.createTempFile(name, '.' + ext);
      } else {
        tmpFile = File.createTempFile(name, '.' + ext, tmpDirFile);
      }
      tmpFile.deleteOnExit();
      fos = new FileOutputStream(tmpFile);
      int read = 0;
      byte[] bytes = new byte[1024 * 100];
      while ((read = inputStream.read(bytes)) != -1) {
        fos.write(bytes, 0, read);
      }
      fos.flush();
      return tmpFile;
    } finally {
      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (IOException e) {
        }
      }
      if (fos != null) {
        try {
          fos.close();
        } catch (IOException e) {
        }
      }
    }
  }
1231019
private static File createTempFile(File storageDir) throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        if(!storageDir.mkdir() && !storageDir.exists()){
            throw new IOException("Unable to create temporary media directory");
        }

        return File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
        );
    }
742004
public static File copyToTempFile(InputStream serialization)
            throws IOException, FileNotFoundException {
        File tempFile = createTempFile();
        StreamUtility.pipeStream(serialization,
                                 new FileOutputStream(tempFile),
                                 4096);
        return tempFile;
    }
257003
public PathImpl createTempFile(String prefix, String suffix) throws IOException
  {
    if (prefix == null || prefix.length () == 0)
      prefix = "t";

    if (suffix == null)
      suffix = ".tmp";

    synchronized (LOCK) {
      for (int i = 0; i < 32768; i++) {
        int r = Math.abs((int) RandomUtil.getRandomLong());
        PathImpl file = lookup(prefix + r + suffix);

        if (file.createNewFile())
          return file;
      }
    }

    throw new IOException("cannot create temp file");
  }