List of usage examples for java.nio.file Path toString
String toString();
From source file:ddf.catalog.cache.impl.ResourceCacheImplTest.java
@Before public void setUp() throws IOException, URISyntaxException { cachedMetacard = createMetacard(SOURCE_ID, METACARD_ID); notCachedMetacard = createMetacard(SOURCE_ID, NOT_CACHED_METACARD_ID); Path ddfData = testFolder.newFolder("data").toPath(); defaultProductCacheDirectory = Paths.get(ddfData.toString(), "Product_Cache"); defaultProductCacheDirectory.toFile().mkdirs(); resourceCache = new ResourceCacheImpl(defaultProductCacheDirectory.toString()); newResourceCache = new org.codice.ddf.catalog.resource.cache.impl.ResourceCacheImpl(resourceCache); }
From source file:com.gitpitch.services.DiskService.java
public int download(PitchParams pp, Path wd, String source, String dest, Map<String, String> headers) { int downloaded = 999; try {//from ww w.j a v a2 s . c o m log.debug("download: pp={}, source={}", pp, source); ensure(bwd(pp)); Path destPath = Paths.get(wd.toString(), dest); delete(destPath); final long start = System.currentTimeMillis(); byte[] fetched = ws.fetchBytes(pp, source, headers); if (fetched != null) { Files.write(destPath, fetched); downloaded = STATUS_OK; log.debug("download: pp={}, time-taken={} (ms) to " + "write {} bytes to {} from source={}", pp, (System.currentTimeMillis() - start), fetched.length, destPath, source); } else { log.debug("download: pp={}, failed to download and write " + "from source={}", pp, source); } } catch (Exception dex) { log.warn("download: failed pp={}, from source={}, ex={}", pp, source, dex); } return downloaded; }
From source file:com.redhat.plugin.eap6.AbstractEAP6Mojo.java
protected void addResourceDir(final File resDir) { if (addResourceFolder && resDir != null && resDir.exists()) { final Resource res = new Resource(); final Path pathResourceDir = Paths.get(resDir.toURI()); final Path pathProject = Paths.get(project.getBasedir().toURI()); final Path pathRelativeDir = pathProject.relativize(pathResourceDir); final String stringRelativeDir = FilenameUtils.separatorsToUnix(pathRelativeDir.toString()); res.setDirectory(stringRelativeDir); getLog().info("Adding dir <" + resDir.getPath() + "> as relative path <" + stringRelativeDir + "> to project-resources"); if (project != null) { project.addResource(res);// ww w .java 2 s .c om } else { getLog().warn("No project available, adding of resource-dir skipped"); } } }
From source file:com.sumzerotrading.eod.trading.strategy.ReportGeneratorTest.java
@Test public void testWriteRoundTrip() throws Exception { Path path = Files.createTempFile("ReportGeneratorUnitTest", ".txt"); reportGenerator.outputFile = path.toString(); String expected = "2016-03-19T07:01:10,Long,ABC,100,100.23,0,2016-03-20T06:01:10,101.23,0,Short,XYZ,50,250.34,0,251.34,0"; Ticker longTicker = new StockTicker("ABC"); Ticker shortTicker = new StockTicker("XYZ"); int longSize = 100; int shortSize = 50; double longEntryFillPrice = 100.23; double longExitFillPrice = 101.23; double shortEntryFillPrice = 250.34; double shortExitFillPrice = 251.34; ZonedDateTime entryTime = ZonedDateTime.of(2016, 3, 19, 7, 1, 10, 0, ZoneId.systemDefault()); ZonedDateTime exitTime = ZonedDateTime.of(2016, 3, 20, 6, 1, 10, 0, ZoneId.systemDefault()); TradeOrder longEntry = new TradeOrder("123", longTicker, longSize, TradeDirection.BUY); longEntry.setFilledPrice(longEntryFillPrice); longEntry.setOrderFilledTime(entryTime); TradeOrder longExit = new TradeOrder("123", longTicker, longSize, TradeDirection.SELL); longExit.setFilledPrice(longExitFillPrice); longExit.setOrderFilledTime(exitTime); TradeOrder shortEntry = new TradeOrder("123", shortTicker, shortSize, TradeDirection.SELL); shortEntry.setFilledPrice(shortEntryFillPrice); shortEntry.setOrderFilledTime(entryTime); TradeOrder shortExit = new TradeOrder("123", shortTicker, shortSize, TradeDirection.BUY); shortExit.setFilledPrice(shortExitFillPrice); shortExit.setOrderFilledTime(exitTime); RoundTrip roundTrip = new RoundTrip(); roundTrip.longEntry = longEntry;/*from w ww . j a va2s .c o m*/ roundTrip.longExit = longExit; roundTrip.shortEntry = shortEntry; roundTrip.shortExit = shortExit; System.out.println("Writing out to file: " + path); reportGenerator.writeRoundTripToFile(roundTrip); List<String> lines = Files.readAllLines(path); assertEquals(1, lines.size()); assertEquals(expected, lines.get(0)); Files.deleteIfExists(path); }
From source file:pro.foundev.cassandra.commons.migrations.MigrationRunnerTest.java
@Test public void whenParsingYamlFileItShouldStillBeAbleToRunMigrations() throws IOException { cqlFile.createCQLFile("1_create_table_1.cql", "CREATE TABLE my_table (id int, value text," + "PRIMARY KEY(id))"); Path yamlFile = cqlFile.createYamlFile(keyspaceName); migrationRunner = new MigrationRunnerImpl(yamlFile.toString()); migrationRunner.runScriptDirectory(scriptDirectory); assertTableExists("my_table"); }
From source file:edu.usu.sdl.openstorefront.service.ReportServiceImpl.java
@Override public void deleteReport(String reportId) { Report existingReport = persistenceService.findById(Report.class, reportId); if (existingReport != null) { Path path = existingReport.pathToReport(); if (path != null) { if (path.toFile().exists()) { boolean success = path.toFile().delete(); if (success == false) { log.log(Level.WARNING, MessageFormat.format("Unable to remove old report: {0}", path.toString())); }//from ww w. j a v a2s . c om } } persistenceService.delete(existingReport); } }
From source file:ca.wumbo.doommanager.client.controller.FileEditorController.java
/** * Requests the user to select a file to open. *///from w w w. j av a 2 s . c om public void openFile() { log.debug("Attempting to open file..."); // Provide a file chooser that looks for extensions we know. FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open file"); fileChooser.getExtensionFilters().addAll( new FileChooser.ExtensionFilter("Any Doom File", "*.wad", "*.WAD", "*.pk3", "*.PK3", "*.dxml", "*.DXML"), new FileChooser.ExtensionFilter("DoomManager Project Files", "*.dxml", "*.DXML"), new FileChooser.ExtensionFilter("Wad Files", "*.wad", "*.WAD"), new FileChooser.ExtensionFilter("PK3 Files", "*.pk3", "*.PK3"), new FileChooser.ExtensionFilter("All files", "*.*")); List<File> files = fileChooser.showOpenMultipleDialog(coreController.getStage()); // If the user selected one or more files... if (files != null) { // For each file the user selected... for (File file : files) { Path filePath = file.toPath(); String lowerPath = filePath.toString().toLowerCase(); log.debug("Attempting to load file from {}...", filePath.toString()); // Handle based on ending: if (lowerPath.endsWith(".wad")) { openWad(filePath); } else if (lowerPath.endsWith(".pk3")) { openPK3(filePath); } else if (lowerPath.endsWith(".dxml")) { openDXMLProject(filePath); } } } }
From source file:io.stallion.dataAccess.file.TextFilePersister.java
public T fromHtml(String fileContent, Path fullPath) { String relativePath = fullPath.toString().replace(getBucketFolderPath(), ""); Path path = fullPath;/* w w w .j ava2 s . c o m*/ List<String> htmlLines = list(); List<String> tomlLines = list(); boolean inToml = false; for (String line : StringUtils.split(fileContent.trim(), "\n")) { if (line.trim().equals("<!--start-toml")) { inToml = true; continue; } else if (line.trim().equals("end-toml-->")) { inToml = false; continue; } if (inToml) { tomlLines.add(line); } else { htmlLines.add(line); } } String toml = StringUtils.join(tomlLines, "\n"); String html = StringUtils.join(htmlLines, "\n"); T item = null; if (!empty(toml)) { item = new Toml().read(toml).to(getModelClass()); } else { try { item = getModelClass().newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } item.setTags(new ArrayList<String>()).setElementById(new HashMap<>()).setElements(new ArrayList<>()) .setTitle("").setDraft(true).setTemplate("").setContent("").setSlug(null); } /* Set the content */ item.setContent(html); item.setOriginalContent(fileContent); /* Set the slug from the file path, if it does not exist */ if (item.getSlug() == null) { item.setSlug(FilenameUtils.removeExtension(relativePath)); if (!item.getSlug().startsWith("/")) { item.setSlug("/" + item.getSlug()); } if (item.getSlug().endsWith("/index")) { item.setSlug(item.getSlug().substring(item.getSlug().length() - 6)); } } Log.fine("Loaded text item: id:{0} slug:{1} title:{2} draft:{3}", item.getId(), item.getSlug(), item.getTitle(), item.getDraft()); return item; }
From source file:de.tudarmstadt.ukp.dkpro.core.api.datasets.internal.actions.Explode.java
@Override public void apply(ActionDescription aAction, DatasetDescription aDataset, ArtifactDescription aPack, Path aCachedFile) throws Exception { DatasetDescriptionImpl dsi = (DatasetDescriptionImpl) aDataset; Map<String, Object> cfg = aAction.getConfiguration(); // Sometimes, we have to explode a file that was created as the result of exploding the // main artifact. Thus, we can override the target Path targetFile = cfg.containsKey("file") ? dsi.getOwner().resolve(dsi).resolve((String) cfg.get("file")) : aCachedFile;/*from ww w .j a v a2s . c o m*/ // Apache Commons Compress does not handle RAR files, so we handle them separately if (targetFile.toString().toLowerCase(Locale.ENGLISH).endsWith(".rar")) { extractRar(aAction, targetFile, dsi.getOwner().resolve(dsi)); } if (targetFile.toString().toLowerCase(Locale.ENGLISH).endsWith(".7z")) { // 7z does not support streaming in Apache Commons Compress extract7z(aAction, targetFile, dsi.getOwner().resolve(dsi)); } else { // Auto-detect the archive format using Apache Commons Compress try (InputStream is = new BufferedInputStream(Files.newInputStream(targetFile))) { InputStream uncompressed; try { uncompressed = new BufferedInputStream( new CompressorStreamFactory().createCompressorInputStream(is)); } catch (CompressorException e) { // If the compressor is not detected, we may be dealing with an archive format that // compresses internally, e.g. ZIP. uncompressed = is; } ArchiveInputStream archive = new ArchiveStreamFactory().createArchiveInputStream(uncompressed); extract(aAction, targetFile, archive, dsi.getOwner().resolve(dsi)); } } }
From source file:com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService.java
private void downloadAndCopyJars(Set<String> jarsToDownload, Path destinationPath) throws IOException { Set<String> copiedJars = new HashSet<>(); for (String jar : jarsToDownload) { if (!copiedJars.contains(jar)) { File destPath = Paths.get(destinationPath.toString(), Paths.get(jar).getFileName().toString()) .toFile();/*from w w w .j av a 2 s.c om*/ try (InputStream src = fileStorage.downloadFile(jar); FileOutputStream dest = new FileOutputStream(destPath)) { IOUtils.copy(src, dest); copiedJars.add(jar); LOG.debug("Jar {} copied to {}", jar, destPath); } } } }