Class ByteWindow

  • Direct Known Subclasses:
    ByteArrayWindow, ByteBufferWindow

    abstract class ByteWindow
    extends java.lang.Object
    A window of data currently stored within a cache.

    All bytes in the window can be assumed to be "immediately available", that is they are very likely already in memory, unless the operating system's memory is very low and has paged part of this process out to disk. Therefore copying bytes from a window is very inexpensive.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected long end  
      protected PackFile pack  
      protected long start  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ByteWindow​(PackFile p, long s, int n)
      Constructor for ByteWindow.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) boolean contains​(PackFile neededFile, long neededPos)  
      protected abstract int copy​(int pos, byte[] dstbuf, int dstoff, int cnt)
      Copy bytes from the window to a caller supplied buffer.
      (package private) int copy​(long pos, byte[] dstbuf, int dstoff, int cnt)
      Copy bytes from the window to a caller supplied buffer.
      protected abstract int setInput​(int pos, java.util.zip.Inflater inf)
      Set the input
      (package private) int setInput​(long pos, java.util.zip.Inflater inf)  
      (package private) int size()  
      (package private) abstract void write​(PackOutputStream out, long pos, int cnt)  
      • Methods inherited from class java.lang.Object

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

      • start

        protected final long start
      • end

        protected final long end
    • Constructor Detail

      • ByteWindow

        protected ByteWindow​(PackFile p,
                             long s,
                             int n)
        Constructor for ByteWindow.
        Parameters:
        p - a PackFile.
        s - where the byte window starts in the pack file
        n - size of the byte window
    • Method Detail

      • size

        final int size()
      • contains

        final boolean contains​(PackFile neededFile,
                               long neededPos)
      • copy

        final int copy​(long pos,
                       byte[] dstbuf,
                       int dstoff,
                       int cnt)
        Copy bytes from the window to a caller supplied buffer.
        Parameters:
        pos - offset within the file to start copying from.
        dstbuf - destination buffer to copy into.
        dstoff - offset within dstbuf to start copying into.
        cnt - number of bytes to copy. This value may exceed the number of bytes remaining in the window starting at offset pos.
        Returns:
        number of bytes actually copied; this may be less than cnt if cnt exceeded the number of bytes available.
      • copy

        protected abstract int copy​(int pos,
                                    byte[] dstbuf,
                                    int dstoff,
                                    int cnt)
        Copy bytes from the window to a caller supplied buffer.
        Parameters:
        pos - offset within the window to start copying from.
        dstbuf - destination buffer to copy into.
        dstoff - offset within dstbuf to start copying into.
        cnt - number of bytes to copy. This value may exceed the number of bytes remaining in the window starting at offset pos.
        Returns:
        number of bytes actually copied; this may be less than cnt if cnt exceeded the number of bytes available.
      • write

        abstract void write​(PackOutputStream out,
                            long pos,
                            int cnt)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • setInput

        final int setInput​(long pos,
                           java.util.zip.Inflater inf)
                    throws java.util.zip.DataFormatException
        Throws:
        java.util.zip.DataFormatException
      • setInput

        protected abstract int setInput​(int pos,
                                        java.util.zip.Inflater inf)
                                 throws java.util.zip.DataFormatException
        Set the input
        Parameters:
        pos - position
        inf - an Inflater object.
        Returns:
        size of the byte window
        Throws:
        java.util.zip.DataFormatException - if any.