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 class
ArchiveManager.ArchiveManagerHolder
private class
ArchiveManager.ArchivePathManager
-
Field Summary
Fields Modifier and Type Field Description (package private) int
currentD
(package private) java.lang.String
fileSeparator
(package private) ArchiveManager.ArchivePathManager
pathManager
(package private) java.lang.String
tmpdir
-
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 folderprivate boolean
deleteRecursive(java.io.File f)
Deletes all nested files and directories, so the root can be deletedprivate boolean
findClazz(java.util.zip.ZipInputStream zis, java.lang.String clazz)
Recursive search through nested jarsstatic ArchiveManager
getInstance()
boolean
isClassInFile(java.lang.String clazz, java.io.File c)
Finds out whether desired class is contained inc
boolean
needExtract()
Returns whether extraction is necessaryjava.io.File
newFile(java.io.File destinationDir, java.util.zip.ZipEntry zipEntry)
ZipSlip guardvoid
pack(java.io.File c)
Packs unpacked filesprivate java.io.File
recursiveUnpack(java.io.File toUnpack)
Recursively unpacks all required archivesvoid
recursiveZip(java.io.File f2zip, java.lang.String fName, java.util.zip.ZipOutputStream zOut)
Recursively adds file or files inside folder to archivestatic boolean
shouldOpen(java.lang.String n)
Determines whether this file can be opened with ZipInputStreamjava.io.File
unpack(java.io.File c)
Unpacks files necessary to access desired class
-
-
-
Field Detail
-
tmpdir
final java.lang.String tmpdir
-
fileSeparator
final java.lang.String fileSeparator
-
pathManager
ArchiveManager.ArchivePathManager pathManager
-
currentD
int currentD
-
-
Method Detail
-
getInstance
public static ArchiveManager getInstance()
-
isClassInFile
public boolean isClassInFile(java.lang.String clazz, java.io.File c) throws java.io.IOException
Finds 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.IOException
Recursive 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.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 directoryzipEntry
- 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 archivedfName
- Name of the filezOut
- 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
-
-