List of usage examples for java.nio.file FileSystems getDefault
public static FileSystem getDefault()
From source file:Util.java
/** * Read a file from disk as a list of String * @param filepath path on disk//from w w w . j a v a 2 s. co m * @return List of String */ public static List<String> readLinesFromFile(String filepath) { try { BufferedReader reader = Files.newBufferedReader(FileSystems.getDefault().getPath("", filepath), Charset.defaultCharset()); List<String> lines = new ArrayList<String>(); String line = null; while ((line = reader.readLine()) != null) lines.add(line); return lines; } catch (IOException ioe) { ioe.printStackTrace(); } return null; }
From source file:com.netflix.spinnaker.halyard.config.config.v1.AtomicFileWriter.java
AtomicFileWriter(String path) throws IOException { this(FileSystems.getDefault().getPath(path)); }
From source file:com.acmutv.ontoqa.tool.io.IOManager.java
/** * Returns an {@link InputStream} from a general resource. * @param resource the resource locator (e.g.: path for local file, http url for remote file). * @return the open {@link InputStream}. * @throws IOException when the {@link InputStream} cannot be opened. *///from w w w .ja v a 2 s. c o m public static InputStream getInputStream(final String resource) throws IOException { if (resource.startsWith("http://") || resource.startsWith("https://")) { final URL url = new URL(resource); return url.openStream(); } else { final Path path = FileSystems.getDefault().getPath(resource).toAbsolutePath(); return Files.newInputStream(path); } }
From source file:eu.uqasar.web.upload.FileUploadUtil.java
static Path getUserProfilePicturesUploadFolder() throws IOException { Path basePath = FileSystems.getDefault().getPath(getUploadFolderBasePath(), "userprofiles"); if (!Files.exists(basePath)) { Files.createDirectories(basePath); }//from www . j a v a 2s . c o m return basePath; }
From source file:org.phoenicis.tools.files.DirectoryWatcher.java
DirectoryWatcher(ExecutorService executorService, Path observedDirectory) { try {//from w ww .jav a 2 s . co m validate(observedDirectory); this.observedDirectory = observedDirectory; this.watcher = FileSystems.getDefault().newWatchService(); observedDirectory.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY); executorService.submit(this::run); } catch (IOException e) { throw new RuntimeException( String.format("Unable to create watcher for %s", observedDirectory.toString())); } }
From source file:opensnap.config.StaticFilesDevConfig.java
@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { try {/*from ww w. j av a 2s . com*/ FileSystem fs = FileSystems.getDefault(); registry.addResourceHandler("/**") .addResourceLocations("file:" + fs.getPath(this.relativePath).toFile().getCanonicalPath() + "/") .setCachePeriod(0); } catch (IOException e) { logger.error("Error while adding static files handler", e); } }
From source file:com.codeasylum.bank.core.Bank.java
public Bank(String configDir) throws IOException { Topology topology;/*from w w w . j a v a 2 s. c o m*/ if ((topology = Topology.read(FileSystems.getDefault().getPath(configDir))) == null) { System.out.println("Go get topology"); } System.out.println(topology); }
From source file:luceneprueba.Index.java
public Index(String path, String indexName) throws IOException { this.path = path; this.indexName = indexName; this.directory = new SimpleFSDirectory(FileSystems.getDefault().getPath(path, indexName)); }
From source file:com.castlemock.web.basis.support.FileRepositorySupport.java
public <T> Collection<T> load(Class<T> entityClass, String directory, String postfix) { final Collection<T> loadedTypes = new ArrayList<T>(); final Path path = FileSystems.getDefault().getPath(directory); if (!Files.exists(path)) { try {// w ww.jav a2 s . c o m LOGGER.debug("Creating the following directory: " + path); Files.createDirectories(path); } catch (IOException e) { LOGGER.error("Unable to create the following directory: " + path, e); throw new IllegalStateException("Unable to create the following folder: " + directory); } } if (!Files.isDirectory(path)) { throw new IllegalStateException("The provided path is not a directory: " + path); } final File folder = new File(directory); try { LOGGER.debug("Start loading files for the following type: " + entityClass.getSimpleName()); for (final File file : folder.listFiles()) { if (file.isFile() && file.getName().endsWith(postfix)) { JAXBContext jaxbContext = JAXBContext.newInstance(entityClass); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); T type = (T) jaxbUnmarshaller.unmarshal(file); loadedTypes.add(type); LOGGER.debug("\tLoaded " + file.getName()); } } } catch (JAXBException e) { LOGGER.error("Unable to parse files for type " + entityClass.getSimpleName(), e); } return loadedTypes; }
From source file:org.dia.kafka.isatools.producer.DirWatcher.java
/** * Creates a WatchService and registers the given directory * * @param dir path to be watched by the service *///from w w w . j ava2 s . com DirWatcher(Path dir) throws IOException { this.watcher = FileSystems.getDefault().newWatchService(); this.keys = new HashMap<WatchKey, Path>(); System.out.format("[%s] Scanning %s\n", ISAToolsKafkaProducer.class.getSimpleName(), dir); registerAll(dir); System.out.format("[%s] Done scanning %s.\n", ISAToolsKafkaProducer.class.getSimpleName(), dir); }