@Test public void testWithDecode() throws IOException { File testFile = new File(folder.getRoot(), "testFileWithDecode.txt"); FileUtils.writeStringToFile(testFile, B64_FILEDATA, UTF_8); List<Text> output = ShellUtil.scanFile(testFile.getAbsolutePath(), true); assertEquals(List.of(new Text("line1"), new Text("line2")), output); }
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "app is run in same security context as user providing the filename") public static List<Text> scanFile(String filename, boolean decode) throws IOException { String line; List<Text> result = new ArrayList<>(); try (Scanner file = new Scanner(new File(filename), UTF_8)) { while (file.hasNextLine()) { line = file.nextLine(); if (!line.isEmpty()) { result.add(decode ? new Text(Base64.getDecoder().decode(line)) : new Text(line)); } } } return result; }
ShellUtil { @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "app is run in same security context as user providing the filename") public static List<Text> scanFile(String filename, boolean decode) throws IOException { String line; List<Text> result = new ArrayList<>(); try (Scanner file = new Scanner(new File(filename), UTF_8)) { while (file.hasNextLine()) { line = file.nextLine(); if (!line.isEmpty()) { result.add(decode ? new Text(Base64.getDecoder().decode(line)) : new Text(line)); } } } return result; } }
ShellUtil { @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "app is run in same security context as user providing the filename") public static List<Text> scanFile(String filename, boolean decode) throws IOException { String line; List<Text> result = new ArrayList<>(); try (Scanner file = new Scanner(new File(filename), UTF_8)) { while (file.hasNextLine()) { line = file.nextLine(); if (!line.isEmpty()) { result.add(decode ? new Text(Base64.getDecoder().decode(line)) : new Text(line)); } } } return result; }  }
ShellUtil { @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "app is run in same security context as user providing the filename") public static List<Text> scanFile(String filename, boolean decode) throws IOException { String line; List<Text> result = new ArrayList<>(); try (Scanner file = new Scanner(new File(filename), UTF_8)) { while (file.hasNextLine()) { line = file.nextLine(); if (!line.isEmpty()) { result.add(decode ? new Text(Base64.getDecoder().decode(line)) : new Text(line)); } } } return result; }  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "app is run in same security context as user providing the filename") static List<Text> scanFile(String filename, boolean decode); static Map<String,String> parseMapOpt(CommandLine cl, Option opt); }
ShellUtil { @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "app is run in same security context as user providing the filename") public static List<Text> scanFile(String filename, boolean decode) throws IOException { String line; List<Text> result = new ArrayList<>(); try (Scanner file = new Scanner(new File(filename), UTF_8)) { while (file.hasNextLine()) { line = file.nextLine(); if (!line.isEmpty()) { result.add(decode ? new Text(Base64.getDecoder().decode(line)) : new Text(line)); } } } return result; }  @SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "app is run in same security context as user providing the filename") static List<Text> scanFile(String filename, boolean decode); static Map<String,String> parseMapOpt(CommandLine cl, Option opt);  }