private List<Path> getPathsFromFile(String file, List<Path> filesToCombine) throws IOException { Path filePath = Paths.get(file); File fileLister = filePath.toFile(); BufferedReader br = new BufferedReader(new FileReader(fileLister)); String line; PathMatcher matcher; Finder finder = new Finder(); String parentFolder; Path filePathToCombine; while ((line = br.readLine()) != null) { if (line.isEmpty()) { continue; } parentFolder = ""; filePathToCombine = Paths.get(line); if (filePathToCombine.getParent() != null) { parentFolder = filePathToCombine.getParent().toString(); } matcher = FileSystems.getDefault() .getPathMatcher("glob:" + filePathToCombine.getFileName().toString()); finder.setMatcher(matcher); Files.walkFileTree( Paths.get(fileLister.getAbsoluteFile().getParent() + parentFolder), finder); } filesToCombine.addAll(finder.getMatchPath()); return filesToCombine; }
public boolean shutdown(int port, boolean ssl) { try { String protocol = "http" + (ssl ? "s" : ""); URL url = new URL(protocol, "127.0.0.1", port, "shutdown"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("servicemanager", "shutdown"); conn.connect(); StringBuffer sb = new StringBuffer(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); int n; char[] cbuf = new char[1024]; while ((n = br.read(cbuf, 0, cbuf.length)) != -1) sb.append(cbuf, 0, n); br.close(); String message = sb.toString().replace("<br>", "\n"); if (message.contains("Goodbye")) { cp.appendln("Shutting down the server:"); String[] lines = message.split("\n"); for (String line : lines) { cp.append("..."); cp.appendln(line); } return true; } } catch (Exception ex) { } cp.appendln("Unable to shutdown CTP"); return false; }
private String getFileText(File file) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); StringWriter sw = new StringWriter(); int n; char[] cbuf = new char[1024]; while ((n = br.read(cbuf, 0, cbuf.length)) != -1) sw.write(cbuf, 0, n); br.close(); return sw.toString(); }
private static boolean isAaptPresent() throws Exception { boolean result = true; try { Process proc = Runtime.getRuntime().exec("aapt"); BufferedReader br = new BufferedReader(new InputStreamReader(proc.getErrorStream())); String line = null; while ((line = br.readLine()) != null) {} } catch (Exception ex) { result = false; } return result; }
public static void eachLine(BufferedReader reader, EachLine eachLine) { try (BufferedReader bufferedReader = reader) { String line; int lineNumber = 0; while ((line = bufferedReader.readLine()) != null && eachLine.line(line, lineNumber++)) { // // no op } } catch (Exception ex) { Exceptions.handle(ex); } }
public static List<String> readLines(BufferedReader reader) { List<String> lines = new ArrayList<>(80); try (BufferedReader bufferedReader = reader) { String line; while ((line = bufferedReader.readLine()) != null) { lines.add(line); } } catch (Exception ex) { return Exceptions.handle(List.class, ex); } return lines; }
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); } } } }