Module notzed.dez
Package au.notzed.dez

Interface ByteDeltaEncoder

  • All Known Implementing Classes:
    DEZEncoder, PrintEncoder

    public interface ByteDeltaEncoder
    The interface for encoding a delta.

    A delta encoder will implement a specific file/transfer format.

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void add​(byte[] data, int off, int len)
      Appends an add command.
      void copy​(int addr, int len)
      Appends a copy command.
      void init​(int sourceSize, int targetSize)
      Initialises creating a new patch.
      void run​(byte b, int len)
      Appends a byte-run.
      static byte[] toDiff​(ByteMatcher matcher, ByteDeltaEncoder encoder)
      Calculates the delta a matcher and writes it to an encoder.
      byte[] toPatch​(int crc)
      Retrieves the patch.
    • Method Detail

      • init

        void init​(int sourceSize,
                  int targetSize)
        Initialises creating a new patch.

        Source is the data which will be common to both the encoder and decoder, target is only known by the encoder.

        Parameters:
        sourceSize - Size of source data.
        targetSize - Size of target data.
      • copy

        void copy​(int addr,
                  int len)
        Appends a copy command.
        Parameters:
        addr - Address of data.
        len - Length of data.
      • add

        void add​(byte[] data,
                 int off,
                 int len)
        Appends an add command.
        Parameters:
        data - Buffer containing bytes to add.
        off - Offset of addition.
        len - Length of addition.
      • run

        void run​(byte b,
                 int len)
        Appends a byte-run.
        Parameters:
        b - Byte to run.
        len - Number of times to repeat byte.
      • toPatch

        byte[] toPatch​(int crc)
        Retrieves the patch.
        Parameters:
        crc - CRC32 of target data.
        Returns:
        The encoded patch bytes.
      • toDiff

        static byte[] toDiff​(ByteMatcher matcher,
                             ByteDeltaEncoder encoder)
        Calculates the delta a matcher and writes it to an encoder.

        This repeatedly calls the matcher to find common runs of data and passes them to the encoder. It calculates the CRC32 of the output data and then returns the patch.

        Parameters:
        matcher - An initialised ByteMatcher used to calculate runs of matching data.
        encoder - An initialised ByteDeltaEncoder used to encode the runs.
        Returns:
        The encoded patch bytes.