ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/util/http/parser/Ranges.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/util/http/parser/Ranges.java
Status
scanned
Type
file
Name
Ranges.java
Extension
.java
Programming language
Java
Mime type
text/x-Algol68
File type
Algol 68 source, ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3569 (3.5 KB)
MD5
d3aa2f06f262decd66b17cb3a0250c05
SHA1
d2a07d617301605187ba007bb51f5393a89d5509
SHA256
20d02957bf6f0c56b93e4ffbdea047bdf207c82be935a164b558014322e13824
SHA512

      
    
SHA1_git
081bcbd05d8f2de3907bf29a8490a125cb39b777
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
Ranges.java | 3.5 KB |

/* * 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; import java.io.IOException; import java.io.StringReader; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Locale; public class Ranges { private final String units; private final List<Entry> entries; 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; } public static class Entry { private final long start; private final long end; public Entry(long start, long end) { this.start = start; this.end = end; } public long getStart() { return start; } public long 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 */ public static Ranges parse(StringReader input) throws IOException { // Units (required) String units = HttpParser.readToken(input); if (units == null || units.isEmpty()) { return null; } // Must be followed by '=' if (HttpParser.skipConstant(input, "=") != SkipResult.FOUND) { return null; } // 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) { return null; } long end = HttpParser.readLong(input); if (start == -1 && end == -1) { // Invalid range return null; } entries.add(new Entry(start, end)); skipResult = HttpParser.skipConstant(input, ","); if (skipResult == SkipResult.NOT_FOUND) { // Invalid range return null; } } while (skipResult == SkipResult.FOUND); return new Ranges(units, entries); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
31.48
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9