private static String read(String location, URI uri) throws Exception { try { FileSystem fileSystem = FileSystems.getFileSystem(uri); Path fsPath = fileSystem.getPath(location); return read(Files.newBufferedReader(fsPath, DEFAULT_CHARSET)); } catch (ProviderNotFoundException ex) { return read(uri.toURL().openStream()); } }
public static String read(Path path) { try { return read(Files.newBufferedReader(path, DEFAULT_CHARSET)); } catch (IOException ex) { return Exceptions.handle(String.class, ex); } }
private static String readFromFileSchema(URI uri) { Path thePath = uriToPath(uri); try { return read(Files.newBufferedReader(thePath, DEFAULT_CHARSET)); } catch (IOException e) { return Exceptions.handle(Typ.string, e); // } }
public static char[] readCharBuffer(Path path) { try { long bufSize = Files.size(path); return readCharBuffer(Files.newBufferedReader(path, DEFAULT_CHARSET), (int) bufSize); } catch (IOException ex) { return Exceptions.handle(char[].class, ex); } }
private static void readFile() { try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { String line; while ((line = reader.readLine()) != null) { System.out.format("----| %s \n", line); } } catch (IOException e) { e.printStackTrace(); } }
private static void eachLine(String location, URI uri, EachLine eachLine) throws Exception { try { FileSystem fileSystem = FileSystems.getFileSystem(uri); Path fsPath = fileSystem.getPath(location); BufferedReader buf = Files.newBufferedReader(fsPath, DEFAULT_CHARSET); eachLine(buf, eachLine); } catch (ProviderNotFoundException ex) { eachLine(uri.toURL().openStream(), eachLine); } }
public static String readFromClasspath(Class<?> clazz, String location) { List<Path> resources = Classpaths.resources(clazz, location); if (len(resources) > 0) { try { return read(Files.newBufferedReader(resources.get(0), DEFAULT_CHARSET)); } catch (IOException e) { return Exceptions.handle(String.class, "unable to read classpath resource " + location, e); } } else { return null; } }
public static String readFromClasspath(String location) { requireNonNull(location, "location can't be null"); if (!location.startsWith(CLASSPATH_SCHEMA + ":")) { die("Location must starts with " + CLASSPATH_SCHEMA); } Path path = path(location); if (path == null) { return null; } try { return read(Files.newBufferedReader(path, DEFAULT_CHARSET)); } catch (IOException e) { return Exceptions.handle(String.class, "unable to read classpath resource " + location, e); } }
protected void readList() { Path path = Paths.get(fileName); try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { String line; while ((line = reader.readLine()) != null) { String[] data = line.split(","); int id = Integer.parseInt(data[0]); String Member = data[1]; String Exercise = data[2]; String Date = data[3]; double Time = Double.parseDouble(data[4]); String Comments = data[5]; Exercise member = new Exercise(id, Member, Exercise, Date, Time, Comments); myList.add(member); } } catch (IOException ioe) { System.out.println("Read file error with " + ioe.getMessage()); } }
public void parse(Path file) throws IOException { clear(); try (BufferedReader inp = Files.newBufferedReader(file)) { String line; while ((line = inp.readLine()) != null) { if (line.startsWith("Cpu ")) { PerfKey key = new PerfKey(); PerfData data = new PerfData(); // Cpu 0 NSE-AB Init Lock Pgs 19 Mem Pages 4194304 key.cpu = Integer.parseInt(line.substring(4, 6).trim()); data.memPages = Integer.parseInt(line.substring(62).trim()); line = inp.readLine(); // Memory MB 65536 PCBs 12100 Pg Size 16384 Bytes if (line == null || !line.startsWith("Memory MB")) { throw new IOException("Строка должна начинаться с 'Memory MB': " + line); } line = inp.readLine(); // IPUs 4 if (line == null || !line.startsWith("IPUs")) { throw new IOException("Строка должна начинаться с 'IPUs': " + line); } line = inp.readLine(); // Format Version: H07 Data Version: H07 Subsystem Version: 3 if (line == null || !line.startsWith("Format Version:")) { throw new IOException("Строка должна начинаться с 'Format Version:': " + line); } line = inp.readLine(); // Local System \KHAFE1 From 1 Oct 2016, 0:00:01 For 5.1 Minutes if (line == null || !line.startsWith("Local System")) { throw new IOException("Строка должна начинаться с 'Local System:': " + line); } key.system = line.substring(13, 21).trim(); String str = line.substring(28, 49); try { key.date = DATETIME_SDF.parse(str); data.duration = parseDuration(line.substring(56).trim()); } catch (ParseException e) { throw new IOException( "Ошибка декодирования строки (Позиция. " + e.getErrorOffset() + "): " + str + ". Строка:" + line, e); } catch (NumberFormatException e) { throw new IOException("Ошибка декодирования строки : " + str + ". Строка:" + line, e); } line = inp.readLine(); // ---------------------------------------------------------------------------- if (line == null || !line.startsWith("---------")) { throw new IOException("Строка должна начинаться с '---------:': " + line); } line = inp.readLine(); // Cpu-Busy-Time 79.99 % Dispatches 115,637 /s if (line == null || !line.startsWith("Cpu-Busy-Time")) { throw new IOException("Строка должна начинаться с 'Cpu-Busy-Time': " + line); } str = line.substring(25, 33).trim(); try { data.cpuBusyTime = DF.parse(str).floatValue(); } catch (ParseException e) { throw new IOException("Ошибка декодирования Cpu-Busy-Time: " + str, e); } line = inp.readLine(); // Cpu-Qtime 13.89 AQL Intr-Busy-Time 14.41 % if (line == null || !line.startsWith("Cpu-Qtime")) { throw new IOException("Строка должна начинаться с 'Cpu-Qtime': " + line); } line = inp.readLine(); // Starting-Free-Mem 3,267,922 # Ending-Free-Mem 3,267,951 # if (line == null || !line.startsWith("Starting-Free-Mem")) { throw new IOException("Строка должна начинаться с 'Starting-Free-Mem': " + line); } str = line.substring(55, 73).trim(); try { data.endingFreeMem = DF.parse(str).intValue(); } catch (ParseException e) { throw new IOException("Ошибка декодирования Ending-Free-Mem: " + str, e); } line = inp.readLine(); // Swaps 1.10 /s Page-Requests 2.19 /s if (line == null || !line.startsWith("Swaps")) { throw new IOException("Строка должна начинаться с 'Swaps': " + line); } line = inp.readLine(); // Disc-IOs 49.79 /s Cache-Hits 946.87 /s if (line == null || !line.startsWith("Disc-IOs")) { throw new IOException("Строка должна начинаться с 'Disc-IOs': " + line); } this.stat.addPerfData(key, data); } } } }