List of usage examples for java.nio.file Files createTempDirectory
public static Path createTempDirectory(String prefix, FileAttribute<?>... attrs) throws IOException
From source file:com.spectralogic.ds3client.helpers.FileObjectPutter_Test.java
@Test public void testThatNamedPipeThrows() throws IOException, InterruptedException { Assume.assumeFalse(Platform.isWindows()); final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String FIFO_NAME = "bFifo"; final AtomicBoolean caughtException = new AtomicBoolean(false); try {//from w w w . j a v a2 s. c o m Runtime.getRuntime().exec("mkfifo " + Paths.get(tempDirectory.toString(), FIFO_NAME)).waitFor(); new FileObjectPutter(tempDirectory).buildChannel(FIFO_NAME); } catch (final UnrecoverableIOException e) { assertTrue(e.getMessage().contains(FIFO_NAME)); caughtException.set(true); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } assertTrue(caughtException.get()); }
From source file:hudson.model.UserIdMigratorTest.java
static File createTestDirectory(Class clazz, TestName testName) throws IOException { File tempDirectory = Files.createTempDirectory(Paths.get("target"), "userIdMigratorTest").toFile(); tempDirectory.deleteOnExit();/* w w w .j ava 2 s . co m*/ copyTestDataIfExists(clazz, testName, tempDirectory); return new File(tempDirectory, "users"); }
From source file:org.corehunter.tests.data.simple.SimpleBiAllelicGenotypeDataTest.java
@Test public void toTxtFile() throws IOException { dataName = "out.txt"; expectedHeaders = HEADERS_UNIQUE_NAMES; expectedMarkerNames = MARKER_NAMES;/* w w w . j av a2s . com*/ SimpleBiAllelicGenotypeData genotypicData = new SimpleBiAllelicGenotypeData(expectedHeaders, expectedMarkerNames, ALLELE_SCORES_BIALLELIC); Path path = Paths.get(TEST_OUTPUT); Files.createDirectories(path); path = Files.createTempDirectory(path, "GenoBiallelic-Txt"); path = Paths.get(path.toString(), dataName); System.out.println(" |- Write File " + dataName); genotypicData.writeData(path, FileType.TXT); System.out.println(" |- Read written File " + dataName); testData(SimpleBiAllelicGenotypeData.readData(path, FileType.TXT)); }
From source file:ee.ria.xroad.common.messagelog.archive.LogArchiveCache.java
private void resetArchive() throws IOException { deleteArchiveArtifacts();// w w w . j a v a 2s .c o m archiveContentDir = Files.createTempDirectory(workingDir, "xroad-log-archive").toFile(); }
From source file:com.spectralogic.ds3client.metadata.MetadataReceivedListenerImpl_Test.java
@Test public void testGettingMetadataFailureHandler() throws IOException, InterruptedException { Assume.assumeFalse(Platform.isWindows()); try {/*from ww w . j a v a 2 s .c o m*/ final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String fileName = "Gracie.txt"; final Path filePath = Files.createFile(Paths.get(tempDirectory.toString(), fileName)); try { // set permissions if (!Platform.isWindows()) { final PosixFileAttributes attributes = Files.readAttributes(filePath, PosixFileAttributes.class); final Set<PosixFilePermission> permissions = attributes.permissions(); permissions.clear(); permissions.add(PosixFilePermission.OWNER_READ); permissions.add(PosixFilePermission.OWNER_WRITE); Files.setPosixFilePermissions(filePath, permissions); } // get permissions final ImmutableMap.Builder<String, Path> fileMapper = ImmutableMap.builder(); fileMapper.put(filePath.toString(), filePath); final Map<String, String> metadataFromFile = new MetadataAccessImpl(fileMapper.build()) .getMetadataValue(filePath.toString()); FileUtils.deleteDirectory(tempDirectory.toFile()); // put old permissions back final Metadata metadata = new MetadataImpl(new MockedHeadersReturningKeys(metadataFromFile)); final AtomicInteger numTimesFailureHandlerCalled = new AtomicInteger(0); new MetadataReceivedListenerImpl(tempDirectory.toString(), new FailureEventListener() { @Override public void onFailure(final FailureEvent failureEvent) { numTimesFailureHandlerCalled.incrementAndGet(); assertEquals(FailureEvent.FailureActivity.RestoringMetadata, failureEvent.doingWhat()); } }, "localhost").metadataReceived(fileName, metadata); assertEquals(1, numTimesFailureHandlerCalled.get()); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } } catch (final Throwable t) { fail("Throwing exceptions from metadata est verbotten"); } }
From source file:org.corehunter.tests.data.simple.SimpleFrequencyGenotypeDataTest.java
@Test public void toTxtFile() throws IOException { dataName = "out.txt"; expectedHeaders = HEADERS_UNIQUE_NAMES; expectedMarkerNames = MARKER_NAMES;// w w w. j a v a 2 s . c om expectedAlleleNames = UNDEFINED_ALLELE_NAMES; SimpleFrequencyGenotypeData genotypicData = new SimpleFrequencyGenotypeData(expectedHeaders, expectedMarkerNames, expectedAlleleNames, ALLELE_FREQUENCIES); Path path = Paths.get(TEST_OUTPUT); Files.createDirectories(path); path = Files.createTempDirectory(path, "GenoFreqs-Txt"); path = Paths.get(path.toString(), dataName); Files.deleteIfExists(path); System.out.println(" |- Write File " + dataName); genotypicData.writeData(path, FileType.TXT); System.out.println(" |- Read written File " + dataName); testData(SimpleFrequencyGenotypeData.readData(path, FileType.TXT)); }
From source file:org.corehunter.tests.data.simple.SimpleDefaultGenotypeDataTest.java
@Test public void homozygousToCsvFile() throws IOException { dataName = "out.csv"; expectedHeaders = HEADERS_UNIQUE_NAMES; expectedMarkerNames = MARKER_NAMES_DEFAULT; expectedAlleleNames = ALLELE_NAMES_HOMOZYGOUS; SimpleDefaultGenotypeData genotypicData = new SimpleDefaultGenotypeData(NAME, HEADERS_UNIQUE_NAMES, MARKER_NAMES_DEFAULT, ALLELE_OBS_HOMOZYGOUS); Path path = Paths.get(TEST_OUTPUT); Files.createDirectories(path); path = Files.createTempDirectory(path, "GenoHomozygous-Csv"); path = Paths.get(path.toString(), dataName); System.out.println(" |- Write homozygous File " + dataName); genotypicData.writeData(path, FileType.CSV); System.out.println(" |- Read written File " + dataName); testDataHomozygous(SimpleDefaultGenotypeData.readData(path, FileType.CSV)); }
From source file:org.corehunter.tests.data.simple.SimpleDistanceMatrixDataTest.java
@Test public void toCsvFileWithSelectedIds() throws IOException { expectedHeaders = HEADERS_UNIQUE_NAMES; SimpleDistanceMatrixData distanceData = new SimpleDistanceMatrixData(expectedHeaders, DISTANCES); Set<Integer> ids = distanceData.getIDs(); Path dirPath = Paths.get(TEST_OUTPUT); Files.createDirectories(dirPath); dirPath = Files.createTempDirectory(dirPath, "DistanceMatrix-SelectedIds"); // create solution SubsetSolution solution = new SubsetSolution(ids); for (int sel : SELECTION) { solution.select(sel);/*from www . j av a 2s. c om*/ } Path path; // write with integer ids dataName = "with-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write distance matrix file (with solution) " + dataName); distanceData.writeData(path, FileType.CSV, solution, true, true, false); assertTrue("Output is not correct!", FileUtils.contentEquals(new File( SimpleDistanceMatrixDataTest.class.getResource("/distances/out/sel-with-ids.csv").getPath()), path.toFile())); // write without integer ids dataName = "no-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write distance matrix file (with solution) " + dataName); distanceData.writeData(path, FileType.CSV, solution, false, true, false); assertTrue("Output is not correct!", FileUtils.contentEquals(new File( SimpleDistanceMatrixDataTest.class.getResource("/distances/out/sel-no-ids.csv").getPath()), path.toFile())); }
From source file:org.corehunter.tests.data.simple.SimpleBiAllelicGenotypeDataTest.java
@Test public void toCsvFile() throws IOException { dataName = "out.csv"; expectedHeaders = HEADERS_NON_UNIQUE_NAMES; expectedMarkerNames = MARKER_NAMES;/* w w w . j a v a 2 s . c om*/ SimpleBiAllelicGenotypeData genotypicData = new SimpleBiAllelicGenotypeData(expectedHeaders, expectedMarkerNames, ALLELE_SCORES_BIALLELIC); Path path = Paths.get(TEST_OUTPUT); Files.createDirectories(path); path = Files.createTempDirectory(path, "GenoBiallelic-Csv"); path = Paths.get(path.toString(), dataName); System.out.println(" |- Write File " + dataName); genotypicData.writeData(path, FileType.CSV); System.out.println(" |- Read written File " + dataName); testData(SimpleBiAllelicGenotypeData.readData(path, FileType.CSV)); }
From source file:majordodo.task.BrokerTestUtils.java
@Before public void brokerTestUtilsBefore() throws Exception { // Setup exception handler Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override/*from ww w .j a v a 2 s . c om*/ public void uncaughtException(Thread t, Throwable e) { System.err.println("uncaughtException from thread " + t.getName() + ": " + e); e.printStackTrace(); unhandledExceptions.add(e); } }); // Setup Logger System.out.println("Setup logger to level " + logLevel.getName()); java.util.logging.LogManager.getLogManager().reset(); ConsoleHandler ch = new ConsoleHandler(); ch.setLevel(logLevel); ch.setFormatter(new Formatter() { @Override public String format(LogRecord record) { return "" + new java.sql.Timestamp(record.getMillis()) + " " + record.getLevel() + " [" + getThreadName(record.getThreadID()) + "<" + record.getThreadID() + ">] " + record.getLoggerName() + ": " + formatMessage(record) + "\n"; } }); java.util.logging.Logger.getLogger("").setLevel(logLevel); java.util.logging.Logger.getLogger("").addHandler(ch); // Initialize groupsMap groupsMap.clear(); groupsMap.put(userId, group); // Setup workdir Path mavenTargetDir = Paths.get("target").toAbsolutePath(); workDir = Files.createTempDirectory(mavenTargetDir, "test" + System.nanoTime()); if (startBroker) { broker = new Broker(brokerConfig, new FileCommitLog(workDir, workDir, 1024 * 1024), new TasksHeap(1000, createTaskPropertiesMapperFunction())); broker.startAsWritable(); server = new NettyChannelAcceptor(broker.getAcceptor()); server.start(); } if (startReplicatedBrokers) { zkServer = new ZKTestEnv(folderZk.getRoot().toPath()); zkServer.startBookie(); // Broker 1 broker1 = new Broker(broker1Config, new ReplicatedCommitLog(zkServer.getAddress(), zkServer.getTimeout(), zkServer.getPath(), folderSnapshots.newFolder().toPath(), BrokerHostData.formatHostdata( new BrokerHostData(broker1Host, broker1Port, "", false, null)), false), new TasksHeap(1000, createTaskPropertiesMapperFunction())); broker1.startAsWritable(); server1 = new NettyChannelAcceptor(broker1.getAcceptor(), broker1Host, broker1Port); server1.start(); // Broker 2 broker2 = new Broker(broker2Config, new ReplicatedCommitLog(zkServer.getAddress(), zkServer.getTimeout(), zkServer.getPath(), folderSnapshots.newFolder().toPath(), BrokerHostData.formatHostdata( new BrokerHostData(broker2Host, broker2Port, "", false, null)), false), new TasksHeap(1000, createTaskPropertiesMapperFunction())); broker2.start(); server2 = new NettyChannelAcceptor(broker2.getAcceptor(), broker2Host, broker2Port); server2.start(); // Broker locator brokerLocator = new ZKBrokerLocator(zkServer.getAddress(), zkServer.getTimeout(), zkServer.getPath()); } }