FileUtil { public static Path copyFile(Path _source_file, Path _target_dir) throws IOException { final Path to = _target_dir.resolve(_source_file.getFileName()); try (final InputStream is = new FileInputStream(_source_file.toFile()); final OutputStream os = new FileOutputStream(to.toFile())) { final byte[] byte_buffer = new byte[1024]; int len = 0; while ((len = is.read(byte_buffer)) != -1) os.write(byte_buffer, 0, len); } return to; }  static String getFileExtension(File _file); static boolean hasFileExtension(Path _p, String[] _extensions); static String toString(Set<Path> _paths, String _sep); static Path createTmpDir(String _prefix); static boolean isAccessibleFile(String _arg); static boolean isAccessibleFile(Path _arg); static final boolean isAccessibleDirectory(Path _dir); static final boolean isAccessibleDirectory(File _dir); static final boolean isAccessibleDirectory(String _dir); static final void createDirectory(Path _p); static String getFileName(String _file_path); static String getFileName(String _file_path, boolean _keep_ext); static String getCharsetName(); static Charset getCharset(); static Path copyFile(Path _source_file, Path _target_dir); static String readFile(String _p); static String readFile(Path _p); static String readInputStream(InputStream _is, Charset _cs); static byte[] readInputStream(InputStream _is); static final void writeToFile(File _f, String _content); static final Path writeToTmpFile(String _filename, String _suffix, String _content); static final void writeToFile(File _f, byte[] _content); static Set<Path> getPaths(String[] _paths); static Path getPath(String _path, boolean _create); static Path getPath(String _path); static final String getSHA1(File _file); static final String getDigest(File _file, DigestAlgorithm _alg); static String getJarFilePath(Class<?> _clazz); static String getJarFilePath(String _url); static Set<String> getJarFilePathsForResources(ClassLoader _cl, String[] _resources); static Set<String> getJarFilePaths(URLClassLoader _cl); static Boolean isZipped(File _f);  }
@Test public void testCopyFile() { try { final VulasConfiguration cfg = new VulasConfiguration(); final Path tmp_dir = cfg.getTmpDir(); final Path source_file = Paths.get("./src/test/resources/Outer.jar"); final Path target_file = FileUtil.copyFile(source_file, tmp_dir); assertEquals( FileUtil.getDigest(source_file.toFile(), DigestAlgorithm.SHA1), FileUtil.getDigest(target_file.toFile(), DigestAlgorithm.SHA1)); } catch (IOException e) { e.printStackTrace(); assertEquals(true, false); } }