Examples of Zip64File


Examples of ch.enterag.utils.zip.Zip64File

   * @param zipName the name the zip file should have. If no zipName is passed, the name of the folder will be used.
   * @param compress true if the file shoukld be compressed, false if not.
   * @return a zip(64) File
   */
  public static File createZip(File srcFolder, File destFolder, String zipName, boolean compress) {
    Zip64File zipFile = null;
   
    if(!srcFolder.isDirectory()) {
      log.severe("[createZip] The File object you have passed is NOT a folder! Nothing has been done, sorry.");
      return null;
    }
   
    if(zipName==null) {
      zipName = srcFolder.getName();
      log.info("[createZip] No zipName specified, using folder name instead: " + zipName);
    }
   
    try {
      File newZip = new File(destFolder, zipName);
      zipFile = new Zip64File(newZip);
      List<String> listOfFiles = listAllFilesAndFolders(srcFolder, new ArrayList<String> ());
      if(listOfFiles.size()==0) {
        log.info("[createZip] Found no files to put in the zip. Created empty Zip file anyway...");
        zipFile.close();
        return new File(zipFile.getDiskFile().getFileName());
      }
      log.info("[createZip] Working on zipFile: " + zipFile.getDiskFile().getFileName());
      log.info("[createZip] Normalizing paths...");
      List<String> normalizedPaths = normalizePaths(srcFolder);
     
      for(int i=0;i<normalizedPaths.size();i++) {
        String currentZipEntryPath = normalizedPaths.get(i);
        FileEntry entry = new FileEntry(currentZipEntryPath);
        File currentFile = new File(listOfFiles.get(i));
       
        writeEntry(zipFile, entry, currentFile, compress);
      }
      log.info("[createZip] All Files written to zip file: " + zipFile.getDiskFile().getFileName());
      zipFile.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return new File(zipFile.getDiskFile().getFileName());
  }
View Full Code Here

Examples of ch.enterag.utils.zip.Zip64File

   */
  @SuppressWarnings("unchecked")
  public static List<File> unzipTo(File zipFile, File destFolder) {
    List<File> extractedFiles = null;
    try {
      Zip64File zip64File = new Zip64File(zipFile);
     
      List<FileEntry> entries = zip64File.getListFileEntries();
      extractedFiles = new ArrayList<File>();
      for (FileEntry fileEntry : entries) {
       
        File currentFile = readEntry(zip64File, fileEntry, destFolder);
        extractedFiles.add(currentFile);
       
      }
      zip64File.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
View Full Code Here

Examples of ch.enterag.utils.zip.Zip64File

   * @return the extracted File.
   */
  public static File getFileFrom(File zip, String targetPathInZipfile, File destFolder) {
    File target = null;
    try {
      Zip64File zip64File = new Zip64File(zip);
      FileEntry targetEntry = getFileEntry(zip64File, targetPathInZipfile);
     
      if(targetEntry!=null) {
        target = readEntry(zip64File, targetEntry, destFolder);
      }
View Full Code Here

Examples of ch.enterag.utils.zip.Zip64File

   * @param toInsert the file to add to the zip
   * @param targetPath the location the file should have in this zip
   * @return the modified zip, containing the file toInsert.
   */
  public static File insertFileInto(File zipFile, File toInsert, String targetPath) {
    Zip64File zip64File = null;
    try {
      boolean compress = false;
     
      zip64File = new Zip64File(zipFile);
     
      FileEntry testEntry = getFileEntry(zip64File, targetPath);
     
      if(testEntry!= null && testEntry.getMethod() == FileEntry.iMETHOD_DEFLATED) {
        compress = true;
      }
     
      processAndCreateFolderEntries(zip64File, parseTargetPath(targetPath, toInsert), compress);
     
      if(testEntry!=null) {
        log.info("[insertFileInto] Entry exists: " + testEntry.getName());
        log.info("[insertFileInto] Will delete this entry before inserting: " + toInsert.getName());
        if(!testEntry.isDirectory()) {
          zip64File.delete(testEntry.getName());
        }
        else {
          log.info("[insertFileInto] Entry is a directory. " +
              "Will delete all files contained in this entry and insert " + toInsert.getName()
              "and all nested files.");
         
          if(!targetPath.contains("/")) {
            targetPath = targetPath + "/";
          }
          deleteFileEntry(zip64File, testEntry);
          log.info("[insertFileInto] Entry successfully deleted.");
        }
       
        log.info("[insertFileInto] Writing new Entry: " + targetPath);
        EntryOutputStream out = null;
        if(!compress) {
          out = zip64File.openEntryOutputStream(targetPath, FileEntry.iMETHOD_STORED, new Date(toInsert.lastModified()));
        }
        else {
          out = zip64File.openEntryOutputStream(targetPath, FileEntry.iMETHOD_DEFLATED, new Date(toInsert.lastModified()));
        }
       
        if(toInsert.isDirectory()) {
          out.flush();
          out.close();
          log.info("[insertFileInto] Finished writing entry: " + targetPath);
         
          List<String> containedPaths = normalizePaths(toInsert);
          List<File> containedFiles = listAllFilesAndFolders(toInsert, new ArrayList<File>());
         
          log.info("[insertFileInto] Added entry is a folder.");
          log.info("[insertFileInto] Adding all nested files: ");
          for(int i=0;i<containedPaths.size();i++) {
            File currentFile = containedFiles.get(i);
            String currentPath = targetPath.replace("/", "") + File.separator + containedPaths.get(i);
            EntryOutputStream loop_out = null;
            if(!compress) {
              loop_out = zip64File.openEntryOutputStream(currentPath, FileEntry.iMETHOD_STORED, new Date(currentFile.lastModified()));
            }
            else {
              loop_out = zip64File.openEntryOutputStream(currentPath, FileEntry.iMETHOD_DEFLATED, new Date(currentFile.lastModified()));
            }
            if(currentFile.isFile()) {
              InputStream loop_in = new FileInputStream(currentFile);
              IOUtils.copyLarge(loop_in, loop_out);
              loop_in.close();
            }
            log.info("[insertFileInto] Added: " + currentPath);
            loop_out.flush();
            loop_out.close();
          }
        }
        else {
          InputStream in = new FileInputStream(toInsert);
          IOUtils.copyLarge(in, out);
          in.close();
          out.flush();
          out.close();
        }
      }
      else {
        EntryOutputStream out = null;
        if(!compress) {
          out = zip64File.openEntryOutputStream(targetPath, FileEntry.iMETHOD_STORED, new Date(toInsert.lastModified()));
        }
        else {
          out = zip64File.openEntryOutputStream(targetPath, FileEntry.iMETHOD_DEFLATED, new Date(toInsert.lastModified()));
        }
       
        if(toInsert.isDirectory()) {
          out.flush();
          out.close();
          log.info("[insertFileInto] Finished writing entry: " + targetPath);
         
          List<String> containedPaths = normalizePaths(toInsert);
          List<File> containedFiles = listAllFilesAndFolders(toInsert, new ArrayList<File>());
         
          log.info("[insertFileInto] Added entry is a folder.");
          log.info("[insertFileInto] Adding all nested files: ");
         
          for(int i=0;i<containedPaths.size();i++) {
            File currentFile = containedFiles.get(i);
            String currentPath = targetPath.replace("/", "") + File.separator + containedPaths.get(i);
            EntryOutputStream loop_out = null;
            if(!compress) {
              loop_out = zip64File.openEntryOutputStream(currentPath, FileEntry.iMETHOD_STORED, new Date(currentFile.lastModified()));
            }
            else {
              loop_out = zip64File.openEntryOutputStream(currentPath, FileEntry.iMETHOD_DEFLATED, new Date(currentFile.lastModified()));
            }
           
            if(currentFile.isFile()) {
              InputStream loop_in = new FileInputStream(currentFile);
              IOUtils.copyLarge(loop_in, loop_out);
              loop_in.close();
            }
            log.info("[insertFileInto] Added: " + currentPath);
            loop_out.flush();
            loop_out.close();
          }
        }
        else {
          InputStream in = new FileInputStream(toInsert);
          IOUtils.copyLarge(in, out);
          in.close();
          out.flush();
          out.close();
        }
      }
      log.info("[insertFileInto] Done! Added " + toInsert.getName() + " to zip.");
      zip64File.close();
     
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return new File(zip64File.getDiskFile().getFileName());
  }
View Full Code Here

Examples of ch.enterag.utils.zip.Zip64File

   * @param zipFile the zip file to remove fileToRemove from.
   * @param fileToRemove the path of the file to remove from zipFile.
   * @return the modified zipFile.
   */
  public static File removeFileFrom(File zipFile, String fileToRemove) {
    Zip64File zip64File = null;
    try {
      zip64File = new Zip64File(zipFile);
     
      FileEntry testEntry = getFileEntry(zip64File, fileToRemove);
     
      if(testEntry==null) {
        log.info("File not found: " + fileToRemove);
        log.info("Nothing has been deleted...");
      }
      else {
        if(testEntry.isDirectory()) {
          deleteFileEntry(zip64File, testEntry);
        }
        else {
          FileEntry deletedEntry = zip64File.delete(fileToRemove);
          log.info("Deleted entry from zip: " + deletedEntry.getName());
          zip64File.close();
        }
      }
     
      zip64File.close();
     
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return new File(zip64File.getDiskFile().getFileName());
  }
View Full Code Here

Examples of ch.enterag.utils.zip.Zip64File

  }
 
  @SuppressWarnings("unchecked")
  public static boolean isZipFile(File file) {
    try {
      Zip64File zip = new Zip64File(file);
      List<FileEntry> entries = zip.getListFileEntries();
      if(entries==null) {
        return false;
      }
      else {
        return true;
View Full Code Here

Examples of ch.enterag.utils.zip.Zip64File

   */
  @SuppressWarnings("unchecked")
  public static List<String> listZipEntries(File zip) {
    List<String> entryList = new ArrayList<String>();
    try {
      Zip64File zip64File = new Zip64File(zip);
      List<FileEntry> entries = zip64File.getListFileEntries();
     
//      zip64File.close();
     
      if(entries.size() > 0) {
        for (FileEntry fileEntry : entries) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.