@Test public void getFileSingleLine() { File testFile = new File(LinuxHelperTest.class.getResource("/smaps.txt").getFile()); Assert.assertEquals("4", LinuxHelper.getFileSingleLine(testFile, "MMUPageSize")); }
static String getFileSingleLine(File file, String key) { try (BufferedReader reader = new BufferedReader(new FileReader(file))) { String line; while ((line = reader.readLine()) != null) { if (line.startsWith(key + ": ")) { Matcher matcher = COUNT_PATTERN.matcher(line); if (matcher.find()) return matcher.group(1); } } } catch (IOException ignored) { } return null; }
LinuxHelper { static String getFileSingleLine(File file, String key) { try (BufferedReader reader = new BufferedReader(new FileReader(file))) { String line; while ((line = reader.readLine()) != null) { if (line.startsWith(key + ": ")) { Matcher matcher = COUNT_PATTERN.matcher(line); if (matcher.find()) return matcher.group(1); } } } catch (IOException ignored) { } return null; } }
LinuxHelper { static String getFileSingleLine(File file, String key) { try (BufferedReader reader = new BufferedReader(new FileReader(file))) { String line; while ((line = reader.readLine()) != null) { if (line.startsWith(key + ": ")) { Matcher matcher = COUNT_PATTERN.matcher(line); if (matcher.find()) return matcher.group(1); } } } catch (IOException ignored) { } return null; } protected  LinuxHelper(); }
LinuxHelper { static String getFileSingleLine(File file, String key) { try (BufferedReader reader = new BufferedReader(new FileReader(file))) { String line; while ((line = reader.readLine()) != null) { if (line.startsWith(key + ": ")) { Matcher matcher = COUNT_PATTERN.matcher(line); if (matcher.find()) return matcher.group(1); } } } catch (IOException ignored) { } return null; } protected  LinuxHelper(); static long getPageSize(); static String[] getFileLineSplit(RandomAccessFile raf); static RandomAccessFile openFile(File file); }
LinuxHelper { static String getFileSingleLine(File file, String key) { try (BufferedReader reader = new BufferedReader(new FileReader(file))) { String line; while ((line = reader.readLine()) != null) { if (line.startsWith(key + ": ")) { Matcher matcher = COUNT_PATTERN.matcher(line); if (matcher.find()) return matcher.group(1); } } } catch (IOException ignored) { } return null; } protected  LinuxHelper(); static long getPageSize(); static String[] getFileLineSplit(RandomAccessFile raf); static RandomAccessFile openFile(File file); static final Pattern COUNT_PATTERN; }