All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.whispersystems.signalservice.internal.push.ContentRange Maven / Gradle / Ivy

There is a newer version: 2.15.3_unofficial_107
Show newest version
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;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy