org.abstracthorizon.danube.http.util
Class Ranges

java.lang.Object
  extended by org.abstracthorizon.danube.http.util.Ranges

public class Ranges
extends Object

Class keeping from and to pointers in a file

Author:
Daniel Sendula

Nested Class Summary
static class Ranges.Range
          Single range definition
 
Field Summary
protected  List<Ranges.Range> ranges
          List of ranges for multi-range
protected  Ranges.Range singleRange
          If this is a single range then it is stored here
protected  long size
          Size of the resource or -1 if unkonwn
 
Constructor Summary
Ranges()
          Constructor
 
Method Summary
 void addRange(long from, long to)
          Adds next range
protected  boolean combine(Ranges.Range range1, Ranges.Range range2)
          Tries to combine two ranges.
 String format()
          Formats value of this ranges object as specified in "Content-Range"
 List<Ranges.Range> getRanges()
          Returns list of ranges
 Ranges.Range getSingleRange()
          Returns single range or null
 long getSize()
          Returns size or -1 if size is unknown
 boolean isMultiRange()
          Returns true if this is multi-range
protected  void makeCanonic()
          Makes this ranges in canonic form (as long as they are sorted
static Ranges parseContentRange(String ranges)
          Parses input string for ranges format
protected static long parseLong(String input, int from, int to)
          Parses input string from given index
protected static boolean parseOneRange(String input, int from, int to, Ranges result)
          Parses one range in format of "xxx-yyy", "xxx-" or "-yyy"
static Ranges parseRange(String ranges)
          Parses input string for ranges format
 void setSize(long size)
          Sets size
 String toString()
          Returns string representation
protected  void updateSize(Ranges.Range range)
          Updates size to prefix and suffix ranges
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

singleRange

protected Ranges.Range singleRange
If this is a single range then it is stored here


ranges

protected List<Ranges.Range> ranges
List of ranges for multi-range


size

protected long size
Size of the resource or -1 if unkonwn

Constructor Detail

Ranges

public Ranges()
Constructor

Method Detail

isMultiRange

public boolean isMultiRange()
Returns true if this is multi-range

Returns:
true if this is multi-range

setSize

public void setSize(long size)
Sets size

Parameters:
size - size

getSize

public long getSize()
Returns size or -1 if size is unknown

Returns:
size or -1 if size is unknown

getRanges

public List<Ranges.Range> getRanges()
Returns list of ranges

Returns:
list of ranges

getSingleRange

public Ranges.Range getSingleRange()
Returns single range or null

Returns:
single range or null

updateSize

protected void updateSize(Ranges.Range range)
Updates size to prefix and suffix ranges

Parameters:
range - range to be updated

addRange

public void addRange(long from,
                     long to)
Adds next range

Parameters:
from - from
to - to

combine

protected boolean combine(Ranges.Range range1,
                          Ranges.Range range2)
Tries to combine two ranges. If it succeeds result is in range1 and result is true. Otherwise result is false and ranges are unchanged.

Parameters:
range1 - range one and result in case of success
range2 - range two
Returns:
true if two ranges can be combined

makeCanonic

protected void makeCanonic()
Makes this ranges in canonic form (as long as they are sorted


parseRange

public static Ranges parseRange(String ranges)
Parses input string for ranges format

Parameters:
ranges - input string
Returns:
parsed ranges object or null if incorrect format

parseContentRange

public static Ranges parseContentRange(String ranges)
Parses input string for ranges format

Parameters:
ranges - input string
Returns:
parsed ranges object or null if incorrect format

parseOneRange

protected static boolean parseOneRange(String input,
                                       int from,
                                       int to,
                                       Ranges result)
Parses one range in format of "xxx-yyy", "xxx-" or "-yyy"

Parameters:
input - input string
from - form index
to - to index
result - result object to be populated with newly recognised range
Returns:
true if format is recognised, false otherwise

parseLong

protected static long parseLong(String input,
                                int from,
                                int to)
Parses input string from given index

Parameters:
input - input string
from - index to start parsing from
Returns:
true if there is at least one digit

toString

public String toString()
Returns string representation

Overrides:
toString in class Object
Returns:
string represetnation

format

public String format()
Formats value of this ranges object as specified in "Content-Range"

Returns:
value of this ranges object as specified in "Content-Range" if there is more then one range then return null


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.