@Test public void getFilesGroupByFilenameTest() { try { FileUtils.getFilesGroupByFilename(null); fail("Run 'getFilesGroupByFilenameTest' failed, expected to occur IOException but not"); } catch (IOException e) { assertEquals("Path is null", e.getMessage()); } try { FileUtils.getFilesGroupByFilename(""); fail("Run 'getFilesGroupByFilenameTest' failed, expected to occur IOException but not"); } catch (IOException e) { assertThat(e.getMessage(), containsString("is not exists")); } }
public static Map<String, byte[]> getFilesGroupByFilename(String pathName) throws IOException { if (pathName == null) { throw new IOException("Path is null"); } if (!new File(pathName).exists()) { throw new IOException("Path " + pathName + " is not exists"); } Map<String, byte[]> filesGroup = new HashMap<>(); File path = new File(pathName); Files.walkFileTree(Paths.get(path.toURI()), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { filesGroup.put(file.toFile().getName(), Files.readAllBytes(file)); return super.visitFile(file, attrs); } }); return filesGroup; }
FileUtils { public static Map<String, byte[]> getFilesGroupByFilename(String pathName) throws IOException { if (pathName == null) { throw new IOException("Path is null"); } if (!new File(pathName).exists()) { throw new IOException("Path " + pathName + " is not exists"); } Map<String, byte[]> filesGroup = new HashMap<>(); File path = new File(pathName); Files.walkFileTree(Paths.get(path.toURI()), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { filesGroup.put(file.toFile().getName(), Files.readAllBytes(file)); return super.visitFile(file, attrs); } }); return filesGroup; } }
FileUtils { public static Map<String, byte[]> getFilesGroupByFilename(String pathName) throws IOException { if (pathName == null) { throw new IOException("Path is null"); } if (!new File(pathName).exists()) { throw new IOException("Path " + pathName + " is not exists"); } Map<String, byte[]> filesGroup = new HashMap<>(); File path = new File(pathName); Files.walkFileTree(Paths.get(path.toURI()), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { filesGroup.put(file.toFile().getName(), Files.readAllBytes(file)); return super.visitFile(file, attrs); } }); return filesGroup; }  }
FileUtils { public static Map<String, byte[]> getFilesGroupByFilename(String pathName) throws IOException { if (pathName == null) { throw new IOException("Path is null"); } if (!new File(pathName).exists()) { throw new IOException("Path " + pathName + " is not exists"); } Map<String, byte[]> filesGroup = new HashMap<>(); File path = new File(pathName); Files.walkFileTree(Paths.get(path.toURI()), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { filesGroup.put(file.toFile().getName(), Files.readAllBytes(file)); return super.visitFile(file, attrs); } }); return filesGroup; }  static void createDirectory(String pathName); static Path createTempDirectory(String pathName); static Map<String, byte[]> getFilesGroupByFilename(String pathName); static void deleteDirectory(String pathName); }
FileUtils { public static Map<String, byte[]> getFilesGroupByFilename(String pathName) throws IOException { if (pathName == null) { throw new IOException("Path is null"); } if (!new File(pathName).exists()) { throw new IOException("Path " + pathName + " is not exists"); } Map<String, byte[]> filesGroup = new HashMap<>(); File path = new File(pathName); Files.walkFileTree(Paths.get(path.toURI()), new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { filesGroup.put(file.toFile().getName(), Files.readAllBytes(file)); return super.visitFile(file, attrs); } }); return filesGroup; }  static void createDirectory(String pathName); static Path createTempDirectory(String pathName); static Map<String, byte[]> getFilesGroupByFilename(String pathName); static void deleteDirectory(String pathName);  }