Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Source code recreated from a .class file by IntelliJ IDEA
- // (powered by Fernflower decompiler)
- //
- package javaapplication1;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.net.URLDecoder;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map.Entry;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipOutputStream;
- import javaapplication1.JavaApplication1;
- public class Body {
- private String targetDir = "";
- private String outputDir = "output\\";
- private String selfName;
- Body() {
- String path = JavaApplication1.class.getProtectionDomain().getCodeSource().getLocation().getPath();
- try {
- File ex = new File(URLDecoder.decode(path, "UTF-8"));
- this.targetDir = ex.getParent();
- this.selfName = ex.getName();
- this.outputDir = this.targetDir + "\\" + this.outputDir;
- } catch (Exception var3) {
- System.out.println("Can not determine app path");
- }
- }
- public void run() {
- try {
- HashMap ex = this.getFilesList();
- this.mkDir();
- Iterator var2 = ex.entrySet().iterator();
- while(var2.hasNext()) {
- Entry entry = (Entry)var2.next();
- String arcName = (String)entry.getKey();
- List files = (List)entry.getValue();
- FileOutputStream fos = new FileOutputStream(this.outputDir + arcName + ".zip");
- ZipOutputStream zos = new ZipOutputStream(fos);
- for(int i = 0; i < files.size(); ++i) {
- this.putFilesToZip((File)files.get(i), zos);
- }
- zos.close();
- fos.close();
- }
- } catch (Exception var9) {
- System.out.println(var9.toString());
- }
- }
- private void mkDir() throws Exception {
- File outDir = new File(this.outputDir);
- if(!outDir.exists()) {
- System.out.println("creating directory: " + this.outputDir);
- try {
- outDir.mkdir();
- } catch (SecurityException var3) {
- throw new Exception("Can\'t create: " + this.outputDir);
- }
- }
- }
- private void putFilesToZip(File file, ZipOutputStream zos) throws FileNotFoundException, IOException {
- FileInputStream fis = new FileInputStream(file);
- ZipEntry zipEntry = new ZipEntry(file.getName());
- zos.putNextEntry(zipEntry);
- byte[] bytes = new byte[1024];
- int length;
- while((length = fis.read(bytes)) >= 0) {
- zos.write(bytes, 0, length);
- }
- zos.closeEntry();
- fis.close();
- }
- private HashMap getFilesList() throws Exception {
- File folder = new File(this.targetDir);
- if(folder.exists()) {
- File[] listOfFiles = folder.listFiles();
- HashMap groups = new HashMap();
- for(int i = 0; i < listOfFiles.length; ++i) {
- File file = listOfFiles[i];
- if(file.isFile() && !file.getName().equals(this.selfName)) {
- String fName = file.getName().replaceFirst("[.][^.]+$", "");
- ArrayList arr = new ArrayList();
- if(groups.containsKey(fName)) {
- List var8 = (List)groups.get(fName);
- var8.add(file);
- groups.put(fName, var8);
- } else {
- arr.add(file);
- groups.put(fName, arr);
- }
- }
- }
- return groups;
- } else {
- throw new Exception("Invalid path");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement