Class BinaryDeltaInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class BinaryDeltaInputStream
    extends java.io.InputStream
    An InputStream that applies a binary delta to a base on the fly.

    Delta application to a base needs random access to the base data. The delta is expressed as a sequence of copy and insert instructions. A copy instruction has the form "COPY fromOffset length" and says "copy length bytes from the base, starting at offset fromOffset, to the result". An insert instruction has the form "INSERT length" followed by length bytes and says "copy the next length bytes from the delta to the result".

    These instructions are generated using a content-defined chunking algorithm (currently C git uses the standard Rabin variant; but there are others that could be used) that identifies equal chunks. It is entirely possible that a later copy instruction has a fromOffset that is before the fromOffset of an earlier copy instruction.

    This makes it impossible to stream the base.

    JGit is limited to 2GB maximum size for the base since array indices are signed 32bit values.

    Since:
    5.12
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      long getExpectedResultSize()
      Tells the expected size of the final result.
      private void initialize()  
      boolean isFullyConsumed()
      Tells whether the delta has been fully consumed, and the expected number of bytes for the combined result have been read from this BinaryDeltaInputStream.
      private int next​(java.io.InputStream in)  
      int read()  
      int read​(byte[] b, int off, int len)  
      private int readNext()  
      private long readVarInt​(java.io.InputStream in)  
      • Methods inherited from class java.io.InputStream

        available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • base

        private final byte[] base
      • delta

        private final java.io.InputStream delta
      • resultLength

        private long resultLength
      • toDeliver

        private long toDeliver
      • fromBase

        private int fromBase
      • fromDelta

        private int fromDelta
      • baseOffset

        private int baseOffset
    • Constructor Detail

      • BinaryDeltaInputStream

        public BinaryDeltaInputStream​(byte[] base,
                                      java.io.InputStream delta)
        Creates a new BinaryDeltaInputStream that applies delta to base.
        Parameters:
        base - data to apply the delta to
        delta - InputStream delivering the delta to apply
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • initialize

        private void initialize()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • readNext

        private int readNext()
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • next

        private int next​(java.io.InputStream in)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • readVarInt

        private long readVarInt​(java.io.InputStream in)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getExpectedResultSize

        public long getExpectedResultSize()
                                   throws java.io.IOException
        Tells the expected size of the final result.
        Returns:
        the size
        Throws:
        java.io.IOException - if the size cannot be determined from delta
      • isFullyConsumed

        public boolean isFullyConsumed()
        Tells whether the delta has been fully consumed, and the expected number of bytes for the combined result have been read from this BinaryDeltaInputStream.
        Returns:
        whether delta application was successful
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException