List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:com.ccserver.digital.controller.CreditCardApplicationDocumentControllerTest.java
@Test public void modifySubmittedDocumentTest() throws IOException { // Arrange//from w ww . jav a2s . c o m long id = 1l; long docId = 1l; CreditCardApplicationDocumentDTO doc = new CreditCardApplicationDocumentDTO(); doc.setId(docId); File ifile = new File("./src/main/resources/sample"); Path idDocPath = FileSystems.getDefault().getPath(ifile.getAbsolutePath(), "IdDoc.pdf"); byte[] idDocByteArray = Files.readAllBytes(idDocPath); MockMultipartFile idDocMultipartFile = new MockMultipartFile("IdDoc", "IdDoc.pdf", "application/pdf", idDocByteArray); Mockito.when(ccAppService.isSubmittedDocument(id)).thenReturn(true); Mockito.when(mockDocService.documentIsBelongToApp(id, docId)).thenReturn(true); // Act ResponseEntity<?> response = mockDocController.saveAll(new MockMultipartFile[] { idDocMultipartFile }, null, id, docId, request); // Assert Assert.assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode()); Assert.assertEquals(Constants.MODIFYING_SUBMITTED_DOCUMENT, ((ErrorObject) response.getBody()).getId()); }
From source file:com.spotify.helios.servicescommon.PersistentAtomicReference.java
public static <T> PersistentAtomicReference<T> create(final String filename, final TypeReference<T> typeReference, final Supplier<? extends T> initialValue) throws IOException, InterruptedException { return create(FileSystems.getDefault().getPath(filename), typeReference, initialValue); }
From source file:com.netflix.conductor.dao.es5.es.EmbeddedElasticSearch.java
private static void createDataDir(String dataDirLoc) { try {/*from w w w .java 2 s .c o m*/ Path dataDirPath = FileSystems.getDefault().getPath(dataDirLoc); Files.createDirectories(dataDirPath); dataDir = dataDirPath.toFile(); } catch (IOException e) { logger.error("Failed to create data dir"); } }
From source file:nz.co.fortytwo.signalk.server.SignalKServer.java
protected SignalKServer(String configDir) throws Exception { // init config Properties props = System.getProperties(); props.setProperty("java.net.preferIPv4Stack", "true"); System.setProperties(props);//from w w w .j a v a 2s .com Util.getConfig(); // make sure we have all the correct dirs and files now ensureInstall(); logger.info("SignalKServer starting...."); // do we have a USB drive connected? //logger.info("USB drive " + Util.getUSBFile()); // create a new Camel Main so we can easily start Camel Main main = new Main(); //main.setApplicationContextUri("classpath:META-INF/spring/camel-context.xml"); // enable hangup support which mean we detect when the JVM terminates, // and stop Camel graceful main.enableHangupSupport(); // Start activemq broker BrokerService broker = ActiveMqBrokerFactory.newInstance(); broker.start(); //DNS-SD, zeroconf mDNS startMdns(); configureRouteManager(main); // and run, which keeps blocking until we terminate the JVM (or stop // CamelContext) main.start(); WatchService service = FileSystems.getDefault().newWatchService(); Path dir = Paths.get("./conf"); dir.register(service, StandardWatchEventKinds.ENTRY_MODIFY); WatchKey key = null; while (true) { key = service.take(); // Dequeueing events Kind<?> kind = null; for (WatchEvent<?> watchEvent : key.pollEvents()) { // Get the type of the event kind = watchEvent.kind(); logger.debug( "SignalKServer conf/ event:" + watchEvent.kind() + " : " + watchEvent.context().toString()); if (StandardWatchEventKinds.OVERFLOW == kind) { continue; //loop } else if (StandardWatchEventKinds.ENTRY_MODIFY == kind) { // A new Path was created @SuppressWarnings("unchecked") Path newPath = ((WatchEvent<Path>) watchEvent).context(); // Output if (newPath.endsWith("signalk-restart")) { logger.info("SignalKServer conf/signalk-restart changed, stopping.."); main.stop(); main.getCamelContexts().clear(); main.getRouteBuilders().clear(); main.getRouteDefinitions().clear(); // so now shutdown serial reader and server RouteManager routeManager = RouteManagerFactory.getInstance(); routeManager.stopNettyServers(); routeManager.stopSerial(); if (server != null) { server.stop(); server = null; } RouteManagerFactory.clear(); configureRouteManager(main); main.start(); } } } if (!key.reset()) { break; //loop } } stopMdns(); broker.stop(); // write out the signalk model SignalKModelFactory.save(SignalKModelFactory.getInstance()); System.exit(0); }
From source file:org.cryptomator.webdav.jackrabbit.DavLocatorFactoryImpl.java
private String decryptResourcePath(String repositoryPath) { final Path absRepoPath = FileSystems.getDefault().getPath(repositoryPath); if (fsRoot.equals(absRepoPath)) { return null; } else {/*from w ww. ja v a2 s . c o m*/ final Path relativeRepositoryPath = fsRoot.relativize(absRepoPath); final String resourcePath = cryptor.decryptPath(relativeRepositoryPath.toString(), FileSystems.getDefault().getSeparator().charAt(0), '/', this); return resourcePath; } }
From source file:se.trixon.toolbox.photokml.Operation.java
public Operation(OperationListener operationListener, File destination) { mListener = operationListener;//from w w w .ja v a2s.c om mDestinationFile = destination; mBundle = NbBundle.getBundle(PhotoKmlTopComponent.class); mValidSourceString = mOptions.getSourcePaths().length() > 0; String[] sourcePathsAsStrings = mOptions.getSourcePaths().split(SystemUtils.PATH_SEPARATOR); mSourceFiles = new File[sourcePathsAsStrings.length]; for (int i = 0; i < sourcePathsAsStrings.length; i++) { if (SystemUtils.IS_OS_WINDOWS) { sourcePathsAsStrings[i] = StringUtils.trim(sourcePathsAsStrings[i]); } mSourceFiles[i] = new File(sourcePathsAsStrings[i]); } mSourcePattern = FileSystems.getDefault().getPathMatcher("glob:" + mOptions.getSourcePattern()); }
From source file:com.ibm.vicos.client.ClientCommand.java
@CliCommand(value = "putblob", help = "Uploads a blob from source path") public String putBlob( @CliOption(key = { "container" }, mandatory = true, help = "container name") final String container, @CliOption(key = { "src" }, mandatory = true, help = "source file") final String src) { Path fullPath = FileSystems.getDefault().getPath(src); final File file = fullPath.toFile(); try {//from w w w. j ava 2 s. c o m InputStream data = new FileInputStream(file); storage.createObject(container, file.getName(), data, file.length()); } catch (FileNotFoundException e) { return src + " does not exists"; } catch (Exception e) { e.printStackTrace(); return "Error while creating Object"; } return "Successfully uploaded " + container + "/" + file.getName(); }
From source file:com.smartsheet.tin.filters.pkpublish.PKPublishFilterRules.java
/** * Read the specified file into a String. * // w w w .j a v a 2 s . c o m * @param path * @return * @throws IOException */ private String readFile(String path) throws IOException { Path p = FileSystems.getDefault().getPath(path); String contents = new String(Files.readAllBytes(p)); return contents; }
From source file:org.wso2.carbon.inbound.localfile.LocalFileOneTimePolling.java
/** * Before start the watch directory if watchedDir has any files it will start to process. *///from www .j a v a 2s .c o m private void setProcessAndWatch() { Path dir = FileSystems.getDefault().getPath(watchedDir); DirectoryStream<Path> stream = null; try { stream = Files.newDirectoryStream(dir); for (Path path : stream) { processFile(path, contentType); } } catch (IOException e) { log.error("Error while processing the directory." + e.getMessage(), e); } finally { try { if (stream != null) { stream.close(); } } catch (IOException e) { log.error("Error while close the DirectoryStream." + e.getMessage(), e); } } startWatch(); }
From source file:org.ng200.openolympus.services.StorageService.java
public String getTaskDescriptionSourcecode(Task task) throws IOException { final Path source = FileSystems.getDefault().getPath(this.storagePath, "tasks", "descriptions", task.getDescriptionFile(), "source"); return new String(FileAccess.readAllBytes(source), Charset.forName("UTF8")); }