01: // HttpRangeList.java
02: // $Id: HttpRangeList.java,v 1.6 2000/08/16 21:38:00 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.www.http;
07:
08: import java.util.Vector;
09:
10: public class HttpRangeList extends BasicValue {
11: HttpRange ranges[] = null;
12:
13: protected void parse() {
14: Vector vr = new Vector(2);
15: ParseState ps = new ParseState(roff, rlen);
16: ps.separator = (byte) ',';
17: ps.spaceIsSep = false;
18: while (HttpParser.nextItem(raw, ps) >= 0) {
19: vr.addElement(new HttpRange(this , raw, ps.start, ps.end));
20: ps.prepare();
21: }
22: if (vr.size() > 0) {
23: ranges = new HttpRange[vr.size()];
24: vr.copyInto(ranges);
25: }
26: }
27:
28: protected void updateByteValue() {
29: HttpBuffer buf = new HttpBuffer();
30: for (int i = 0; i < ranges.length; i++) {
31: if (i > 0)
32: buf.append(',');
33: ranges[i].appendValue(buf);
34: }
35: raw = buf.getByteCopy();
36: roff = 0;
37: rlen = raw.length;
38: }
39:
40: public Object getValue() {
41: validate();
42: return ranges;
43: }
44:
45: /**
46: * Add a range to this list.
47: * @param range The range to add.
48: */
49:
50: public void addRange(HttpRange range) {
51: if (ranges == null) {
52: ranges = new HttpRange[1];
53: ranges[0] = range;
54: } else {
55: int len = ranges.length;
56: HttpRange nranges[] = new HttpRange[len + 1];
57: System.arraycopy(ranges, 0, nranges, 0, len);
58: nranges[len] = range;
59: ranges = nranges;
60: }
61: }
62:
63: HttpRangeList(HttpRange ranges[]) {
64: this .ranges = ranges;
65: this .isValid = true;
66: }
67:
68: HttpRangeList() {
69: this .isValid = false;
70: }
71:
72: }
|