Package com.github.ambry.router
Class ByteRange
- java.lang.Object
-
- com.github.ambry.router.ByteRange
-
public abstract class ByteRange extends java.lang.Object
Represents a byte range for performing ranged get requests.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ByteRange.ByteRangeType
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract boolean
equals(java.lang.Object o)
static ByteRange
fromLastNBytes(long lastNBytes)
Deprecated.Please useByteRanges.fromLastNBytes(long)
instead.static ByteRange
fromOffsetRange(long startOffset, long endOffset)
Deprecated.Please useByteRanges.fromOffsetRange(long, long)
instead.static ByteRange
fromStartOffset(long startOffset)
Deprecated.Please useByteRanges.fromStartOffset(long)
instead.long
getEndOffset()
long
getLastNBytes()
long
getRangeSize()
long
getStartOffset()
abstract ByteRange.ByteRangeType
getType()
abstract int
hashCode()
ByteRange
toResolvedByteRange(long totalSize)
Given the total size of a blob, generate a newByteRange
of typeByteRange.ByteRangeType.OFFSET_RANGE
with defined start and end offsets that are verified to be within the supplied total blob size.abstract ByteRange
toResolvedByteRange(long totalSize, boolean resolveRangeOnEmptyBlob)
Given the total size of a blob, generate a newByteRange
of typeByteRange.ByteRangeType.OFFSET_RANGE
with defined start and end offsets that are verified to be within the supplied total blob size.abstract java.lang.String
toString()
-
-
-
Method Detail
-
fromOffsetRange
@Deprecated public static ByteRange fromOffsetRange(long startOffset, long endOffset)
Deprecated.Please useByteRanges.fromOffsetRange(long, long)
instead.Construct a range from a start offset to an end offset.- Parameters:
startOffset
- the (inclusive) start byte offset.endOffset
- the (inclusive) end byte offset.- Returns:
- A
ByteRange
with the specified offsets. - Throws:
java.lang.IllegalArgumentException
- if the start offset is less than 0, or the end offset is less than the start.
-
fromStartOffset
@Deprecated public static ByteRange fromStartOffset(long startOffset)
Deprecated.Please useByteRanges.fromStartOffset(long)
instead.Construct a range from a start offset to the end of an object.- Parameters:
startOffset
- The (inclusive) start byte offset.- Returns:
- A
ByteRange
with the specified start offset. - Throws:
java.lang.IllegalArgumentException
- if the start offset is less than 0
-
fromLastNBytes
@Deprecated public static ByteRange fromLastNBytes(long lastNBytes)
Deprecated.Please useByteRanges.fromLastNBytes(long)
instead.Construct a range that represents the last N bytes of an object.- Parameters:
lastNBytes
- the number of bytes to read from the end of an object.- Returns:
- A
ByteRange
representing the last N bytes of an objects. - Throws:
java.lang.IllegalArgumentException
- if the number of bytes to read is less than or equal to 0.
-
getStartOffset
public long getStartOffset()
- Returns:
- The inclusive start offset for this range.
- Throws:
java.lang.UnsupportedOperationException
- if the range does not have a defined start offset (i.e. not of the typeByteRange.ByteRangeType.OFFSET_RANGE
orByteRange.ByteRangeType.FROM_START_OFFSET
)
-
getEndOffset
public long getEndOffset()
- Returns:
- The inclusive end offset for this range.
- Throws:
java.lang.UnsupportedOperationException
- if the range does not have a defined start offset (i.e. not of the typeByteRange.ByteRangeType.OFFSET_RANGE
)
-
getLastNBytes
public long getLastNBytes()
- Returns:
- The number of bytes to read from the end of the object.
- Throws:
java.lang.UnsupportedOperationException
- if the range is not of the typeByteRange.ByteRangeType.LAST_N_BYTES
)
-
getRangeSize
public long getRangeSize()
- Returns:
- the size of the range, in bytes.
- Throws:
java.lang.UnsupportedOperationException
- forByteRange.ByteRangeType.FROM_START_OFFSET
type ranges.
-
getType
public abstract ByteRange.ByteRangeType getType()
- Returns:
- the
ByteRange.ByteRangeType
for the range.
-
toResolvedByteRange
public ByteRange toResolvedByteRange(long totalSize)
Given the total size of a blob, generate a newByteRange
of typeByteRange.ByteRangeType.OFFSET_RANGE
with defined start and end offsets that are verified to be within the supplied total blob size.- Parameters:
totalSize
- the total size of the blob that this range corresponds to.- Returns:
- the
ByteRange
with start and end offsets - Throws:
java.lang.IllegalArgumentException
- if the byte range starts past the end of the blob.
-
toResolvedByteRange
public abstract ByteRange toResolvedByteRange(long totalSize, boolean resolveRangeOnEmptyBlob)
Given the total size of a blob, generate a newByteRange
of typeByteRange.ByteRangeType.OFFSET_RANGE
with defined start and end offsets that are verified to be within the supplied total blob size.- Parameters:
totalSize
- the total size of the blob that this range corresponds to.resolveRangeOnEmptyBlob
-true
to force range resolution to succeed if the blob is empty. In other words, return an empty range iftotalSize == 0
.- Returns:
- the
ByteRange
with start and end offsets - Throws:
java.lang.IllegalArgumentException
- if the byte range starts past the end of the blob.
-
toString
public abstract java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public abstract boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public abstract int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-