org.whispersystems.signalservice.internal.push.ContentRange Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of signal-service-java Show documentation
Show all versions of signal-service-java Show documentation
Signal Service communication library for Java, unofficial fork
package org.whispersystems.signalservice.internal.push;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class ContentRange {
private static final Pattern PATTERN = Pattern.compile("versions (\\d+)-(\\d+)\\/(\\d+)");
private final int rangeStart;
private final int rangeEnd;
private final int totalSize;
/**
* Parses a content range header.
*/
public static Optional parse(String header) {
if (header != null) {
Matcher matcher = PATTERN.matcher(header);
if (matcher.matches()) {
return Optional.of(new ContentRange(Integer.parseInt(matcher.group(1)),
Integer.parseInt(matcher.group(2)),
Integer.parseInt(matcher.group(3))));
}
}
return Optional.empty();
}
private ContentRange(int rangeStart, int rangeEnd, int totalSize) {
this.rangeStart = rangeStart;
this.rangeEnd = rangeEnd;
this.totalSize = totalSize;
}
public int getRangeStart() {
return rangeStart;
}
public int getRangeEnd() {
return rangeEnd;
}
public int getTotalSize() {
return totalSize;
}
}