yifan-c commented on code in PR #35:
URL: https://github.com/apache/cassandra-sidecar/pull/35#discussion_r943957845


##########
src/main/java/org/apache/cassandra/sidecar/models/Range.java:
##########
@@ -31,132 +31,133 @@
  * Accepted Range formats are start-end, start-, -suffix_length
  * start-end (start = start index of the range, end = end index of the range, 
both inclusive)
  * start- (start = start index of the range, end = end of file)
- * -suffix-length (Requested length from end of file)
+ * -suffix-length (Requested length from end of file. The length should be 
positive)
  */
 public class Range
 {
-    private static final Pattern START_END = 
Pattern.compile("^(\\d+)-(\\d+)$");
-    private static final Pattern PARTIAL = 
Pattern.compile("^((\\d+)-)$|^(-(\\d+))$");
     private static final String RANGE_UNIT = "bytes";
+    // matches a. bytes=1-2, b. bytes=1-, c. bytes=-2, d. bytes=-. Need to do 
another valid for case d.
+    private static final Pattern RANGE_HEADER = Pattern.compile("^" + 
RANGE_UNIT + "=(\\d*)-(\\d*)$");
     private final long start;
     private final long end;
     private final long length;
 
-    private Range(final long start, final long end)
+    /**
+     * Accepted RangeHeader formats are bytes=start-end, bytes=start-, 
bytes=-suffix_length
+     */
+    public static Range parseHeader(final String header, final long fileSize)
     {
-        this.start = start;
-        this.end = end;
-        this.length = length(start, end);
+        if (header == null)
+        {
+            return new Range(0, fileSize - 1);
+        }
+        if (!header.startsWith(RANGE_UNIT + "="))

Review Comment:
   No. I will remove it. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to