List of usage examples for java.nio.file Path toAbsolutePath
Path toAbsolutePath();
From source file:org.lavajug.streamcaster.server.web.controllers.LiveStreamController.java
/** * *///from w w w . j a v a2 s. c o m @GET("/index") public void index() { LinkedList<String> devices = new LinkedList<>(); Path devicesPath = Paths.get("/dev"); try { for (Path device : Files.newDirectoryStream(devicesPath)) { if (device.getFileName().toString().startsWith("video")) { devices.addFirst(device.toAbsolutePath().toString()); } } } catch (IOException ex) { } context.addParameter("isWindows", SystemUtils.IS_OS_WINDOWS); context.addParameter("devices", devices); context.addParameter("section", "LIVE"); context.addParameter("current", Configuration.getCurrentProfile()); render(); }
From source file:com.streamsets.pipeline.lib.io.LiveFile.java
private LiveFile(Path path, String inode, String headHash, int headLen) { this.path = path.toAbsolutePath(); iNode = inode;//from w ww. j ava2 s .c om this.headHash = headHash; this.headLen = headLen; }
From source file:org.apache.geode.test.junit.rules.gfsh.GfshRule.java
protected ProcessBuilder toProcessBuilder(GfshScript gfshScript, Path gfshPath, File workingDir) { List<String> commandsToExecute = new ArrayList<>(); commandsToExecute.add(gfshPath.toAbsolutePath().toString()); for (String command : gfshScript.getCommands()) { commandsToExecute.add("-e " + command); }/*from w ww . jav a 2s.c om*/ ProcessBuilder processBuilder = new ProcessBuilder(commandsToExecute); processBuilder.directory(workingDir); List<String> extendedClasspath = gfshScript.getExtendedClasspath(); if (!extendedClasspath.isEmpty()) { Map<String, String> environmentMap = processBuilder.environment(); String classpathKey = "CLASSPATH"; String existingJavaArgs = environmentMap.get(classpathKey); String specified = String.join(PATH_SEPARATOR, extendedClasspath); String newValue = String.format("%s%s", existingJavaArgs == null ? "" : existingJavaArgs + ":", specified); environmentMap.put(classpathKey, newValue); } return processBuilder; }
From source file:at.tfr.securefs.process.ProcessFilesBean.java
@Override public void verifyDecryption(Path path, CrypterProvider cp, BigInteger newSecret, ProcessFilesData cfd) { if (Files.isRegularFile(path)) { cfd.setCurrentFromPath(path.toAbsolutePath().toString()); updateCache(cfd);/*w w w .j a v a 2 s .c o m*/ try (OutputStream os = new NullOutputStream(); InputStream is = cp.getDecrypter(path, newSecret)) { IOUtils.copy(is, os); log.info("verified read: " + path.toAbsolutePath()); } catch (IOException ioe) { log.info("failed to verify: " + path + " err: " + ioe); cfd.putError(path, ioe); cfd.setLastErrorException(ioe); } } }
From source file:org.apache.taverna.configuration.database.impl.DatabaseManagerImpl.java
private void setDerbyPaths() { if (databaseConfiguration.getConnectorType() == DatabaseConfiguration.CONNECTOR_DERBY) { String homeDir = applicationConfiguration.getApplicationHomeDir().toAbsolutePath().toString(); System.setProperty("derby.system.home", homeDir); Path logFile = applicationConfiguration.getLogDir().resolve("derby.log"); System.setProperty("derby.stream.error.file", logFile.toAbsolutePath().toString()); }//from w w w.j av a 2 s .c o m }
From source file:org.eclipse.vorto.remoterepository.internal.dao.FilesystemModelDAO.java
@Override public ModelContent getModelById(ModelId id) { Objects.requireNonNull(id);/*from ww w . j a v a 2 s . co m*/ Objects.requireNonNull(id.getModelType(), "Model type shouldn't be Null."); Objects.requireNonNull(id.getName(), "Model name shouldn't be Null."); Objects.requireNonNull(id.getNamespace(), "Namespace shouldn't be Null."); Objects.requireNonNull(id.getVersion(), "Version shouldn't be Null."); ModelContent mc = new ModelContent(id, id.getModelType(), null); Path pathToModel = resolvePathToModel(id); log.info("pathToModel: " + pathToModel.toAbsolutePath().toString()); if (pathToModel.toFile().exists()) { mc = this.getModelContent(pathToModel); } return mc; }
From source file:org.tinymediamanager.core.tvshow.tasks.TvShowUpdateDatasourceTask2.java
/** * simple NIO File.listFiles() replacement<br> * returns all files & folders in specified dir (NOT recursive) * //from w w w . j ava 2 s . c o m * @param directory * the folder to list the items for * @return list of files&folders */ public static List<Path> listFilesAndDirs(Path directory) { List<Path> fileNames = new ArrayList<>(); try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directory)) { for (Path path : directoryStream) { String fn = path.getFileName().toString().toUpperCase(Locale.ROOT); if (!skipFolders.contains(fn) && !fn.matches(skipRegex) && !TvShowModuleManager.SETTINGS .getTvShowSkipFolders().contains(path.toFile().getAbsolutePath())) { fileNames.add(path.toAbsolutePath()); } else { LOGGER.debug("Skipping: " + path); } } } catch (IOException ex) { } return fileNames; }
From source file:org.sakuli.starter.SahiConnectorTest.java
@Test public void testReconnectOK() throws Throwable { Path pathMock = mock(Path.class); when(sakuliProperties.getJsLibFolder()).thenReturn(pathMock); when(pathMock.toAbsolutePath()).thenReturn(pathMock); when(pathMock.toString()).thenReturn("/sakuli/src/main/include"); testling.countConnections = 3;/*from w w w. ja va2 s . co m*/ when(sahiProxyProperties.getMaxConnectTries()).thenReturn(3); testling.reconnect(new Exception("Test")); verify(testling).startSahiTestSuite(); }
From source file:org.sakuli.starter.SahiConnectorTest.java
@Test(expectedExceptions = InterruptedException.class) public void testReconnectFAILURE() throws Throwable { Path pathMock = mock(Path.class); when(sakuliProperties.getJsLibFolder()).thenReturn(pathMock); when(pathMock.toAbsolutePath()).thenReturn(pathMock); when(pathMock.toString()).thenReturn("/sakuli/src/main/include"); testling.countConnections = 4;/*www . j a v a 2 s .c o m*/ when(sahiProxyProperties.getMaxConnectTries()).thenReturn(3); testling.reconnect(new Exception("Test")); verify(testling, never()).startSahiTestSuite(); }
From source file:org.apache.openaz.xacml.rest.XACMLPdpLoader.java
public static synchronized void loadPolicy(Properties properties, StdPDPStatus status, String id, boolean isRoot) throws PAPException { PolicyDef policy = null;// www . j a v a 2 s . c o m String location = null; URI locationURI = null; boolean isFile = false; try { location = properties.getProperty(id + ".file"); if (location == null) { location = properties.getProperty(id + ".url"); if (location != null) { // // Construct the URL // locationURI = URI.create(location); URL url = locationURI.toURL(); URLConnection urlConnection = url.openConnection(); urlConnection.setRequestProperty(XACMLRestProperties.PROP_PDP_HTTP_HEADER_ID, XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_ID)); // // Now construct the output file name // Path outFile = Paths.get(getPDPConfig().toAbsolutePath().toString(), id); // // Copy it to disk // try (FileOutputStream fos = new FileOutputStream(outFile.toFile())) { IOUtils.copy(urlConnection.getInputStream(), fos); } // // Now try to load // isFile = true; try (InputStream fis = Files.newInputStream(outFile)) { policy = DOMPolicyDef.load(fis); } // // Save it // properties.setProperty(id + ".file", outFile.toAbsolutePath().toString()); } } else { isFile = true; locationURI = Paths.get(location).toUri(); try (InputStream is = Files.newInputStream(Paths.get(location))) { policy = DOMPolicyDef.load(is); } } if (policy != null) { status.addLoadedPolicy(new StdPDPPolicy(id, isRoot, locationURI, properties)); logger.info("Loaded policy: " + policy.getIdentifier() + " version: " + policy.getVersion().stringValue()); } else { String error = "Failed to load policy " + location; logger.error(error); status.setStatus(PDPStatus.Status.LOAD_ERRORS); status.addLoadError(error); status.addFailedPolicy(new StdPDPPolicy(id, isRoot)); } } catch (Exception e) { logger.error("Failed to load policy '" + id + "' from location '" + location + "'", e); status.setStatus(PDPStatus.Status.LOAD_ERRORS); status.addFailedPolicy(new StdPDPPolicy(id, isRoot)); // // Is it a file? // if (isFile) { // // Let's remove it // try { logger.error("Corrupted policy file, deleting: " + location); Files.delete(Paths.get(location)); } catch (IOException e1) { logger.error(e1); } } throw new PAPException("Failed to load policy '" + id + "' from location '" + location + "'"); } }