Class B2ByteRange


  • public class B2ByteRange
    extends java.lang.Object
    Represents a range of bytes in an HTTP entity. Used both for the Range header and the Content-Range header. In the Range header, we do not support multiple ranges, but do support all three forms of single ranges: bytes=10-20 11 bytes, from index 10 to index 20 bytes=15- All bytes from index 15 to the end of the entity. bytes=-37 The last 37 bytes of the entity. See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.16 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.lang.Long end
      The index of the last byte in the range, inclusive.
      java.lang.Long start
      The index of the first byte in the range, zero based, or null if there is no starting index.
    • Constructor Summary

      Constructors 
      Constructor Description
      B2ByteRange​(java.lang.Long start, java.lang.Long end)
      Initializes a new B2ByteRange.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static B2ByteRange between​(long start, long end)  
      B2ByteRange effectiveRange​(long entitySize)
      Return an equivalent byte range with both start and end set, and with both being valid indexes into the entity.
      boolean equals​(java.lang.Object o)  
      long getNumberOfBytes()
      Returns the number of bytes that the range specifies.
      int hashCode()  
      boolean isSatisfied​(long entitySize)
      Can this range be satisfied with a file of the given length.
      static B2ByteRange parse​(java.lang.String s)
      Parses a byte range that looks like: bytes=100-999 Returns null on error.
      static B2ByteRange startAt​(long start)  
      java.lang.String toString()
      Returns a string like "bytes=200-340"
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • start

        public final java.lang.Long start
        The index of the first byte in the range, zero based, or null if there is no starting index.
      • end

        public final java.lang.Long end
        The index of the last byte in the range, inclusive. The range "bytes=0-0" is a one-byte range that is the first byte in the content. Null if there is no ending index.
    • Constructor Detail

      • B2ByteRange

        public B2ByteRange​(java.lang.Long start,
                           java.lang.Long end)
        Initializes a new B2ByteRange. Remember that "end" is the index of the last byte in the range, inclusive.
    • Method Detail

      • startAt

        public static B2ByteRange startAt​(long start)
      • between

        public static B2ByteRange between​(long start,
                                          long end)
      • parse

        public static B2ByteRange parse​(java.lang.String s)
        Parses a byte range that looks like: bytes=100-999 Returns null on error.
      • isSatisfied

        public boolean isSatisfied​(long entitySize)
        Can this range be satisfied with a file of the given length.
      • effectiveRange

        public B2ByteRange effectiveRange​(long entitySize)
        Return an equivalent byte range with both start and end set, and with both being valid indexes into the entity. Caller is responsible for making sure the range is satisfiable with the given entity size.
      • getNumberOfBytes

        public long getNumberOfBytes()
        Returns the number of bytes that the range specifies.
      • toString

        public java.lang.String toString()
        Returns a string like "bytes=200-340"
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object