Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. private static void addToArchiveCompression(SevenZOutputFile out, File file, String dir) throws IOException {
  2. String name = dir + File.separator + file.getName();
  3. if (file.isFile()){
  4. SevenZArchiveEntry entry = out.createArchiveEntry(file, name);
  5. out.putArchiveEntry(entry);
  6.  
  7. FileInputStream in = new FileInputStream(file);
  8. byte[] b = new byte[1024];
  9. int count = 0;
  10. while ((count = in.read(b)) > 0) {
  11. out.write(b, 0, count);
  12. }
  13. out.closeArchiveEntry();
  14.  
  15. } else if (file.isDirectory()) {
  16. File[] children = file.listFiles();
  17. if (children != null){
  18. for (File child : children){
  19. addToArchiveCompression(out, child, name);
  20. }
  21. }
  22. } else {
  23. System.out.println(file.getName() + " is not supported");
  24. }
  25. }
  26.  
  27. byte[] arr = new byte[1024];
  28. SevenZOutputFile file = new SevenZOutputFile(new SeekableInMemoryByteChannel(arr));
  29. addToArchiveCompression(file, ...);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement