Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.92 KB | None | 0 0
  1. //
  2. // Source code recreated from a .class file by IntelliJ IDEA
  3. // (powered by Fernflower decompiler)
  4. //
  5.  
  6. package javaapplication1;
  7.  
  8. import java.io.File;
  9. import java.io.FileInputStream;
  10. import java.io.FileNotFoundException;
  11. import java.io.FileOutputStream;
  12. import java.io.IOException;
  13. import java.net.URLDecoder;
  14. import java.util.ArrayList;
  15. import java.util.HashMap;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import java.util.Map.Entry;
  19. import java.util.zip.ZipEntry;
  20. import java.util.zip.ZipOutputStream;
  21. import javaapplication1.JavaApplication1;
  22.  
  23. public class Body {
  24.     private String targetDir = "";
  25.     private String outputDir = "output\\";
  26.     private String selfName;
  27.  
  28.     Body() {
  29.         String path = JavaApplication1.class.getProtectionDomain().getCodeSource().getLocation().getPath();
  30.  
  31.         try {
  32.             File ex = new File(URLDecoder.decode(path, "UTF-8"));
  33.             this.targetDir = ex.getParent();
  34.             this.selfName = ex.getName();
  35.             this.outputDir = this.targetDir + "\\" + this.outputDir;
  36.         } catch (Exception var3) {
  37.             System.out.println("Can not determine app path");
  38.         }
  39.     }
  40.  
  41.     public void run() {
  42.         try {
  43.             HashMap ex = this.getFilesList();
  44.             this.mkDir();
  45.             Iterator var2 = ex.entrySet().iterator();
  46.  
  47.             while(var2.hasNext()) {
  48.                 Entry entry = (Entry)var2.next();
  49.                 String arcName = (String)entry.getKey();
  50.                 List files = (List)entry.getValue();
  51.                 FileOutputStream fos = new FileOutputStream(this.outputDir + arcName + ".zip");
  52.                 ZipOutputStream zos = new ZipOutputStream(fos);
  53.  
  54.                 for(int i = 0; i < files.size(); ++i) {
  55.                     this.putFilesToZip((File)files.get(i), zos);
  56.                 }
  57.  
  58.                 zos.close();
  59.                 fos.close();
  60.             }
  61.  
  62.         } catch (Exception var9) {
  63.             System.out.println(var9.toString());
  64.         }
  65.     }
  66.  
  67.     private void mkDir() throws Exception {
  68.         File outDir = new File(this.outputDir);
  69.         if(!outDir.exists()) {
  70.             System.out.println("creating directory: " + this.outputDir);
  71.  
  72.             try {
  73.                 outDir.mkdir();
  74.             } catch (SecurityException var3) {
  75.                 throw new Exception("Can\'t create: " + this.outputDir);
  76.             }
  77.         }
  78.  
  79.     }
  80.  
  81.     private void putFilesToZip(File file, ZipOutputStream zos) throws FileNotFoundException, IOException {
  82.         FileInputStream fis = new FileInputStream(file);
  83.         ZipEntry zipEntry = new ZipEntry(file.getName());
  84.         zos.putNextEntry(zipEntry);
  85.         byte[] bytes = new byte[1024];
  86.  
  87.         int length;
  88.         while((length = fis.read(bytes)) >= 0) {
  89.             zos.write(bytes, 0, length);
  90.         }
  91.  
  92.         zos.closeEntry();
  93.         fis.close();
  94.     }
  95.  
  96.     private HashMap getFilesList() throws Exception {
  97.         File folder = new File(this.targetDir);
  98.         if(folder.exists()) {
  99.             File[] listOfFiles = folder.listFiles();
  100.             HashMap groups = new HashMap();
  101.  
  102.             for(int i = 0; i < listOfFiles.length; ++i) {
  103.                 File file = listOfFiles[i];
  104.                 if(file.isFile() && !file.getName().equals(this.selfName)) {
  105.                     String fName = file.getName().replaceFirst("[.][^.]+$", "");
  106.                     ArrayList arr = new ArrayList();
  107.                     if(groups.containsKey(fName)) {
  108.                         List var8 = (List)groups.get(fName);
  109.                         var8.add(file);
  110.                         groups.put(fName, var8);
  111.                     } else {
  112.                         arr.add(file);
  113.                         groups.put(fName, arr);
  114.                     }
  115.                 }
  116.             }
  117.  
  118.             return groups;
  119.         } else {
  120.             throw new Exception("Invalid path");
  121.         }
  122.     }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement