List of usage examples for java.nio.file Files createTempDirectory
public static Path createTempDirectory(String prefix, FileAttribute<?>... attrs) throws IOException
From source file:org.corehunter.tests.data.simple.SimpleFrequencyGenotypeDataTest.java
@Test public void toCsvFileWithAlleleNames() throws IOException { dataName = "out.csv"; expectedHeaders = HEADERS_UNIQUE_NAMES; expectedMarkerNames = MARKER_NAMES;/* w w w. jav a 2s .co m*/ expectedAlleleNames = 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-CsvAlleleNames"); 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(SimpleFrequencyGenotypeData.readData(path, FileType.CSV)); }
From source file:org.corehunter.tests.data.simple.SimpleDefaultGenotypeDataTest.java
@Test public void homozygousToCsvFileWithAllIds() throws IOException { 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); Set<Integer> ids = genotypicData.getIDs(); Path dirPath = Paths.get(TEST_OUTPUT); Files.createDirectories(dirPath); dirPath = Files.createTempDirectory(dirPath, "GenoHomozygous-AllIds"); // create solution SubsetSolution solution = new SubsetSolution(ids); for (int sel : SELECTION) { solution.select(sel);/*w ww . j av a 2s . c o m*/ } Path path; // write with integer ids dataName = "with-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write default genotypes file (homozygous, with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, true, true); assertTrue("Output is not correct!", FileUtils.contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/homozygous_genotypes/out/all-with-ids.csv").getPath()), path.toFile())); // write without integer ids dataName = "no-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write default genotypes file (homozygous, with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, true, false); assertTrue("Output is not correct!", FileUtils.contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/homozygous_genotypes/out/all-no-ids.csv").getPath()), path.toFile())); }
From source file:org.corehunter.tests.data.simple.SimpleBiAllelicGenotypeDataTest.java
@Test public void toCsvFileWithAllIds() throws IOException { expectedHeaders = HEADERS_UNIQUE_NAMES; expectedMarkerNames = MARKER_NAMES;//from ww w . ja v a 2 s . co m SimpleBiAllelicGenotypeData genotypicData = new SimpleBiAllelicGenotypeData(expectedHeaders, expectedMarkerNames, ALLELE_SCORES_BIALLELIC); Set<Integer> ids = genotypicData.getIDs(); Path dirPath = Paths.get(TEST_OUTPUT); Files.createDirectories(dirPath); dirPath = Files.createTempDirectory(dirPath, "GenoBiallelic-AllIds"); // create solution SubsetSolution solution = new SubsetSolution(ids); for (int sel : SELECTION) { solution.select(sel); } Path path; // write allele score format with integer ids dataName = "bi-with-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write biallelic genotypes file (with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, true, true); assertTrue("Output file is not correct!", FileUtils.contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/biallelic_genotypes/out/all-bi-with-ids.csv").getPath()), path.toFile())); // write allele score format without integer ids dataName = "bi-no-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write biallelic genotypes file (with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, true, false); assertTrue("Output file is not correct!", FileUtils.contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/biallelic_genotypes/out/all-bi-no-ids.csv").getPath()), path.toFile())); }
From source file:org.corehunter.tests.data.simple.SimpleFrequencyGenotypeDataTest.java
@Test public void toCsvFileWithAllIds() throws IOException { expectedHeaders = HEADERS_UNIQUE_NAMES; expectedMarkerNames = MARKER_NAMES;/*from w w w . jav a2s . c o m*/ expectedAlleleNames = ALLELE_NAMES; SimpleFrequencyGenotypeData genotypicData = new SimpleFrequencyGenotypeData(expectedHeaders, expectedMarkerNames, expectedAlleleNames, ALLELE_FREQUENCIES); Set<Integer> ids = genotypicData.getIDs(); Path dirPath = Paths.get(TEST_OUTPUT); Files.createDirectories(dirPath); dirPath = Files.createTempDirectory(dirPath, "GenoFreqs-AllIds"); // create solution SubsetSolution solution = new SubsetSolution(ids); for (int sel : SELECTION) { solution.select(sel); } Path path; // write with integer ids dataName = "with-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write frequency genotypes file (with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, true, true); assertTrue("Output is not correct!", FileUtils.contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/frequency_genotypes/out/all-with-ids.csv").getPath()), path.toFile())); // write without integer ids dataName = "no-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write frequency genotypes file (with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, true, false); assertTrue("Output is not correct!", FileUtils .contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/frequency_genotypes/out/all-no-ids.csv").getPath()), path.toFile())); }
From source file:org.corehunter.tests.data.simple.SimpleDistanceMatrixDataTest.java
@Test public void toCsvFileWithUnselectedIds() 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-UnselectedIds"); // create solution SubsetSolution solution = new SubsetSolution(ids); for (int sel : SELECTION) { solution.select(sel);//from w w w .ja v a 2s. c o m } 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, false, true); assertTrue("Output is not correct!", FileUtils .contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/distances/out/unsel-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, false, true); assertTrue("Output is not correct!", FileUtils.contentEquals(new File( SimpleDistanceMatrixDataTest.class.getResource("/distances/out/unsel-no-ids.csv").getPath()), path.toFile())); }
From source file:com.facebook.presto.hive.TestPrestoS3FileSystem.java
@Test public void testCreateWithNonexistentStagingDirectory() throws Exception { java.nio.file.Path tmpdir = Paths.get(StandardSystemProperty.JAVA_IO_TMPDIR.value()); java.nio.file.Path stagingParent = Files.createTempDirectory(tmpdir, "test"); java.nio.file.Path staging = Paths.get(stagingParent.toString(), "staging"); // stagingParent = /tmp/testXXX // staging = /tmp/testXXX/staging try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) { MockAmazonS3 s3 = new MockAmazonS3(); Configuration conf = new Configuration(); conf.set(PrestoS3FileSystem.S3_STAGING_DIRECTORY, staging.toString()); fs.initialize(new URI("s3n://test-bucket/"), conf); fs.setS3Client(s3);/* w w w . j a v a2 s . c o m*/ FSDataOutputStream stream = fs.create(new Path("s3n://test-bucket/test")); stream.close(); assertTrue(Files.exists(staging)); } finally { deleteRecursively(stagingParent.toFile()); } }
From source file:com.spectralogic.ds3client.metadata.MetadataReceivedListenerImpl_Test.java
@Test public void testGettingMetadataFailureWindows() throws IOException, InterruptedException { Assume.assumeTrue(Platform.isWindows()); try {/* ww w .ja va2 s .c om*/ 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 { // 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)); new MetadataReceivedListenerImpl(tempDirectory.toString()).metadataReceived(fileName, metadata); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } } catch (final Throwable t) { fail("Throwing exceptions from metadata est verbotten"); } }
From source file:org.corehunter.tests.data.simple.SimpleDefaultGenotypeDataTest.java
@Test public void homozygousToCsvFileWithSelectedIds() throws IOException { 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); Set<Integer> ids = genotypicData.getIDs(); Path dirPath = Paths.get(TEST_OUTPUT); Files.createDirectories(dirPath); dirPath = Files.createTempDirectory(dirPath, "GenoHomozygous-SelectedIds"); // create solution SubsetSolution solution = new SubsetSolution(ids); for (int sel : SELECTION) { solution.select(sel);// w w w . j av a 2s .c o m } Path path; // write with integer ids dataName = "with-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write default genotypes file (homozygous, with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, false, true); assertTrue("Output is not correct!", FileUtils.contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/homozygous_genotypes/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 default genotypes file (homozygous, with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, false, false); assertTrue("Output is not correct!", FileUtils.contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/homozygous_genotypes/out/sel-no-ids.csv").getPath()), path.toFile())); }
From source file:io.fabric8.maven.plugin.mojo.infra.AbstractInstallMojo.java
private File createDownloadFile(File downloadLocation, String fileName) throws MojoExecutionException { try {/*from www .ja va2 s.co m*/ File downloadDir = Files.createTempDirectory(downloadLocation.toPath(), "download").toFile(); downloadDir.deleteOnExit(); File ret = new File(downloadDir, fileName); ret.deleteOnExit(); log.debug("Downloading %s to temporary file %s", fileName, ret); return ret; } catch (IOException e) { throw new MojoExecutionException("Failed to create a temporary file for the download"); } }
From source file:org.corehunter.tests.data.simple.SimpleBiAllelicGenotypeDataTest.java
@Test public void toCsvFileWithSelectedIds() throws IOException { expectedHeaders = HEADERS_UNIQUE_NAMES; expectedMarkerNames = MARKER_NAMES;//from ww w . j a v a 2 s . c o m SimpleBiAllelicGenotypeData genotypicData = new SimpleBiAllelicGenotypeData(expectedHeaders, expectedMarkerNames, ALLELE_SCORES_BIALLELIC); Set<Integer> ids = genotypicData.getIDs(); Path dirPath = Paths.get(TEST_OUTPUT); Files.createDirectories(dirPath); dirPath = Files.createTempDirectory(dirPath, "GenoBiallelic-SelectedIds"); // create solution SubsetSolution solution = new SubsetSolution(ids); for (int sel : SELECTION) { solution.select(sel); } Path path; // write allele score format with integer ids dataName = "bi-with-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write biallelic genotypes file (with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, false, true); assertTrue("Output file is not correct!", FileUtils.contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/biallelic_genotypes/out/sel-bi-with-ids.csv").getPath()), path.toFile())); // write allele score format without integer ids dataName = "bi-no-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write biallelic genotypes file (with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, false, false); assertTrue("Output file is not correct!", FileUtils.contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/biallelic_genotypes/out/sel-bi-no-ids.csv").getPath()), path.toFile())); }