Class MultiChunker

  • Direct Known Subclasses:
    ZipMultiChunker

    public abstract class MultiChunker
    extends java.lang.Object
    A multichunker combines a set of Chunks into a single file. It can be implemented by a simple container or archive format. The multichunker is used by the Deduper to write multichunks, and by other parts of the application to read multichunks and re-assemble files.

    The class supports two modes:

    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.
    • 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:
      • 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 multichunk
        os - 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 class java.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 the init() method. The given type attribute is mapped to fully qualified class name (FQCN) of the form org.syncany.chunk.XMultiChunker, where X is the camel-cased type attribute.
        Parameters:
        type - Type/name of the multichunker (corresponds to its camel case class name)
        Returns:
        a new multichunker