- All Implemented Interfaces:
Runnable
public class ChopJob extends Job
Job
to convert a file into one or more chopped (*.chp + *.cXX) files.
The conversion is done in steps, which may be skipped if the required configuration is null
:
- Compress (if
compressConfig
is notnull
) - Crypt (if
cryptConfig
is notnull
) - Split (if
splitConfig
is notnull
) - *.chp file creation
- See Also:
StitchJob
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields Modifier and Type Field Description private static int
BUFFER_SIZE
The size in bytes of theBufferedInputStream
wrapping theFileInputStream
created whenrun()
is called to read the data from the file to be chopped.private ICompressConfig
compressConfig
TheIConfig
for the Compress step.private ICryptConfig
cryptConfig
TheIConfig
for the Crypt step.private File
fileToChop
The file to chop.private ISplitConfig
splitConfig
TheIConfig
for the Split step. -
Constructor Summary
Constructors Constructor Description ChopJob(File fileToChop, ICompressConfig compressConfig, ICryptConfig cryptConfig, ISplitConfig splitConfig)
Create a new ChopJob (without progress updates support).ChopJob(File fileToChop, ICompressConfig compressConfig, ICryptConfig cryptConfig, ISplitConfig splitConfig, Runnable onProgressChange)
Create a new ChopJob (with progress updates support). -
Method Summary
Modifier and Type Method Description protected void
createChpFile(OutputStream outputStream)
Generate the *.chp file for this job by calling theICleaverOutputStream.toElement(Document)
method of the passedOutputStream
and by writing the results on a file with aTransformer
.private OutputStream
createCompressOutputStream(OutputStream sourceOutputStream)
Create aOutputStream
based on thecompressConfig
of this ChopJob.private OutputStream
createCryptOutputStream(OutputStream sourceOutputStream)
Create aOutputStream
based on thecryptConfig
of this ChopJob.private OutputStream
createSplitOutputStream()
Create aOutputStream
based on thesplitConfig
of this ChopJob.String
getFileString()
String
getOperationsString()
String
getTypeString()
void
run()
Methods inherited from class eu.steffo.cleaver.logic.job.Job
getProgress, getProgressString, setProgress
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, toString, yield
-
Field Details
-
fileToChop
The file to chop. -
cryptConfig
TheIConfig
for the Crypt step. -
compressConfig
TheIConfig
for the Compress step. -
splitConfig
TheIConfig
for the Split step. -
BUFFER_SIZE
private static final int BUFFER_SIZEThe size in bytes of theBufferedInputStream
wrapping theFileInputStream
created whenrun()
is called to read the data from the file to be chopped. The same value is used for a temporary array in therun()
method where bytes are stored between being read from the input file and being written through aICleaverOutputStream
; after that amount of bytes are written,Job.getProgress()
is called, updating theProgress
of this Job.- See Also:
- Constant Field Values
-
-
Constructor Details
-
ChopJob
public ChopJob(File fileToChop, ICompressConfig compressConfig, ICryptConfig cryptConfig, ISplitConfig splitConfig, Runnable onProgressChange)Create a new ChopJob (with progress updates support).- Parameters:
fileToChop
- The file to chop.compressConfig
- TheIConfig
for the Compress step.cryptConfig
- TheIConfig
for the Crypt step.splitConfig
- TheIConfig
for the Split step.onProgressChange
- ARunnable
that will be invoked on the GUIThread
(withSwingUtilities.invokeLater(Runnable)
) every timeJob.setProgress(Progress)
is called.- See Also:
Job(Runnable)
-
ChopJob
public ChopJob(File fileToChop, ICompressConfig compressConfig, ICryptConfig cryptConfig, ISplitConfig splitConfig)Create a new ChopJob (without progress updates support).- Parameters:
fileToChop
- The file to chop.compressConfig
- TheIConfig
for the Compress step.cryptConfig
- TheIConfig
for the Crypt step.splitConfig
- TheIConfig
for the Split step.- See Also:
ChopJob(File, ICompressConfig, ICryptConfig, ISplitConfig, Runnable)
,Job()
-
-
Method Details
-
getTypeString
- Specified by:
getTypeString
in classJob
- Returns:
- The
String
that should be displayed in the Type column of theJobs Table
.
-
getFileString
- Specified by:
getFileString
in classJob
- Returns:
- The
String
that should be displayed in the File column of theJobs Table
.
-
getOperationsString
- Specified by:
getOperationsString
in classJob
- Returns:
- The
String
that should be displayed in the Operations column of theJobs Table
.
-
createSplitOutputStream
Create aOutputStream
based on thesplitConfig
of this ChopJob. TheOutputStream
will be the sink of the stream chain created inrun()
.- Returns:
- The created
OutputStream
. - Throws:
FileNotFoundException
- If one or more files cannot be created (for example, a directory with the same name is present).- See Also:
CleaverSplitFileOutputStream
,CleaverForkFileOutputStream
,CleaverSimpleFileOutputStream
-
createCompressOutputStream
Create aOutputStream
based on thecompressConfig
of this ChopJob. The createdOutputStream
will wrap theOutputStream
passed as parameter, creating a chain of streams.- Parameters:
sourceOutputStream
- TheOutputStream
that should be wrapped.- Returns:
- The created
OutputStream
, wrapping the one that was passed as parameter. - See Also:
CleaverDeflateOutputStream
-
createCryptOutputStream
Create aOutputStream
based on thecryptConfig
of this ChopJob. The createdOutputStream
will wrap theOutputStream
passed as parameter, creating a chain of streams.- Parameters:
sourceOutputStream
- TheOutputStream
that should be wrapped.- Returns:
- The created
OutputStream
, wrapping the one that was passed as parameter. - See Also:
CleaverCryptOutputStream
-
createChpFile
Generate the *.chp file for this job by calling the
ICleaverOutputStream.toElement(Document)
method of the passedOutputStream
and by writing the results on a file with aTransformer
.*.chp files are special XML files that contain information about the stream chain used to produce the *.cXX files.
Every *.chp file has a <Cleaver> element as root containing all the information required to reconstruct the original file.
Every element below the root represents either a
FilterOutputStream
that wraps the stream represented by its child, or, if the child node is <OriginalFile>, aOutputStream
reading from theFile
having thetext content
of the <OriginalFile> element as name.Possible tags representing
FilterOutputStreams
are:- <Crypt>, representing a
CleaverCryptOutputStream
; - <Deflate>, representing a
CleaverDeflateOutputStream
.
Possible tags representing
simple OutputStreams
are:- <Simple>, representing a
CleaverSimpleFileOutputStream
; - <Split>, representing a
CleaverSplitFileOutputStream
; - <Fork>, representing a
CleaverForkFileOutputStream
.
Elements may include attributes that useful or required to reconstruct the original file: for example, the <Crypt> tag includes the value of the salt used to generate the AES key and the value of the initialization vector used to encrypt the stream.
Example
<?xml version="1.0" encoding="UTF-8" standalone="no"?><Cleaver><Crypt algorithm="AES" iteration-count="65535" iv="-10,6,-6,63,-68,-106,-102,-12,59,-58,-123,-76,-16,-29,-75,-67," key-algorithm="PBKDF2WithHmacSHA512" key-length="256" mode-of-operation="CFB8" padding="NoPadding" salt="-60,-84,108,93,100,5,63,44,"><Deflate><Split part-size="16384" parts="4"><OriginalFile>AllThreeExample.png</OriginalFile></Split></Deflate></Crypt></Cleaver>
- Parameters:
outputStream
- TheOutputStream
to create the *.chp file for.- See Also:
ICleaverInputStream.fromElement(Element, File, String)
- <Crypt>, representing a
-
run
public void run()
-