private static File getTmpFile() { File tmpDir = FileUtils.getTempDirectory(); String tmpFileName = (Math.random() * 10000 + "").replace(".", ""); return new File(tmpDir, tmpFileName); }
public TempFiles() { myCurrentTempDir = ourCurrentTempDir; if (!myCurrentTempDir.isDirectory()) { throw new IllegalStateException("Temp directory is not a directory, was deleted by some process: " + myCurrentTempDir.getAbsolutePath() + "\njava.io.tmpdir: " + FileUtils.getTempDirectory()); } myShutdownHook = new Thread(new Runnable() { public void run() { myInsideShutdownHook = true; cleanup(); } }); Runtime.getRuntime().addShutdownHook(myShutdownHook); }
@Override /** * We don't expect any callers to call this code, but just in case, implementation is provided for * backward compatibility * * @deprecated since 1.4 use processCommand(String commandString, Map<String, String> env, * List<String> stagedFilePaths) */ public String processCommand(String commandString, Map<String, String> env, Byte[][] binaryData) { // save the binaryData into stagedFile first, and then call the new api File tempDir = FileUtils.getTempDirectory(); List<String> filePaths = null; try { filePaths = CliUtil.bytesToFiles(binaryData, tempDir.getAbsolutePath()); return bridge.processCommand(commandString, env, filePaths); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { // delete the staged files FileUtils.deleteQuietly(tempDir); } }
@Test public void testGetTempDirectory() { final File tempDirectory = new File(System.getProperty("java.io.tmpdir")); assertEquals(tempDirectory, FileUtils.getTempDirectory()); }
File tempDir = File.createTempFile(SEGMENT_UPLOADER, null, FileUtils.getTempDirectory()); FileUtils.deleteQuietly(tempDir); FileUtils.forceMkdir(tempDir);
workingDir = FileUtils.getTempDirectory(); } else { workingDir = new File(_workingDirectory);
_tempDir = builderConfig.getOutDir(); if (_tempDir == null) { _tempDir = new File(FileUtils.getTempDirectory(), V1Constants.STAR_TREE_INDEX_DIR + "_" + DateTime.now());
@Test public void shouldRefreshUsableSpaceOfAgent() throws Exception { AgentIdentifier identifier = new AgentIdentifier("local.in", "127.0.0.1", "uuid-1"); String workingDirectory = FileUtils.getTempDirectory().getAbsolutePath(); AgentRuntimeInfo runtimeInfo = ElasticAgentRuntimeInfo.fromAgent(identifier, AgentRuntimeStatus.Idle, workingDirectory, false); long space = ElasticAgentRuntimeInfo.usableSpace(workingDirectory); assertThat(runtimeInfo.getUsableSpace(), is(space)); } }
@SuppressWarnings("ResultOfMethodCallIgnored") private StringBuilder addPythonPathJvmArgument(StringBuilder jvmArguments) { jvmArguments.append(" -Dpython.path="); jvmArguments.append(new File(baseDirectory.getFile(), "lib").getAbsolutePath()); String pythonPath = System.getenv().get("PYTHONPATH"); if (pythonPath != null) { jvmArguments.append(File.pathSeparator).append(pythonPath); } String pythonHome = System.getenv().get("PYTHONHOME"); if (pythonHome != null) { jvmArguments.append(" -Dpython.home="); jvmArguments.append(pythonHome); } jvmArguments.append(" "); File jythonCache = new File(FileUtils.getTempDirectory(), "jython"); jythonCache.mkdirs(); jvmArguments.append(" -Dpython.cachedir=").append(jythonCache.getAbsolutePath()).append(" "); return jvmArguments; }
File tempFile = new File(FileUtils.getTempDirectory(), fileName); FileUtils.copyInputStreamToFile(inputStream, tempFile);
public static void main(String[] args) throws IOException, InterruptedException { Configuration conf = HBaseConfiguration.create(); Connection connection = ConnectionFactory.createConnection(conf); // vv TokenExample Token<AuthenticationTokenIdentifier> token = TokenUtil.obtainToken(connection); String urlString = token.encodeToUrlString(); File temp = new File(FileUtils.getTempDirectory(), "token"); FileUtils.writeStringToFile(temp, urlString); System.out.println("Encoded Token: " + urlString); String strToken = FileUtils.readFileToString(new File("token")); Token token2 = new Token(); token2.decodeFromUrlString(strToken); UserGroupInformation.getCurrentUser().addToken(token2); // ^^ TokenExample connection.close(); } }
public String post(String url, InputStream inputStream, String fileName, Map<String, String> form) { File tempFile = new File(FileUtils.getTempDirectory(), fileName); try { FileUtils.copyInputStreamToFile(inputStream, tempFile); } catch (IOException e) { logger.error("http post: {} failed", url, e); throw new WxRuntimeException(999, "Copy stream to file failed:" + e.getMessage()); } try { return httpPost(appendAccessToken(url), tempFile, form); } catch (Exception e) { if(e instanceof WxRuntimeException) { WxRuntimeException wxRuntimeException = (WxRuntimeException) e; if(invalidToken(wxRuntimeException.getCode())) { logger.warn("token invalid: {}, will refresh.", wxRuntimeException.getCode()); refreshToken(); return httpPost(appendAccessToken(url), tempFile, form); } } throw e; } finally { FileUtils.deleteQuietly(tempFile); } }
private static File getTmpFile() { File tmpDir = FileUtils.getTempDirectory(); String tmpFileName = (Math.random() * 10000 + "").replace(".", ""); return new File(tmpDir, tmpFileName); }
private static File getTmpFile() { File tmpDir = FileUtils.getTempDirectory(); String tmpFileName = (Math.random() * 10000 + "").replace(".", ""); return new File(tmpDir, tmpFileName); }
private static File getTmpFile() { File tmpDir = FileUtils.getTempDirectory(); String tmpFileName = (Math.random() * 10000 + "").replace(".", ""); return new File(tmpDir, tmpFileName); }
private static File getTmpFile() { File tmpDir = FileUtils.getTempDirectory(); String tmpFileName = (Math.random() * 10000 + "").replace(".", ""); return new File(tmpDir, tmpFileName); }
private File createTempDir() { File tmpRoot = FileUtils.getTempDirectory(); File tmpDir = new File(tmpRoot, UUID.randomUUID().toString()); tmpDir.mkdir(); return tmpDir; }
public static File createTmpFolder() throws IOException { File root = org.apache.commons.io.FileUtils.getTempDirectory(); File tmpFolder; do { tmpFolder = new File(root, UUID.randomUUID().toString()); } while (tmpFolder.isDirectory()); tmpFolder.mkdir(); return tmpFolder; }
private File createRootFolder(final String rootDirectory) { final File root; if (rootDirectory == null || rootDirectory.isEmpty()) { root = new File(FileUtils.getTempDirectory(), "s3mockFileStore" + new Date().getTime()); } else { root = new File(rootDirectory); } root.deleteOnExit(); root.mkdir(); return root; }
@Before public void setUp() { TEST_PATH = new File(FileUtils.getTempDirectory().getAbsolutePath(), "DatastoreManagerTest" + UUID.randomUUID()); }