Package org.jrd.backend.data
Class ArchiveManager
- java.lang.Object
-
- org.jrd.backend.data.ArchiveManager
-
public class ArchiveManager extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classArchiveManager.ArchiveManagerHolderprivate static classArchiveManager.ArchivePathManager
-
Field Summary
Fields Modifier and Type Field Description private intcurrentDprivate static java.lang.StringFILE_SEPARATOR(package private) java.lang.StringjrdFolderprivate ArchiveManager.ArchivePathManagerpathManagerprivate static java.lang.StringTMP_DIR
-
Constructor Summary
Constructors Constructor Description ArchiveManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandelete()Deletes jrd temporary folderprivate booleandeleteRecursive(java.io.File f)Deletes all nested files and directories, so the root can be deletedprivate booleanfindClazz(java.util.zip.ZipInputStream zis, java.lang.String clazz)Recursive search through nested jarsstatic ArchiveManagergetInstance()booleanisClassInFile(java.lang.String clazz, java.io.File c)Finds out whether desired class is contained incbooleanneedExtract()Returns whether extraction is necessaryjava.io.FilenewFile(java.io.File destinationDir, java.util.zip.ZipEntry zipEntry)ZipSlip guardvoidpack(java.io.File c)Packs unpacked filesprivate java.io.FilerecursiveUnpack(java.io.File toUnpack)Recursively unpacks all required archivesvoidrecursiveZip(java.io.File f2zip, java.lang.String fName, java.util.zip.ZipOutputStream zOut)Recursively adds file or files inside folder to archivestatic booleanshouldOpen(java.lang.String n)Determines whether this file can be opened with ZipInputStreamjava.io.Fileunpack(java.io.File c)Unpacks files necessary to access desired class
-
-
-
Field Detail
-
TMP_DIR
private static final java.lang.String TMP_DIR
-
FILE_SEPARATOR
private static final java.lang.String FILE_SEPARATOR
-
pathManager
private ArchiveManager.ArchivePathManager pathManager
-
jrdFolder
final java.lang.String jrdFolder
-
currentD
private int currentD
-
-
Method Detail
-
getInstance
public static ArchiveManager getInstance()
-
isClassInFile
public boolean isClassInFile(java.lang.String clazz, java.io.File c) throws java.io.IOExceptionFinds out whether desired class is contained inc- 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.IOExceptionRecursive search through nested jars- Parameters:
zis- ZipInputStream of current jarclazz- 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.IOExceptionDetermines whether this file can be opened with ZipInputStream- Parameters:
n- Name of the file- Returns:
- Whether file can be 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.IOExceptionUnpacks 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.IOExceptionRecursively unpacks all required archives- Parameters:
toUnpack- Archive to be unpacked- Returns:
- File pointer to last archive
- Throws:
java.io.IOException- if an I/O error occurs during unpacking
-
newFile
public java.io.File newFile(java.io.File destinationDir, java.util.zip.ZipEntry zipEntry) throws java.io.IOExceptionZipSlip guard- Parameters:
destinationDir- Destination directoryzipEntry- Zip entry- Returns:
- File object pointing to "destinationDir/zipEntry"
- Throws:
java.io.IOException- cannot happen
-
pack
public void pack(java.io.File c) throws java.io.IOExceptionPacks 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.IOExceptionRecursively 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:
java.io.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(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 deleted
-
-