Class BinaryDelta


  • public class BinaryDelta
    extends Object
    Recreate a stream from a base stream and a GIT pack delta.

    This entire class is heavily cribbed from patch-delta.c in the GIT project. The original delta patching code was written by Nicolas Pitre (<nico@cam.org>).

    • Constructor Summary

      Constructors 
      Constructor Description
      BinaryDelta()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] apply​(byte[] base, byte[] delta)
      Apply the changes defined by delta to the data in base, yielding a new array of bytes.
      static byte[] apply​(byte[] base, byte[] delta, byte[] result)
      Apply the changes defined by delta to the data in base, yielding a new array of bytes.
      static String format​(byte[] delta)
      Format this delta as a human readable string.
      static String format​(byte[] delta, boolean includeHeader)
      Format this delta as a human readable string.
      static long getBaseSize​(byte[] delta)
      Length of the base object in the delta stream.
      static long getResultSize​(byte[] delta)
      Length of the resulting object in the delta stream.
    • Constructor Detail

      • BinaryDelta

        public BinaryDelta()
    • Method Detail

      • getBaseSize

        public static long getBaseSize​(byte[] delta)
        Length of the base object in the delta stream.
        Parameters:
        delta - the delta stream, or at least the header of it.
        Returns:
        the base object's size.
      • getResultSize

        public static long getResultSize​(byte[] delta)
        Length of the resulting object in the delta stream.
        Parameters:
        delta - the delta stream, or at least the header of it.
        Returns:
        the resulting object's size.
      • apply

        public static final byte[] apply​(byte[] base,
                                         byte[] delta)
        Apply the changes defined by delta to the data in base, yielding a new array of bytes.
        Parameters:
        base - some byte representing an object of some kind.
        delta - a git pack delta defining the transform from one version to another.
        Returns:
        patched base
      • apply

        public static final byte[] apply​(byte[] base,
                                         byte[] delta,
                                         byte[] result)
        Apply the changes defined by delta to the data in base, yielding a new array of bytes.
        Parameters:
        base - some byte representing an object of some kind.
        delta - a git pack delta defining the transform from one version to another.
        result - array to store the result into. If null the result will be allocated and returned.
        Returns:
        either result, or the result array allocated.
      • format

        public static String format​(byte[] delta)
        Format this delta as a human readable string.
        Parameters:
        delta - the delta instruction sequence to format.
        Returns:
        the formatted delta.
      • format

        public static String format​(byte[] delta,
                                    boolean includeHeader)
        Format this delta as a human readable string.
        Parameters:
        delta - the delta instruction sequence to format.
        includeHeader - true if the header (base size and result size) should be included in the formatting.
        Returns:
        the formatted delta.