/** * Returns a {@link File} representing the system temporary directory. * * @return the system temporary directory. * * @since 2.0 */ public static File getTempDirectory() { return new File(getTempDirectoryPath()); }
/** * Starts a local Zk instance with a generated empty data directory * @param port The port to listen on */ public static ZookeeperInstance startLocalZkServer(final int port) { return startLocalZkServer(port, org.apache.commons.io.FileUtils.getTempDirectoryPath() + File.separator + "test-" + System.currentTimeMillis()); }
public void initWorkingDir() { String workingDir = EnvironmentUtils.getProperty(Constants.JARSLINK_WORKING_DIR); File dirFile = StringUtils.isEmpty(workingDir) ? null : new File(workingDir); if (StringUtils.isEmpty(workingDir)) { workingDir = FileUtils.getTempDirectoryPath() + File.separator + Constants.JARSLINK_IDENTITY; dirFile = new File(workingDir); FileUtils.deleteQuietly(dirFile); dirFile.mkdir(); dirFile.deleteOnExit(); EnvironmentUtils.setProperty(Constants.JARSLINK_WORKING_DIR, workingDir); } AssertUtils.isTrue(dirFile.exists() && dirFile.isDirectory(), "Jarslink Working directory must exist."); }
@Test public void testGetTempDirectoryPath() { assertEquals(System.getProperty("java.io.tmpdir"), FileUtils.getTempDirectoryPath()); }
public static File archiveTARFiles(File base, Iterable<File> files, String archiveNameWithOutExtension) throws IOException { File tarFile = new File(FileUtils.getTempDirectoryPath(), archiveNameWithOutExtension + ".tar"); tarFile.deleteOnExit(); try (TarArchiveOutputStream tos = new TarArchiveOutputStream(new GZIPOutputStream(new BufferedOutputStream( new FileOutputStream(tarFile))))) { tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU); for (File file : files) { TarArchiveEntry tarEntry = new TarArchiveEntry(file); tarEntry.setName(relativize(base, file)); if (!file.isDirectory() && file.canExecute()) { tarEntry.setMode(tarEntry.getMode() | 0755); } tos.putArchiveEntry(tarEntry); if (!file.isDirectory()) { FileUtils.copyFile(file, tos); } tos.closeArchiveEntry(); } } return tarFile; } }
@SuppressWarnings("unchecked") protected void addTable(String tableName) { TableDataManagerConfig tableDataManagerConfig = mock(TableDataManagerConfig.class); when(tableDataManagerConfig.getTableDataManagerType()).thenReturn("OFFLINE"); when(tableDataManagerConfig.getTableName()).thenReturn(tableName); when(tableDataManagerConfig.getDataDir()).thenReturn(FileUtils.getTempDirectoryPath()); TableDataManager tableDataManager = TableDataManagerProvider .getTableDataManager(tableDataManagerConfig, "testInstance", mock(ZkHelixPropertyStore.class), mock(ServerMetrics.class)); tableDataManager.start(); _tableDataManagerMap.put(tableName, tableDataManager); } }
when(tableDataManagerConfig.getTableDataManagerType()).thenReturn("OFFLINE"); when(tableDataManagerConfig.getTableName()).thenReturn(TABLE_NAME); when(tableDataManagerConfig.getDataDir()).thenReturn(FileUtils.getTempDirectoryPath()); @SuppressWarnings("unchecked") TableDataManager tableDataManager = TableDataManagerProvider
String tmpdir = FileUtils.getTempDirectoryPath(); if (!tmpdir.endsWith(File.separator)) { tmpdir = tmpdir + File.separator;
/** * Starts a local Zk instance with a generated empty data directory * @param port The port to listen on */ public static void startLocalZkServer(final int port) { startLocalZkServer(port, org.apache.commons.io.FileUtils.getTempDirectoryPath() + File.separator + "test-" + System.currentTimeMillis()); }
/** * Returns a {@link File} representing the system temporary directory. * * @return the system temporary directory. * * @since 2.0 */ public static File getTempDirectory() { return new File(getTempDirectoryPath()); }
/** * Returns a {@link File} representing the system temporary directory. * * @return the system temporary directory. * * @since 2.0 */ public static File getTempDirectory() { return new File(getTempDirectoryPath()); }
/** * Returns a {@link File} representing the system temporary directory. * * @return the system temporary directory. * * @since 2.0 */ public static File getTempDirectory() { return new File(getTempDirectoryPath()); }
/** * Returns a {@link File} representing the system temporary directory. * * @return the system temporary directory. * * @since 2.0 */ public static File getTempDirectory() { return new File(getTempDirectoryPath()); }
/** * Starts a local Zk instance with a generated empty data directory * * @param port The port to listen on */ public static void startLocalZkServer(final int port) { startLocalZkServer(port, org.apache.commons.io.FileUtils.getTempDirectoryPath() + File.separator + "test-" + System.currentTimeMillis()); }
/** * Starts a local Zk instance with a generated empty data directory * * @param port The port to listen on */ public static void startLocalZkServer(final int port) { startLocalZkServer(port, org.apache.commons.io.FileUtils.getTempDirectoryPath() + File.separator + "test-" + System.currentTimeMillis()); }
/** * Starts a local Zk instance with a generated empty data directory * * @param port The port to listen on */ public static void startLocalZkServer(final int port) { startLocalZkServer(port, org.apache.commons.io.FileUtils.getTempDirectoryPath() + File.separator + "test-" + System.currentTimeMillis()); }
public static File outputDirectory() { final File tempDir = new File(FileUtils.getTempDirectoryPath(), RandomStringUtils.randomAlphanumeric(4)); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { FileUtils.deleteQuietly(tempDir); } }); return tempDir; }
@Before public void setUp() throws Exception { dir = Paths.get(FileUtils.getTempDirectoryPath(), "/test/foo"); Files.createDirectories(dir); f = Paths.get(dir.toString(), "test.txt"); Files.createFile(f); }
@Test public void testIsFileLocatedInDirectoryHomeAlthoughExistsNok() throws IOException { Path f2 = Paths.get(FileUtils.getTempDirectoryPath(), "test.txt"); try { Files.createFile(f2); } catch (FileAlreadyExistsException e) { //Only thrown on Windows } Assert.assertFalse(fileLoader.isFileLocatedInDirectory(dir, f2)); Files.delete(f2); }
@Test public void testIsFileLocatedInDirectorySymbolicLinkFromOutsideOk() throws IOException { //symlinks work only on unix Assume.assumeTrue (isUnix()); Path symlink = Paths.get(FileUtils.getTempDirectoryPath(), "symlink.txt"); //TODO check: is this statement true? I can't think of any harm this could do... //We create a symbolic link outside of the permitted folder pointing to a file inside of the permitted folder. This should be ok as well. Files.createSymbolicLink(symlink, f); Assert.assertTrue(fileLoader.isFileLocatedInDirectory(dir, symlink)); Files.delete(symlink); }