List of usage examples for java.nio.file Files createTempDirectory
public static Path createTempDirectory(String prefix, FileAttribute<?>... attrs) throws IOException
From source file:com.google.cloud.dataflow.sdk.io.TextIOTest.java
License:asdf
private <T> void runTestWrite(T[] elems, String header, String footer, Coder<T> coder, int numShards) throws Exception { String outputName = "file.txt"; Path baseDir = Files.createTempDirectory(tempFolder, "testwrite"); String baseFilename = baseDir.resolve(outputName).toString(); Pipeline p = TestPipeline.create();//from ww w . j ava2 s . c om PCollection<T> input = p.apply(Create.of(Arrays.asList(elems)).withCoder(coder)); TextIO.Write.Bound<T> write; if (coder.equals(StringUtf8Coder.of())) { TextIO.Write.Bound<String> writeStrings = TextIO.Write.to(baseFilename); // T==String write = (TextIO.Write.Bound<T>) writeStrings; } else { write = TextIO.Write.to(baseFilename).withCoder(coder); } if (numShards == 1) { write = write.withoutSharding(); } else { write = write.withNumShards(numShards).withShardNameTemplate(ShardNameTemplate.INDEX_OF_MAX); } write = write.withHeader(header).withFooter(footer); input.apply(write); p.run(); assertOutputFiles(elems, header, footer, coder, numShards, baseDir, outputName, write.getShardNameTemplate()); }
From source file:org.dawnsci.marketplace.ui.editors.OverviewPage.java
protected void scheduleExportJob() throws IOException { Path folder = Files.createTempDirectory("eclipse-export", new FileAttribute<?>[0]); final FeatureExportInfo info = new FeatureExportInfo(); info.toDirectory = false; // in order to install from the repository info.useJarFormat = true;// w w w . j a va2 s .c o m info.exportSource = false; info.exportSourceBundle = false; info.allowBinaryCycles = true; info.useWorkspaceCompiledClasses = false; info.destinationDirectory = folder.toString(); info.zipFileName = "p2-repo.zip"; info.items = getFeatures(); info.signingInfo = null; // info.exportMetadata = true; info.qualifier = QualifierReplacer.getDateQualifier(); final FeatureExportOperation job = new FeatureExportOperation(info, PDEUIMessages.FeatureExportJob_name); job.setUser(true); job.setRule(ResourcesPlugin.getWorkspace().getRoot()); job.setProperty(IProgressConstants.ICON_PROPERTY, PDEPluginImages.DESC_PLUGIN_OBJ); // listen to job changes, we'll upload stuff when the building has been done job.addJobChangeListener(new JobChangeAdapter() { public void done(IJobChangeEvent event) { if (job.hasAntErrors()) { // if there were errors when running the ant scripts, inform // the user where the logs can be found. final File logLocation = new File(info.destinationDirectory, "logs.zip"); //$NON-NLS-1$ if (logLocation.exists()) { PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { public void run() { AntErrorDialog dialog = new AntErrorDialog(logLocation); dialog.open(); } }); } } else if (event.getResult().isOK()) { // can publish try (CloseableHttpClient client = HttpClientBuilder.create().build()) { // sign in and upload items if (signIn(client)) { uploadForm(client); // upload the images if (solution.getScreenshot() != null) { uploadFile(client, Paths.get(solution.getScreenshot()), "upload-screenshot"); } if (solution.getImage() != null) { uploadFile(client, Paths.get(solution.getImage()), "upload-image"); } // upload the repository uploadFile(client, folder.resolve("p2-repo.zip"), "upload-p2repo"); } } catch (Exception e) { e.printStackTrace(); addMessage(IMessage.ERROR, e.getMessage()); } } } }); job.schedule(); }
From source file:org.corehunter.tests.data.simple.SimplePhenotypeDataTest.java
@Test public void toCsvFileWithSelectedIds() throws IOException { expectedHeaders = HEADERS_UNIQUE_NAMES; SimplePhenotypeData phenotypeData = new SimplePhenotypeData("Phenotype Data", OBJECT_FEATURES_MIN_MAX_COL, OBJECT_TABLE_AS_LIST);//from w w w.ja v a 2s .c o m Set<Integer> ids = phenotypeData.getIDs(); Path dirPath = Paths.get(TEST_OUTPUT); Files.createDirectories(dirPath); dirPath = Files.createTempDirectory(dirPath, "Phenotype-SelectedIds"); // 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 phenotype file (with solution) " + dataName); phenotypeData.writeData(path, FileType.CSV, solution, true, true, false); assertTrue("Output is not correct!", FileUtils .contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/phenotypes/out/sel-with-ids.csv").getPath()), path.toFile())); // write with integer ids dataName = "no-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write phenotype file (with solution) " + dataName); phenotypeData.writeData(path, FileType.CSV, solution, false, true, false); assertTrue("Output is not correct!", FileUtils.contentEquals(new File( SimpleDistanceMatrixDataTest.class.getResource("/phenotypes/out/sel-no-ids.csv").getPath()), path.toFile())); }
From source file:org.corehunter.tests.data.simple.SimplePhenotypeDataTest.java
@Test public void toCsvFileWithUnselectedIds() throws IOException { expectedHeaders = HEADERS_UNIQUE_NAMES; SimplePhenotypeData phenotypeData = new SimplePhenotypeData("Phenotype Data", OBJECT_FEATURES_MIN_MAX_COL, OBJECT_TABLE_AS_LIST);/*w w w .j a va 2 s. c o m*/ Set<Integer> ids = phenotypeData.getIDs(); Path dirPath = Paths.get(TEST_OUTPUT); Files.createDirectories(dirPath); dirPath = Files.createTempDirectory(dirPath, "Phenotype-UnselectedIds"); // 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 phenotype file (with solution) " + dataName); phenotypeData.writeData(path, FileType.CSV, solution, true, false, true); assertTrue("Output is not correct!", FileUtils .contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/phenotypes/out/unsel-with-ids.csv").getPath()), path.toFile())); // write with integer ids dataName = "no-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write phenotype file (with solution) " + dataName); phenotypeData.writeData(path, FileType.CSV, solution, false, false, true); assertTrue("Output is not correct!", FileUtils .contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/phenotypes/out/unsel-no-ids.csv").getPath()), path.toFile())); }
From source file:org.corehunter.tests.data.simple.SimpleDefaultGenotypeDataTest.java
@Test public void diploidToCsvFile() throws IOException { dataName = "out.csv"; expectedHeaders = HEADERS_NON_UNIQUE_NAMES; expectedMarkerNames = MARKER_NAMES_DEFAULT; expectedAlleleNames = ALLELE_NAMES_DIPLOID; SimpleDefaultGenotypeData genotypicData = new SimpleDefaultGenotypeData(NAME, HEADERS_NON_UNIQUE_NAMES, MARKER_NAMES_DEFAULT, ALLELE_OBS_DIPLOID); Path path = Paths.get(TEST_OUTPUT); Files.createDirectories(path); path = Files.createTempDirectory(path, "GenoDiploid-Csv"); path = Paths.get(path.toString(), dataName); System.out.println(" |- Write diploid File " + dataName); genotypicData.writeData(path, FileType.CSV); System.out.println(" |- Read written File " + dataName); testDataDiploid(SimpleDefaultGenotypeData.readData(path, FileType.CSV)); }
From source file:com.spectralogic.ds3client.integration.GetJobManagement_Test.java
@Test(expected = AccessDeniedException.class) public void testReadRetryBugFixWithUnwritableDirectory() throws IOException, URISyntaxException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InterruptedException { Assume.assumeFalse(iAmRoot());// w ww.ja va 2 s . c o m final String tempPathPrefix = null; final Path tempDirectoryPath = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String tempDirectoryName = tempDirectoryPath.toString(); if (org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS) { // Deny write data access to everyone, making the directory unwritable. Runtime.getRuntime().exec("icacls " + tempDirectoryName + " /deny Everyone:(WD)").waitFor(); } else { Runtime.getRuntime().exec("chmod -w " + tempDirectoryName).waitFor(); } try { disableWritePermissionForRoot(tempDirectoryName); final String DIR_NAME = "largeFiles/"; final String FILE_NAME = "lesmis-copies.txt"; final Path objPath = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME); final long bookSize = Files.size(objPath); final Ds3Object obj = new Ds3Object(FILE_NAME, bookSize); final Ds3ClientShim ds3ClientShim = new Ds3ClientShim((Ds3ClientImpl) client); final int maxNumBlockAllocationRetries = 1; final int maxNumObjectTransferAttempts = 3; final Ds3ClientHelpers ds3ClientHelpers = Ds3ClientHelpers.wrap(ds3ClientShim, maxNumBlockAllocationRetries, maxNumObjectTransferAttempts); final Ds3ClientHelpers.Job readJob = ds3ClientHelpers.startReadJob(BUCKET_NAME, Arrays.asList(obj)); final GetJobSpectraS3Response jobSpectraS3Response = ds3ClientShim .getJobSpectraS3(new GetJobSpectraS3Request(readJob.getJobId())); assertThat(jobSpectraS3Response.getMasterObjectListResult(), is(notNullValue())); readJob.transfer(new FileObjectGetter(tempDirectoryPath)); final File originalFile = ResourceUtils.loadFileResource(DIR_NAME + FILE_NAME).toFile(); final File fileCopiedFromBP = Paths.get(tempDirectoryPath.toString(), FILE_NAME).toFile(); assertTrue(FileUtils.contentEquals(originalFile, fileCopiedFromBP)); } finally { enableWritePermissionForRoot(tempDirectoryName); if (org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS) { // Grant write data access to everyone, so we can delete the directory Runtime.getRuntime().exec("icacls " + tempDirectoryName + " /grant Everyone:(WD)").waitFor(); } else { Runtime.getRuntime().exec("chmod +w " + tempDirectoryName).waitFor(); } FileUtils.deleteDirectory(tempDirectoryPath.toFile()); } }
From source file:org.apache.beam.sdk.io.TextIOTest.java
License:asdf
@Test @Category(NeedsRunner.class) public void testWriteWithWritableByteChannelFactory() throws Exception { Coder<String> coder = StringUtf8Coder.of(); String outputName = "file.txt"; Path baseDir = Files.createTempDirectory(tempFolder, "testwrite"); PCollection<String> input = p.apply(Create.of(Arrays.asList(LINES2_ARRAY)).withCoder(coder)); final WritableByteChannelFactory writableByteChannelFactory = new DrunkWritableByteChannelFactory(); TextIO.Write write = TextIO.write().to(baseDir.resolve(outputName).toString()).withoutSharding() .withWritableByteChannelFactory(writableByteChannelFactory); DisplayData displayData = DisplayData.from(write); assertThat(displayData, hasDisplayItem("writableByteChannelFactory", "DRUNK")); input.apply(write);/*from w w w . j av a2s. com*/ p.run(); final List<String> drunkElems = new ArrayList<>(LINES2_ARRAY.length * 2 + 2); for (String elem : LINES2_ARRAY) { drunkElems.add(elem); drunkElems.add(elem); } assertOutputFiles(drunkElems.toArray(new String[0]), null, null, 1, baseDir, outputName + writableByteChannelFactory.getFilenameSuffix(), write.getShardTemplate()); }
From source file:com.boundlessgeo.wps.grass.GrassProcesses.java
/** * Define a GISBASE/LOCATION_NAME for the provided dem. * * @param operation Name used for the location on disk * @param dem File used to establish CRS and Bounds for the location * @return// w w w.ja v a 2 s . c o m * @throws Exception */ static File location(CoordinateReferenceSystem crs) throws Exception { String code = CRS.toSRS(crs, true); File geodb = new File(System.getProperty("user.home"), "grassdata"); File location = Files.createTempDirectory(geodb.toPath(), code).toFile(); KVP kvp = new KVP("geodb", geodb, "location", location); // grass70 + ' -c epsg:' + myepsg + ' -e ' + location_path CommandLine cmd = new CommandLine(EXEC); cmd.addArgument("-c"); cmd.addArgument("epsg:" + code); cmd.addArgument("-e"); cmd.addArgument("${location}"); cmd.setSubstitutionMap(kvp); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValue(0); executor.setWatchdog(new ExecuteWatchdog(60000)); executor.setStreamHandler(new PumpStreamHandler(System.out)); int exitValue = executor.execute(cmd); return location; }
From source file:org.corehunter.tests.data.simple.SimpleDefaultGenotypeDataTest.java
@Test public void diploidToCsvFileWithAllIds() throws IOException { expectedHeaders = HEADERS_UNIQUE_NAMES; expectedMarkerNames = MARKER_NAMES_DEFAULT; expectedAlleleNames = ALLELE_NAMES_DIPLOID; SimpleDefaultGenotypeData genotypicData = new SimpleDefaultGenotypeData(NAME, HEADERS_UNIQUE_NAMES, MARKER_NAMES_DEFAULT, ALLELE_OBS_DIPLOID); Set<Integer> ids = genotypicData.getIDs(); Path dirPath = Paths.get(TEST_OUTPUT); Files.createDirectories(dirPath); dirPath = Files.createTempDirectory(dirPath, "GenoDiploid-AllIds"); // create solution SubsetSolution solution = new SubsetSolution(ids); for (int sel : SELECTION) { solution.select(sel);/* ww w.jav a2 s .co m*/ } Path path; // write with integer ids dataName = "with-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write default genotypes file (diploid, with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, true, true); assertTrue("Output is not correct!", FileUtils .contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/diploid_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 (diploid, with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, true, false); assertTrue("Output is not correct!", FileUtils .contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/diploid_genotypes/out/all-no-ids.csv").getPath()), path.toFile())); }
From source file:org.corehunter.tests.data.simple.SimpleDefaultGenotypeDataTest.java
@Test public void diploidToCsvFileWithSelectedIds() throws IOException { expectedHeaders = HEADERS_UNIQUE_NAMES; expectedMarkerNames = MARKER_NAMES_DEFAULT; expectedAlleleNames = ALLELE_NAMES_DIPLOID; SimpleDefaultGenotypeData genotypicData = new SimpleDefaultGenotypeData(NAME, HEADERS_UNIQUE_NAMES, MARKER_NAMES_DEFAULT, ALLELE_OBS_DIPLOID); Set<Integer> ids = genotypicData.getIDs(); Path dirPath = Paths.get(TEST_OUTPUT); Files.createDirectories(dirPath); dirPath = Files.createTempDirectory(dirPath, "GenoDiploid-SelectedIds"); // create solution SubsetSolution solution = new SubsetSolution(ids); for (int sel : SELECTION) { solution.select(sel);/*from w w w .j a va2s . com*/ } Path path; // write with integer ids dataName = "with-ids.csv"; path = Paths.get(dirPath.toString(), dataName); System.out.println(" |- Write default genotypes file (diploid, with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, false, true); assertTrue("Output is not correct!", FileUtils .contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/diploid_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 (diploid, with solution) " + dataName); genotypicData.writeData(path, FileType.CSV, solution, true, false, false); assertTrue("Output is not correct!", FileUtils .contentEquals( new File(SimpleDistanceMatrixDataTest.class .getResource("/diploid_genotypes/out/sel-no-ids.csv").getPath()), path.toFile())); }