Class Range

java.lang.Object
org.restlet.data.Range

public class Range extends Object
Describes a range of bytes.
Author:
Jerome Louvel
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    Index for the first byte (or range unit) of an entity.
    static final long
    Index for the last byte (or range unit) of an entity.
    static final String
     
    static final long
    Maximum size available from the index.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor defining a range starting on the first byte and with a maximum size, i.e., covering the whole entity.
    Range(long size)
    Constructor defining a range starting on the first byte and with the given size.
    Range(long index, long size)
    Constructor.
    Range(long index, long size, long instanceSize, String unitName)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(Object object)
     
    long
    Returns the index from which to start the range.
    long
    Returns the total size of the instance in number of bytes (or range unit).
    long
    Returns the size of the range in number of bytes.
    Returns the name of the range unit.
    int
     
    static boolean
    Indicates if the unit of the given range is "bytes".
    boolean
    isIncluded(long position, long totalSize)
    Indicates if the given index is included in the range.
    void
    setIndex(long index)
    Sets the index from which to start the range.
    void
    setInstanceSize(long instanceSize)
    Sets the total size of the instance in number of bytes (or range unit).
    void
    setSize(long size)
    Sets the size of the range in number of bytes.
    void
    setUnitName(String unitName)
    Sets the name of the range unit.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INDEX_FIRST

      public static final long INDEX_FIRST
      Index for the first byte (or range unit) of an entity.
      See Also:
    • INDEX_LAST

      public static final long INDEX_LAST
      Index for the last byte (or range unit) of an entity.
      See Also:
    • RANGE_BYTES_UNIT

      public static final String RANGE_BYTES_UNIT
      See Also:
    • SIZE_MAX

      public static final long SIZE_MAX
      Maximum size available from the index.
      See Also:
  • Constructor Details

    • Range

      public Range()
      Default constructor defining a range starting on the first byte and with a maximum size, i.e., covering the whole entity.
    • Range

      public Range(long size)
      Constructor defining a range starting on the first byte and with the given size.
      Parameters:
      size - Size of the range in number of bytes.
    • Range

      public Range(long index, long size)
      Constructor. Sets the name of the range unit as "bytes" by default.
      Parameters:
      index - Index from which to start the range
      size - Size of the range in number of bytes.
    • Range

      public Range(long index, long size, long instanceSize, String unitName)
      Constructor. Sets the name of the range unit as "bytes" by default.
      Parameters:
      index - Index from which to start the range
      size - Size of the range in number of bytes.
      instanceSize - Size of the instance in number of bytes.
      unitName - Unit of the range.
  • Method Details

    • isBytesRange

      public static boolean isBytesRange(Range range)
      Indicates if the unit of the given range is "bytes".
      Parameters:
      range - The range.
      Returns:
      true if the unit of the given range is "bytes".
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • getIndex

      public long getIndex()
      Returns the index from which to start the range. If the index is superior or equal to zero, the index will define the start of the range. If its value is -1L (-1), then it defines the end of the range. The default value is INDEX_FIRST (0), starting at the first byte.
      Returns:
      The index from which to start the range.
    • getInstanceSize

      public long getInstanceSize()
      Returns the total size of the instance in number of bytes (or range unit). In the case of "bytes" range, this attribute is ignored, as the instance size is taken from the entity.
      Returns:
      The total size of the instance.
    • getSize

      public long getSize()
      Returns the size of the range in number of bytes. If the size is the maximum available from the index, then use the -1L constant.
      Returns:
      The size of the range in number of bytes.
    • getUnitName

      public String getUnitName()
      Returns the name of the range unit.
      Returns:
      The name of the range unit.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • isIncluded

      public boolean isIncluded(long position, long totalSize)
      Indicates if the given index is included in the range.
      Parameters:
      position - The position to test.
      totalSize -
      Returns:
      True if the given index is included in the range, false otherwise.
    • setIndex

      public void setIndex(long index)
      Sets the index from which to start the range. If the index is superior or equal to zero, the index will define the start of the range. If its value is -1L (-1), then it defines the end of the range. The default value is INDEX_FIRST (0), starting at the first byte
      Parameters:
      index - The index from which to start the range.
    • setInstanceSize

      public void setInstanceSize(long instanceSize)
      Sets the total size of the instance in number of bytes (or range unit).
      Parameters:
      instanceSize - The total size of the instance.
    • setSize

      public void setSize(long size)
      Sets the size of the range in number of bytes. If the size is the maximum available from the index, then use the -1L constant.
      Parameters:
      size - The size of the range in number of bytes.
    • setUnitName

      public void setUnitName(String unitName)
      Sets the name of the range unit.
      Parameters:
      unitName - The name of the range unit.