Package org.restlet.data
Class Range
- java.lang.Object
-
- org.restlet.data.Range
-
public class Range extends java.lang.Object
Describes a range of bytes.- Author:
- Jerome Louvel
-
-
Field Summary
Fields Modifier and Type Field Description static long
INDEX_FIRST
Index for the first byte (or range unit) of an entity.static long
INDEX_LAST
Index for the last byte (or range unit) of an entity.static java.lang.String
RANGE_BYTES_UNIT
static long
SIZE_MAX
Maximum size available from the index.
-
Constructor Summary
Constructors Constructor Description Range()
Default constructor defining a range starting on the first byte and with a maximum size, i.e.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, java.lang.String unitName)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object object)
long
getIndex()
Returns the index from which to start the range.long
getInstanceSize()
Returns the total size of the instance in number of bytes (or range unit).long
getSize()
Returns the size of the range in number of bytes.java.lang.String
getUnitName()
Returns the name of the range unit.int
hashCode()
static boolean
isBytesRange(Range range)
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(java.lang.String unitName)
Sets the name of the range unit.
-
-
-
Field Detail
-
INDEX_FIRST
public static final long INDEX_FIRST
Index for the first byte (or range unit) of an entity.- See Also:
- Constant Field Values
-
INDEX_LAST
public static final long INDEX_LAST
Index for the last byte (or range unit) of an entity.- See Also:
- Constant Field Values
-
RANGE_BYTES_UNIT
public static final java.lang.String RANGE_BYTES_UNIT
- See Also:
- Constant Field Values
-
SIZE_MAX
public static final long SIZE_MAX
Maximum size available from the index.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 rangesize
- Size of the range in number of bytes.
-
Range
public Range(long index, long size, long instanceSize, java.lang.String unitName)
Constructor. Sets the name of the range unit as "bytes" by default.- Parameters:
index
- Index from which to start the rangesize
- Size of the range in number of bytes.instanceSize
- Size of the instance in number of bytes.unitName
- Unit of the range.
-
-
Method Detail
-
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(java.lang.Object object)
- Overrides:
equals
in classjava.lang.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 isINDEX_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 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 java.lang.String getUnitName()
Returns the name of the range unit.- Returns:
- The name of the range unit.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.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 isINDEX_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(java.lang.String unitName)
Sets the name of the range unit.- Parameters:
unitName
- The name of the range unit.
-
-