/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.tomcat.util.http.parser;
public Ranges(String units, List<Entry> entries) { // Units are lower case (RFC 9110, section 14.1) if (units == null) { this.units = null;
} else { this.units = units.toLowerCase(Locale.ENGLISH);
} this.entries = Collections.unmodifiableList(entries);
}
public List<Entry> getEntries() { return entries;
}
public String getUnits() { return units;
}
publicstaticclass Entry {
privatefinallong start; privatefinallong end;
public Entry(long start, long end) { this.start = start; this.end = end;
}
publiclong getStart() { return start;
}
publiclong getEnd() { return end;
}
}
/** * Parses a Range header from an HTTP header. * * @param input a reader over the header text * * @return a set of ranges parsed from the input, or null if not valid * * @throws IOException if there was a problem reading the input
*/ publicstatic Ranges parse(StringReader input) throws IOException {
// Units (required)
String units = HttpParser.readToken(input); if (units == null || units.length() == 0) { returnnull;
}
// Must be followed by '=' if (HttpParser.skipConstant(input, "=") != SkipResult.FOUND) { returnnull;
}
// Range entries
List<Entry> entries = new ArrayList<>();
SkipResult skipResult; do { long start = HttpParser.readLong(input); // Must be followed by '-' if (HttpParser.skipConstant(input, "-") != SkipResult.FOUND) { returnnull;
} long end = HttpParser.readLong(input);
if (start == -1 && end == -1) { // Invalid range returnnull;
}
entries.add(new Entry(start, end));
skipResult = HttpParser.skipConstant(input, ","); if (skipResult == SkipResult.NOT_FOUND) { // Invalid range returnnull;
}
} while (skipResult == SkipResult.FOUND);
returnnew Ranges(units, entries);
}
}
¤ Dauer der Verarbeitung: 0.22 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.