Class ArchiveManager


  • public class ArchiveManager
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ArchiveManager()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean delete()
      Deletes jrd temporary folder
      private boolean deleteRecursive​(java.io.File f)
      Deletes all nested files and directories, so the root can be deleted
      private boolean findClazz​(java.util.zip.ZipInputStream zis, java.lang.String clazz)
      Recursive search through nested jars
      static ArchiveManager getInstance()  
      boolean isClassInFile​(java.lang.String clazz, java.io.File c)
      Finds out whether desired class is contained in c
      boolean needExtract()
      Returns whether extraction is necessary
      java.io.File newFile​(java.io.File destinationDir, java.util.zip.ZipEntry zipEntry)
      ZipSlip guard
      void pack​(java.io.File c)
      Packs unpacked files
      private java.io.File recursiveUnpack​(java.io.File toUnpack)
      Recursively unpacks all required archives
      void recursiveZip​(java.io.File f2zip, java.lang.String fName, java.util.zip.ZipOutputStream zOut)
      Recursively adds file or files inside folder to archive
      static boolean shouldOpen​(java.lang.String n)
      Determines whether this file can be opened with ZipInputStream
      java.io.File unpack​(java.io.File c)
      Unpacks files necessary to access desired class
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ArchiveManager

        public ArchiveManager()
    • Method Detail

      • isClassInFile

        public boolean isClassInFile​(java.lang.String clazz,
                                     java.io.File c)
                              throws java.io.IOException
        Finds out whether desired class is contained in c
        Parameters:
        clazz - Class to search
        Returns:
        Whether class is in this file
        Throws:
        java.io.IOException - Error while reading streams
      • findClazz

        private boolean findClazz​(java.util.zip.ZipInputStream zis,
                                  java.lang.String clazz)
                           throws java.io.IOException
        Recursive search through nested jars
        Parameters:
        zis - ZipInputStream of current jar
        clazz - Class to search
        Returns:
        Whether class is in this file
        Throws:
        java.io.IOException - Error while reading streams
      • shouldOpen

        public static boolean shouldOpen​(java.lang.String n)
                                  throws java.io.IOException
        Determines whether this file can be opened with ZipInputStream
        Parameters:
        n - Name of the file
        Returns:
        Whether file can opened with ZipInputStream
        Throws:
        java.io.IOException
      • needExtract

        public boolean needExtract()
        Returns whether extraction is necessary
        Returns:
        If extraction is necessary
      • unpack

        public java.io.File unpack​(java.io.File c)
                            throws java.io.IOException
        Unpacks files necessary to access desired class
        Returns:
        .jar containing desired class
        Throws:
        java.io.IOException - Error while reading streams
      • recursiveUnpack

        private java.io.File recursiveUnpack​(java.io.File toUnpack)
                                      throws java.io.IOException
        Recursively unpacks all required archives
        Parameters:
        toUnpack - Archive to be unpacked
        Returns:
        File pointer to last archive
        Throws:
        java.io.IOException
      • newFile

        public java.io.File newFile​(java.io.File destinationDir,
                                    java.util.zip.ZipEntry zipEntry)
                             throws java.io.IOException
        ZipSlip guard
        Parameters:
        destinationDir - Destination directory
        zipEntry - Zip entry
        Returns:
        Throws:
        java.io.IOException
      • pack

        public void pack​(java.io.File c)
                  throws java.io.IOException
        Packs unpacked files
        Throws:
        java.io.IOException
      • recursiveZip

        public void recursiveZip​(java.io.File f2zip,
                                 java.lang.String fName,
                                 java.util.zip.ZipOutputStream zOut)
                          throws java.io.IOException
        Recursively adds file or files inside folder to archive
        Parameters:
        f2zip - File/Folder to be archived
        fName - Name of the file
        zOut - Zip output stream used to output zipped bytes
        Throws:
        java.io.IOException
      • delete

        public boolean delete()
        Deletes jrd temporary folder
        Returns:
        whether folder was successfully deleted
      • deleteRecursive

        private boolean deleteRecursive​(java.io.File f)
        Deletes all nested files and directories, so the root can be deleted
        Parameters:
        f - Directory to be deleted
        Returns:
        Whether directory was delted