List of usage examples for java.nio.file Path toAbsolutePath
Path toAbsolutePath();
From source file:org.sakuli.starter.helper.SakuliFolderHelperTest.java
@Test public void testCheckHomeFolder() throws Exception { Path path = Paths.get(BaseTest.SAKULI_HOME_FOLDER_PATH); assertTrue(Files.exists(path)); SakuliFolderHelper.checkSakuliHomeFolderAndSetContextVariables(path.toString(), ""); assertEquals(SakuliPropertyPlaceholderConfigurer.SAKULI_HOME_FOLDER_VALUE, path.toAbsolutePath().normalize().toString()); }
From source file:org.epics.archiverappliance.etl.DataReductionTest.java
/** * Generates some data in STS; then calls the ETL to move it to MTS. * Check that we only move reduced data into the MTS. *///from ww w .jav a2 s . c o m @Test public void testMove() throws Exception { String reduceDataUsing = "firstSample_3600"; PlainPBStoragePlugin etlSrc = (PlainPBStoragePlugin) StoragePluginURLParser .parseStoragePlugin("pb://localhost?name=STS&rootFolder=" + shortTermFolderName + "/&partitionGranularity=PARTITION_DAY", configService); ; PlainPBStoragePlugin etlDest = (PlainPBStoragePlugin) StoragePluginURLParser .parseStoragePlugin( "pb://localhost?name=MTS&rootFolder=" + mediumTermFolderName + "/&partitionGranularity=PARTITION_YEAR&reducedata=" + reduceDataUsing, configService); logger.info("Testing data reduction for " + etlSrc.getPartitionGranularity() + " to " + etlDest.getPartitionGranularity()); String pvName = ConfigServiceForTests.ARCH_UNIT_TEST_PVNAME_PREFIX + "ETL_testMove" + etlSrc.getPartitionGranularity(); SimulationEventStream simstream = new SimulationEventStream(ArchDBRTypes.DBR_SCALAR_DOUBLE, new SineGenerator(0)); try (BasicContext context = new BasicContext()) { etlSrc.appendData(context, pvName, simstream); } logger.info("Done creating src data for PV " + pvName); long beforeCount = 0; try (BasicContext context = new BasicContext(); EventStream before = new CurrentThreadWorkerEventStream(pvName, etlSrc.getDataForPV(context, pvName, TimeUtils.minusDays(TimeUtils.now(), 366), TimeUtils.plusDays(TimeUtils.now(), 366)))) { for (@SuppressWarnings("unused") Event e : before) { beforeCount++; } } PostProcessor postProcessor = PostProcessors.findPostProcessor(reduceDataUsing); postProcessor.initialize(reduceDataUsing, pvName); long beforeReducedCount = 0; List<Event> reducedEvents = new LinkedList<Event>(); try (BasicContext context = new BasicContext(); EventStream before = new CurrentThreadWorkerEventStream(pvName, etlSrc.getDataForPV(context, pvName, TimeUtils.minusDays(TimeUtils.now(), 366), TimeUtils.plusDays(TimeUtils.now(), 366), postProcessor))) { for (Event e : before) { reducedEvents.add(e.makeClone()); beforeReducedCount++; } } PVTypeInfo typeInfo = new PVTypeInfo(pvName, ArchDBRTypes.DBR_SCALAR_DOUBLE, true, 1); String[] dataStores = new String[] { etlSrc.getURLRepresentation(), etlDest.getURLRepresentation() }; typeInfo.setDataStores(dataStores); configService.updateTypeInfoForPV(pvName, typeInfo); configService.registerPVToAppliance(pvName, configService.getMyApplianceInfo()); configService.getETLLookup().manualControlForUnitTests(); Timestamp timeETLruns = TimeUtils.plusDays(TimeUtils.now(), 365 * 10); ETLExecutor.runETLs(configService, timeETLruns); logger.info( "Done performing ETL as though today is " + TimeUtils.convertToHumanReadableString(timeETLruns)); Timestamp startOfRequest = TimeUtils.minusDays(TimeUtils.now(), 366); Timestamp endOfRequest = TimeUtils.plusDays(TimeUtils.now(), 366); // Check that all the files in the destination store are valid files. Path[] allPaths = PlainPBPathNameUtility.getAllPathsForPV(new ArchPaths(), etlDest.getRootFolder(), pvName, ".pb", etlDest.getPartitionGranularity(), CompressionMode.NONE, configService.getPVNameToKeyConverter()); assertTrue("PlainPBFileNameUtility returns null for getAllFilesForPV for " + pvName, allPaths != null); assertTrue("PlainPBFileNameUtility returns empty array for getAllFilesForPV for " + pvName + " when looking in " + etlDest.getRootFolder(), allPaths.length > 0); for (Path destPath : allPaths) { assertTrue("File validation failed for " + destPath.toAbsolutePath().toString(), ValidatePBFile.validatePBFile(destPath, false)); } logger.info("Asking for data between" + TimeUtils.convertToHumanReadableString(startOfRequest) + " and " + TimeUtils.convertToHumanReadableString(endOfRequest)); long afterCount = 0; try (BasicContext context = new BasicContext(); EventStream afterDest = new CurrentThreadWorkerEventStream(pvName, etlDest.getDataForPV(context, pvName, startOfRequest, endOfRequest))) { assertNotNull(afterDest); for (@SuppressWarnings("unused") Event e : afterDest) { afterCount++; } } logger.info("Of the " + beforeCount + " events, " + afterCount + " events were moved into the dest store."); assertTrue("Seems like no events were moved by ETL " + afterCount, (afterCount != 0)); long afterSourceCount = 0; try (BasicContext context = new BasicContext(); EventStream afterSrc = new CurrentThreadWorkerEventStream(pvName, etlSrc.getDataForPV(context, pvName, startOfRequest, endOfRequest))) { for (@SuppressWarnings("unused") Event e : afterSrc) { afterSourceCount++; } } assertTrue("Seems like we still have " + afterSourceCount + " events in the source ", (afterSourceCount == 0)); // Now compare the events itself try (BasicContext context = new BasicContext(); EventStream afterDest = new CurrentThreadWorkerEventStream(pvName, etlDest.getDataForPV(context, pvName, startOfRequest, endOfRequest))) { int index = 0; for (Event afterEvent : afterDest) { Event beforeEvent = reducedEvents.get(index); assertTrue( "Before timestamp " + TimeUtils.convertToHumanReadableString(beforeEvent.getEventTimeStamp()) + " After timestamp " + TimeUtils.convertToHumanReadableString(afterEvent.getEventTimeStamp()), beforeEvent.getEventTimeStamp().equals(afterEvent.getEventTimeStamp())); assertTrue( "Before value " + beforeEvent.getSampleValue().getValue() + " After value " + afterEvent.getSampleValue().getValue(), beforeEvent.getSampleValue().getValue().equals(afterEvent.getSampleValue().getValue())); index++; } } assertTrue("Of the total " + beforeCount + " event, we should have moved " + beforeReducedCount + ". Instead we seem to have moved " + afterCount, beforeReducedCount == afterCount); }
From source file:net.geoprism.localization.LocaleManager.java
private Collection<Locale> loadCLDRs() { try {//from w w w . jav a 2 s .c om // Get the list of known CLDR locale Set<Locale> locales = new HashSet<Locale>(); Set<String> paths = new HashSet<String>(); URL resource = this.getClass().getResource("/cldr/main"); URI uri = resource.toURI(); if (uri.getScheme().equals("jar")) { FileSystem fileSystem = FileSystems.newFileSystem(uri, new HashMap<String, Object>()); Path path = fileSystem.getPath("/cldr/main"); Stream<Path> walk = Files.walk(path, 1); try { for (Iterator<Path> it = walk.iterator(); it.hasNext();) { Path location = it.next(); paths.add(location.toAbsolutePath().toString()); } } finally { walk.close(); } } else { String url = resource.getPath(); File root = new File(url); File[] files = root.listFiles(new DirectoryFilter()); if (files != null) { for (File file : files) { paths.add(file.getAbsolutePath()); } } } for (String path : paths) { File file = new File(path); String filename = file.getName(); locales.add(LocaleManager.getLocaleForName(filename)); } return locales; } catch (Exception e) { throw new ProgrammingErrorException(e); } }
From source file:org.xlrnet.tibaija.graphics.FontRegistry.java
public void registerFont(@NotNull Path filePath, @NotNull String identifier) throws IOException { if (fontMap.containsKey(identifier)) { throw new FontImportException("Font with identifier " + identifier + " already exists"); }/*from w w w . ja v a 2s . c om*/ LOGGER.info("Reading font file {} ...", filePath.toAbsolutePath()); InputStream in = Files.newInputStream(filePath); Font font = objectMapper.readValue(in, Font.class); registerFont(font, identifier); }
From source file:ee.ria.xroad.confproxy.util.OutputBuilder.java
/** * Opens a stream for writing the configuration file describes by the metadata to the target location. * @param targetPath location to write the file to * @param metadata describes the configuration file * @return output stream for writing the file * @throws Exception if errors during file operations occur *///from ww w .ja v a 2s . co m private FileOutputStream createFileOutputStream(final Path targetPath, final ConfigurationPartMetadata metadata) throws Exception { Path filepath = targetPath .resolve(Paths.get(metadata.getInstanceIdentifier(), metadata.getContentLocation())); Files.createDirectories(filepath.getParent()); Path newFile = Files.createFile(filepath); log.debug("Copying file '{}' to directory '{}'", newFile.toAbsolutePath(), targetPath); return new FileOutputStream(newFile.toAbsolutePath().toFile()); }
From source file:org.codice.ddf.configuration.AbsolutePathResolver.java
/** * This method will attempt to convert the already given path into an absolute path: first by * appending the given {@code rootPath}, then by using {@code Path}'s {@code toAbsolutePath}'s * method//from w w w. j a va2 s . c om * * @param rootPath String to append to path * @return Absolute path as a String */ public String getPath(String rootPath) { if (path == null) { return null; } boolean trailingSeparator = path.endsWith(File.separator); Path absolutePath = Paths.get(path); if (!absolutePath.isAbsolute()) { if (StringUtils.isNotBlank(rootPath)) { absolutePath = Paths.get(rootPath, path); } else { LOGGER.debug("Root path is blank. Resolving relative path [{}] to: {}", path, absolutePath.toAbsolutePath()); } } String absolutePathStr = absolutePath.toAbsolutePath().toString(); return trailingSeparator ? absolutePathStr + File.separator : absolutePathStr; }
From source file:codes.thischwa.c5c.requestcycle.impl.FilemanagerIconResolver.java
private void buildCache(String iconPath, String defaultIcon, String directoryIcon) { this.defaultIcon = defaultIcon; this.directoryIcon = directoryIcon; PathBuilder fileSystemIconPath = new PathBuilder(iconPath); java.nio.file.Path iconFolder = Paths.get(servletContext.getRealPath(fileSystemIconPath.toString())); if (!Files.exists(iconFolder)) throw new RuntimeException(String.format("C5 file icons folder couldn't be found! (%s / %s)", PropertiesLoader.getFilemanagerPath(), iconFolder.toAbsolutePath().toString())); PathBuilder urlPath;//from w w w .java 2 s.c o m if (!StringUtils.isNullOrEmpty(servletContext.getContextPath())) { urlPath = new PathBuilder(servletContext.getContextPath()); urlPath.addFolder(fileSystemIconPath.toString()); } else { urlPath = new PathBuilder(fileSystemIconPath.toString()); } collectIcons(iconPath, iconFolder, urlPath); }
From source file:it.sonarlint.cli.tools.SonarlintCli.java
public Path deployProject(String location) throws IOException { Path originalLoc = Paths.get("projects").resolve(location); String projectName = originalLoc.getFileName().toString(); if (!Files.isDirectory(originalLoc)) { throw new IllegalArgumentException( "Couldn't find project directory: " + originalLoc.toAbsolutePath().toString()); }//from w ww. j a v a 2 s . c o m cleanProject(); project = Files.createTempDirectory(projectName); FileUtils.copyDirectory(originalLoc.toFile(), project.toFile()); return project; }
From source file:functions.TestOptions.java
@Test public void testConfigExists() { Path currentRelativePath = Paths.get(""); String s = currentRelativePath.toAbsolutePath().toString(); final String wdir = FilesystemUtils.getBotAbsolutePath(); File f = new File(testconfig); assertTrue(f.exists());//from ww w . j av a 2s . c o m }
From source file:edu.si.sidora.tabularmetadata.webapp.integration.OperationIT.java
@Test public void testUrlOperation() throws IOException, SAXException { final Path dataFileLocation = createTempFile("testUrlOperation", "-" + randomUUID()); final List<String> lines = asList("NAME,RANK,SERIAL NUMBER", "Kirk,Admiral,002", "McCoy,Doctor,567"); write(dataFileLocation, lines, UTF_8); final Response r = client.resetQuery().query("url", "file://" + dataFileLocation.toAbsolutePath()).get(); assertEquals(OK.getStatusCode(), r.getStatus()); final String text = r.readEntity(String.class); log.trace("Got response: {}", text); assertXMLEqual(properResponse1, text); dataFileLocation.toFile().delete();/*from ww w .j a va2s .c o m*/ }