List of utility methods to do Path File Read nio
String | breadcrumbPath(String urlPrefix, String path, char sep) Convenience method for breadcrumbPath(urlPrefix, path, sep, "", false) . return breadcrumbPath(urlPrefix, path, sep, "", false); |
Path | checkReadableDirectory(final Path directory) check Readable Directory requireNonNull(directory, "No directory provided"); if (!(Files.isReadable(directory) && Files.isDirectory(directory))) { throw new IllegalArgumentException(String.format("Directory is not readable, %s", directory)); return directory; |
BufferedReader | getReaderForFile(final Path file) get Reader For File final String filename = file.getFileName().toString().toLowerCase(); if (filename.endsWith(".gz")) { return new BufferedReader(new InputStreamReader(new GZIPInputStream(Files.newInputStream(file)))); return Files.newBufferedReader(file); |
InputStream | getResourceAsStream(String resourcePath, ClassLoader classLoader, Class> clazz, String resourceDesc, Consumer Get the InputStream input stream to the resource given by the supplied path. if (resourcePath == null) throw new IllegalArgumentException("resourcePath may not be null"); if (resourceDesc == null && logger != null) resourceDesc = resourcePath; InputStream result = null; if (result == null) { try { Path filePath = FileSystems.getDefault().getPath(resourcePath).toAbsolutePath(); ... |
URLClassLoader | getTestClassPathURLClassLoader(ClassLoader parent) get Test Class Path URL Class Loader URL[] urls = Arrays.stream(TEST_CLASS_PATH.split(File.pathSeparator)).map(Paths::get).map(Path::toUri) .map(x -> { try { return x.toURL(); } catch (MalformedURLException ex) { throw new Error( "Test issue. JTREG property" + " 'test.class.path'" + " is not defined correctly", ex); ... |
Properties | load(Path p, PrintStream errorStream, String propertyInfo) load try { FileInputStream fis = new FileInputStream(p.toFile()); return loadAndClose(fis, errorStream, propertyInfo); } catch (FileNotFoundException e) { errorStream.println("Could not find property file " + propertyInfo); return new Properties(); |
String | loadFile(final Path filePath) load File if (!isExists(filePath) || !isFile(filePath)) { throw new IllegalArgumentException("The given path doesn't point to an existing file"); StringBuilder strBuilder = new StringBuilder(); try (Scanner scanner = new Scanner(filePath, StandardCharsets.UTF_8.name())) { while (scanner.hasNextLine()) { strBuilder.append(scanner.nextLine()); strBuilder.append('\n'); ... |
String | loadFile(final Path p) load File Scanner in = null; try { in = new Scanner(p.toFile()); } catch (FileNotFoundException e) { e.printStackTrace(); StringBuffer buffer = new StringBuffer(); while (in.hasNextLine()) { ... |
Properties | loadFile(Path file) load File Properties props = new Properties(); try (InputStream in = Files.newInputStream(file)) { props.load(in); return props; |
File | loadFile(String path) load File if (path == null) { path = "/"; File f = new File(path); if (f.exists()) { return f.getAbsoluteFile(); if (!path.startsWith("/")) { ... |