Package org.jrd.backend.data
Class ArchiveManager
java.lang.Object
org.jrd.backend.data.ArchiveManager
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
delete()
Deletes jrd temporary folderprivate boolean
Deletes all nested files and directories, so the root can be deletedprivate boolean
findClazz
(ZipInputStream zis, String clazz) Recursive search through nested jarsstatic ArchiveManager
boolean
isClassInFile
(String clazz, File c) Finds out whether desired class is contained inc
boolean
Returns whether extraction is necessaryZipSlip guardvoid
Packs unpacked filesprivate File
recursiveUnpack
(File toUnpack) Recursively unpacks all required archivesvoid
recursiveZip
(File f2zip, String fName, ZipOutputStream zOut) Recursively adds file or files inside folder to archivestatic boolean
shouldOpen
(String n) Determines whether this file can be opened with ZipInputStreamUnpacks files necessary to access desired class
-
Field Details
-
TMP_DIR
-
FILE_SEPARATOR
-
pathManager
-
jrdFolder
-
currentD
private int currentD
-
-
Constructor Details
-
ArchiveManager
public ArchiveManager()
-
-
Method Details
-
getInstance
-
isClassInFile
Finds out whether desired class is contained inc
- Parameters:
clazz
- Class to search- Returns:
- Whether class is in this file
- Throws:
IOException
- Error while reading streams
-
findClazz
Recursive search through nested jars- Parameters:
zis
- ZipInputStream of current jarclazz
- Class to search- Returns:
- Whether class is in this file
- Throws:
IOException
- Error while reading streams
-
shouldOpen
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
Unpacks files necessary to access desired class- Returns:
- .jar containing desired class
- Throws:
IOException
- Error while reading streams
-
recursiveUnpack
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
ZipSlip guard- Parameters:
destinationDir
- Destination directoryzipEntry
- Zip entry- Returns:
- File object pointing to "destinationDir/zipEntry"
- Throws:
IOException
- cannot happen
-
pack
Packs unpacked files- Throws:
IOException
-
recursiveZip
Recursively adds file or files inside folder to archive- Parameters:
f2zip
- File/Folder to be archivedfName
- Name of the filezOut
- 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
Deletes all nested files and directories, so the root can be deleted- Parameters:
f
- Directory to be deleted- Returns:
- Whether directory was deleted
-