Class ArchiveManager

java.lang.Object
org.jrd.backend.data.ArchiveManager

public class ArchiveManager extends Object
  • Field Details

  • Constructor Details

    • ArchiveManager

      public ArchiveManager()
  • Method Details

    • getInstance

      public static ArchiveManager getInstance()
    • isClassInFile

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

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

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

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

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

      private File recursiveUnpack(File toUnpack) throws IOException
      Recursively unpacks all required archives
      Parameters:
      toUnpack - Archive to be unpacked
      Returns:
      File pointer to last archive
      Throws:
      IOException - if an I/O error occurs during unpacking
    • newFile

      public File newFile(File destinationDir, ZipEntry zipEntry) throws IOException
      ZipSlip guard
      Parameters:
      destinationDir - Destination directory
      zipEntry - Zip entry
      Returns:
      File object pointing to "destinationDir/zipEntry"
      Throws:
      IOException - cannot happen
    • pack

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

      public void recursiveZip(File f2zip, String fName, ZipOutputStream zOut) throws 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:
      IOException - if an I/O error occurs when writing to the output stream
    • delete

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

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