Package org.restlet.data
Class Range
java.lang.Object
org.restlet.data.Range
Describes a range of bytes.
- Author:
- Jerome Louvel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longIndex for the first byte (or range unit) of an entity.static final longIndex for the last byte (or range unit) of an entity.static final Stringstatic final longMaximum size available from the index. -
Constructor Summary
ConstructorsConstructorDescriptionRange()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.Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanlonggetIndex()Returns the index from which to start the range.longReturns the total size of the instance in number of bytes (or range unit).longgetSize()Returns the size of the range in number of bytes.Returns the name of the range unit.inthashCode()static booleanisBytesRange(Range range) Indicates if the unit of the given range is "bytes".booleanisIncluded(long position, long totalSize) Indicates if the given index is included in the range.voidsetIndex(long index) Sets the index from which to start the range.voidsetInstanceSize(long instanceSize) Sets the total size of the instance in number of bytes (or range unit).voidsetSize(long size) Sets the size of the range in number of bytes.voidsetUnitName(String unitName) Sets the name of the range unit.
-
Field Details
-
INDEX_FIRST
public static final long INDEX_FIRSTIndex for the first byte (or range unit) of an entity.- See Also:
-
INDEX_LAST
public static final long INDEX_LASTIndex for the last byte (or range unit) of an entity.- See Also:
-
RANGE_BYTES_UNIT
- See Also:
-
SIZE_MAX
public static final long SIZE_MAXMaximum 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 rangesize- Size of the range in number of bytes.
-
Range
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 Details
-
isBytesRange
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
-
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 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
Returns the name of the range unit.- Returns:
- The name of the range unit.
-
hashCode
public int hashCode() -
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
Sets the name of the range unit.- Parameters:
unitName- The name of the range unit.
-