Class MultiChunker
- java.lang.Object
-
- org.syncany.chunk.MultiChunker
-
- Direct Known Subclasses:
ZipMultiChunker
public abstract class MultiChunker extends java.lang.Object
A multichunker combines a set ofChunk
s into a single file. It can be implemented by a simple container or archive format. The multichunker is used by theDeduper
to write multichunks, and by other parts of the application to read multichunks and re-assemble files.The class supports two modes:
- When writing a
MultiChunker
, thecreateMultiChunk(MultiChunkId, OutputStream)
must be used. The method emits a new implementation-specificMultiChunk
to which new chunks can be added/written to. - When reading a multichunk from a file or input stream, the
createMultiChunk(InputStream)
orcreateMultiChunk(File)
must be used. The emitted multichunk object can be read from.
Important: Implementations must make sure that when providing a readable multichunk, the individual chunk objects must be randomly accessible. A sequential read (like with TAR, for instance), is not sufficient for the quick processing required in the application.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
minMultiChunkSize
static java.lang.String
PROPERTY_SIZE
Minimal multi chunk size in KB.
-
Constructor Summary
Constructors Constructor Description MultiChunker()
Creates new multichunker without setting the minimum size of a multichunk.MultiChunker(int minMultiChunkSize)
Creates a new multichunker, and sets the minimum size of a multichunk.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract MultiChunk
createMultiChunk(java.io.File file)
Open existing multichunk in read mode using an underlying file.abstract MultiChunk
createMultiChunk(java.io.InputStream is)
Open existing multichunk in read mode using an underlying input stream.abstract MultiChunk
createMultiChunk(MultiChunkEntry.MultiChunkId id, java.io.OutputStream os)
Create a new multichunk in write mode.static MultiChunker
getInstance(java.lang.String type)
Instantiates a multichunker by its name using the default constructor.void
init(java.util.Map<java.lang.String,java.lang.String> settings)
Initializes the multichunker using a settings map.abstract java.lang.String
toString()
Returns a comprehensive string representation of a multichunker
-
-
-
Field Detail
-
PROPERTY_SIZE
public static final java.lang.String PROPERTY_SIZE
Minimal multi chunk size in KB.- See Also:
- Constant Field Values
-
minMultiChunkSize
protected int minMultiChunkSize
-
-
Constructor Detail
-
MultiChunker
public MultiChunker()
Creates new multichunker without setting the minimum size of a multichunk.
-
MultiChunker
public MultiChunker(int minMultiChunkSize)
Creates a new multichunker, and sets the minimum size of a multichunk.Implementations should react on the minimum multichunk size by allowing at least the given amount of KBs to be written to a multichunk, and declaring a multichunk 'full' if this limit is reached.
- Parameters:
minMultiChunkSize
- Minimum multichunk file size in kilo-bytes
-
-
Method Detail
-
init
public void init(java.util.Map<java.lang.String,java.lang.String> settings)
Initializes the multichunker using a settings map.
Required settings are:- key:
PROPERTY_SIZE
, value: integer encoded as String
- key:
-
createMultiChunk
public abstract MultiChunk createMultiChunk(MultiChunkEntry.MultiChunkId id, java.io.OutputStream os) throws java.io.IOException
Create a new multichunk in write mode.Using this method only allows writing to the returned multichunk. The resulting data will be written to the underlying output stream given in the parameter.
- Parameters:
id
- Identifier of the newly created multichunkos
- Underlying output stream to write the new multichunk to- Returns:
- Returns a new multichunk object which can only be used for writing
- Throws:
java.io.IOException
-
createMultiChunk
public abstract MultiChunk createMultiChunk(java.io.InputStream is)
Open existing multichunk in read mode using an underlying input stream.Using this method only allows reading from the returned multichunk. The underlying input stream is opened and can be used to retrieve chunk data.
- Parameters:
is
- InputStream to initialize an existing multichunk for read-operations only- Returns:
- Returns an existing multichunk object that allows read operations only
-
createMultiChunk
public abstract MultiChunk createMultiChunk(java.io.File file) throws java.io.IOException
Open existing multichunk in read mode using an underlying file.Using this method only allows reading from the returned multichunk. The underlying input stream is opened and can be used to retrieve chunk data.
- Parameters:
file
- File to read into a multichunk for read-operations only- Returns:
- Returns an existing multichunk object that allows read operations only
- Throws:
java.io.IOException
-
toString
public abstract java.lang.String toString()
Returns a comprehensive string representation of a multichunker- Overrides:
toString
in classjava.lang.Object
-
getInstance
public static MultiChunker getInstance(java.lang.String type)
Instantiates a multichunker by its name using the default constructor.
After creating a new multichunker, it must be initialized using theinit()
method. The given type attribute is mapped to fully qualified class name (FQCN) of the formorg.syncany.chunk.XMultiChunker
, whereX
is the camel-cased type attribute.- Parameters:
type
- Type/name of the multichunker (corresponds to its camel case class name)- Returns:
- a new multichunker
-
-