List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:com.yahoo.labs.samoa.utils.SamzaConfigFactory.java
public List<Map<String, String>> getMapsForTopology(SamzaTopology topology) throws Exception { List<Map<String, String>> maps = new ArrayList<Map<String, String>>(); // File to write serialized objects String filename = topology.getTopologyName() + ".dat"; Path dirPath = FileSystems.getDefault().getPath("dat"); Path filePath = FileSystems.getDefault().getPath(dirPath.toString(), filename); String dstPath = filePath.toString(); String resPath;//from ww w . j av a 2s. com String filesystem; if (this.isLocalMode) { filesystem = SystemsUtils.LOCAL_FS; File dir = dirPath.toFile(); if (!dir.exists()) FileUtils.forceMkdir(dir); } else { filesystem = SystemsUtils.HDFS; } // Correct system name for streams this.setSystemNameForStreams(topology.getStreams()); // Add all PIs to a collection (map) Map<String, Object> piMap = new HashMap<String, Object>(); Set<EntranceProcessingItem> entranceProcessingItems = topology.getEntranceProcessingItems(); Set<IProcessingItem> processingItems = topology.getNonEntranceProcessingItems(); for (EntranceProcessingItem epi : entranceProcessingItems) { SamzaEntranceProcessingItem sepi = (SamzaEntranceProcessingItem) epi; piMap.put(sepi.getName(), sepi); } for (IProcessingItem pi : processingItems) { SamzaProcessingItem spi = (SamzaProcessingItem) pi; piMap.put(spi.getName(), spi); } // Serialize all PIs boolean serialized = false; if (this.isLocalMode) { serialized = SystemsUtils.serializeObjectToLocalFileSystem(piMap, dstPath); resPath = dstPath; } else { resPath = SystemsUtils.serializeObjectToHDFS(piMap, dstPath); serialized = resPath != null; } if (!serialized) { throw new Exception("Fail serialize map of PIs to file"); } // MapConfig for all PIs for (EntranceProcessingItem epi : entranceProcessingItems) { SamzaEntranceProcessingItem sepi = (SamzaEntranceProcessingItem) epi; maps.add(this.getMapForEntrancePI(sepi, resPath, filesystem)); } for (IProcessingItem pi : processingItems) { SamzaProcessingItem spi = (SamzaProcessingItem) pi; maps.add(this.getMapForPI(spi, resPath, filesystem)); } return maps; }
From source file:ste.xtest.net.StubURLConnection.java
/** * Sets the body, content-type (depending on file) and content-length (-1 if * the file does not exist or the file length if the file exists) of the * request. //from w w w. ja va 2s. c om * * @param file - MAY BE NULL * * @return this */ public StubURLConnection file(final String file) { String type = null; Path path = (file == null) ? null : FileSystems.getDefault().getPath(file); if (path != null) { try { type = Files.probeContentType(path); } catch (IOException x) { // // noting to do // } } setContent(path, (type == null) ? "application/octet-stream" : type); return this; }
From source file:com.vmware.photon.controller.common.dcp.helpers.dcp.MultiHostEnvironment.java
/** * Generates a unique storage sandbox path. * @return/*from ww w.j a v a 2s . c om*/ */ protected String generateStorageSandboxPath() { Path sandboxPath = FileSystems.getDefault().getPath(System.getProperty("user.home"), STORAGE_PATH_PREFIX, UUID.randomUUID().toString()); return sandboxPath.toAbsolutePath().toString(); }
From source file:business.services.FileService.java
public HttpEntity<InputStreamResource> downloadAccessLog(String filename, boolean writeContentDispositionHeader) { try {//w w w. j a v a 2 s. c o m FileSystem fileSystem = FileSystems.getDefault(); Path path = fileSystem.getPath(accessLogsPath).normalize(); filename = filename.replace(fileSystem.getSeparator(), "_"); filename = URLEncoder.encode(filename, "utf-8"); Path f = fileSystem.getPath(accessLogsPath, filename).normalize(); // filter path names that point to places outside the logs path. // E.g., to prevent that in cases where clients use '../' in the filename // arbitrary locations are reachable. if (!Files.isSameFile(path, f.getParent())) { // Path f is not in the upload path. Maybe 'name' contains '..'? log.error("Invalid filename: " + filename); throw new FileDownloadError("Invalid file name"); } if (!Files.isReadable(f)) { log.error("File does not exist: " + filename); throw new FileDownloadError("File does not exist"); } InputStream input = new FileInputStream(f.toFile()); InputStreamResource resource = new InputStreamResource(input); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); if (writeContentDispositionHeader) { headers.set("Content-Disposition", "attachment; filename=" + filename.replace(" ", "_")); } HttpEntity<InputStreamResource> response = new HttpEntity<InputStreamResource>(resource, headers); return response; } catch (IOException e) { log.error(e); throw new FileDownloadError(); } }
From source file:org.openecomp.sdc.ci.tests.utils.rest.ImportRestUtils.java
private static String getTestJsonStringOfFile(String folderName, String fileName) throws IOException { // String sourceDir = "src/test/resources/CI/importResourceTests"; Config config = Utils.getConfig();/*from ww w . j ava2s . c o m*/ String sourceDir = config.getImportResourceTestsConfigDir(); java.nio.file.Path filePath = FileSystems.getDefault().getPath(sourceDir + File.separator + folderName, fileName); byte[] fileContent = Files.readAllBytes(filePath); String content = new String(fileContent); return content; }
From source file:edu.vt.vbi.patric.cache.DataLandingGenerator.java
public boolean createCacheFileSpecialtyGenes(String filePath) { boolean isSuccess = false; JSONObject jsonData = new JSONObject(); JSONObject data;// w ww . j a v a2 s .com // from WP // data data = read(baseURL + "/tab/dlp-specialtygenes-data/?req=passphrase"); if (data != null) { jsonData.put("data", data); } // popular genomes data = getPopularGenomesForSpecialtyGene(); if (data != null) { jsonData.put("popularGenomes", data); } // tools data = read(baseURL + "/tab/dlp-specialtygenes-tools/?req=passphrase"); if (data != null) { jsonData.put("tools", data); } // process data = read(baseURL + "/tab/dlp-specialtygenes-process/?req=passphrase"); if (data != null) { jsonData.put("process", data); } // download data = read(baseURL + "/tab/dlp-specialtygenes-download/?req=passphrase"); if (data != null) { jsonData.put("download", data); } // save jsonData to file try (PrintWriter jsonOut = new PrintWriter( Files.newBufferedWriter(FileSystems.getDefault().getPath(filePath), Charset.defaultCharset()));) { jsonData.writeJSONString(jsonOut); isSuccess = true; } catch (IOException e) { LOGGER.error(e.getMessage(), e); } return isSuccess; }
From source file:org.bigbluebutton.api.RecordingService.java
private static List<File> getDirectories(String path) { List<File> files = new ArrayList<File>(); try {//w ww . j a v a 2s .c o m DirectoryStream<Path> stream = Files.newDirectoryStream(FileSystems.getDefault().getPath(path)); Iterator<Path> iter = stream.iterator(); while (iter.hasNext()) { Path next = iter.next(); files.add(next.toFile()); } stream.close(); } catch (IOException e) { e.printStackTrace(); } return files; }
From source file:org.apache.coheigea.bigdata.knox.ranger.KnoxRangerTest.java
private void makeHBaseInvocation(int statusCode, String user, String password) throws IOException { String basedir = System.getProperty("basedir"); if (basedir == null) { basedir = new File(".").getCanonicalPath(); }/*from w ww. j a v a 2 s.co m*/ Path path = FileSystems.getDefault().getPath(basedir, "/src/test/resources/webhbase-table-list.xml"); hbaseServer.expect().method("GET").pathInfo("/").header("Accept", ContentType.XML.toString()).respond() .status(HttpStatus.SC_OK).content(IOUtils.toByteArray(path.toUri())) .contentType(ContentType.XML.toString()); given().log().all().auth().preemptive().basic(user, password).header("X-XSRF-Header", "jksdhfkhdsf") .header("Accept", ContentType.XML.toString()).when() .get("http://localhost:" + gateway.getAddresses()[0].getPort() + "/gateway/cluster/hbase").then() .statusCode(statusCode).log().body(); }
From source file:com.scooter1556.sms.server.service.ScannerService.java
private void scanMediaFolder(MediaFolder folder) { Path path = FileSystems.getDefault().getPath(folder.getPath()); ParseFiles fileParser = new ParseFiles(folder); try {// ww w.j a v a2 s.c o m // Start Scan directory LogService.getInstance().addLogEntry(LogService.Level.INFO, CLASS_NAME, "Scanning media folder " + folder.getPath(), null); Files.walkFileTree(path, fileParser); // Add new media elements in database if (!fileParser.getNewMediaElements().isEmpty()) { mediaDao.createMediaElements(fileParser.getNewMediaElements()); } // Update existing media elements in database if (!fileParser.getUpdatedMediaElements().isEmpty()) { mediaDao.updateMediaElementsByID(fileParser.getUpdatedMediaElements()); } // Extract media streams from parsed media elements List<VideoStream> vStreams = new ArrayList<>(); List<AudioStream> aStreams = new ArrayList<>(); List<SubtitleStream> sStreams = new ArrayList<>(); for (MediaElement element : fileParser.getAllMediaElements()) { if (element.getVideoStreams() != null) { vStreams.addAll(element.getVideoStreams()); } if (element.getAudioStreams() != null) { aStreams.addAll(element.getAudioStreams()); } if (element.getSubtitleStreams() != null) { sStreams.addAll(element.getSubtitleStreams()); } } // Add media streams to database mediaDao.createVideoStreams(vStreams); mediaDao.createAudioStreams(aStreams); mediaDao.createSubtitleStreams(sStreams); // Add new playlists if (!fileParser.getNewPlaylists().isEmpty()) { for (Playlist playlist : fileParser.getNewPlaylists()) { mediaDao.createPlaylist(playlist); } } // Update existing playlists if (!fileParser.getUpdatedPlaylists().isEmpty()) { for (Playlist playlist : fileParser.getUpdatedPlaylists()) { mediaDao.updatePlaylistLastScanned(playlist.getID(), fileParser.getScanTime()); } } // Remove files which no longer exist mediaDao.removeDeletedMediaElements(folder.getPath(), fileParser.getScanTime()); mediaDao.removeDeletedPlaylists(folder.getPath(), fileParser.getScanTime()); // Update folder statistics folder.setFolders(fileParser.getFolders()); folder.setFiles(fileParser.getFiles()); folder.setLastScanned(fileParser.getScanTime()); // Determine primary media type in folder if (folder.getType() == null || folder.getType() == MediaFolder.ContentType.UNKNOWN) { int audio = 0, video = 0, playlist; // Get number of playlists playlist = fileParser.getAllPlaylists().size(); // Iterate over media elements to determine number of each type for (MediaElement element : fileParser.getAllMediaElements()) { switch (element.getType()) { case MediaElementType.AUDIO: audio++; break; case MediaElementType.VIDEO: video++; break; } } if (audio == 0 && video == 0 && playlist > 0) { folder.setType(MediaFolder.ContentType.PLAYLIST); } else if (audio > video) { folder.setType(MediaFolder.ContentType.AUDIO); } else if (video > audio) { folder.setType(MediaFolder.ContentType.VIDEO); } } settingsDao.updateMediaFolder(folder); LogService.getInstance().addLogEntry(LogService.Level.INFO, CLASS_NAME, "Finished scanning media folder " + folder.getPath() + " (Items Scanned: " + fileParser.getTotal() + ", Folders: " + fileParser.getFolders() + ", Files: " + fileParser.getFiles() + ", Playlists: " + fileParser.getPlaylists() + ")", null); } catch (IOException ex) { LogService.getInstance().addLogEntry(LogService.Level.ERROR, CLASS_NAME, "Error scanning media folder " + folder.getPath(), ex); } }
From source file:org.openecomp.sdc.ci.tests.utils.rest.ImportRestUtils.java
private static File getTestZipFile(String elementName) throws IOException { Config config = Utils.getConfig();/* w ww . j av a 2 s . c o m*/ String sourceDir = config.getImportResourceTestsConfigDir(); java.nio.file.Path filePath = FileSystems.getDefault().getPath(sourceDir + File.separator + elementName, "normative-types-new-" + elementName + ".zip"); return filePath.toFile(); }