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

io.github.jpmorganchase.fusion.api.tools.RegexBasedContentRangeParser Maven / Gradle / Ivy

There is a newer version: 0.0.14
Show newest version
package io.github.jpmorganchase.fusion.api.tools;

import io.github.jpmorganchase.fusion.api.response.ContentRange;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Tool used to parse the "Content-Range" header for each pertinent element.
 * 

* Content-Range header expected to hold a value following the pattern "bytes startPos-endPos/contentLength" */ public class RegexBasedContentRangeParser implements ContentRangeParser { private static final String PATTERN = "bytes (\\d+)-(\\d+)/(\\d+)"; private static final Long EMPTY = -1L; @Override public ContentRange parse(String contentRange) { Pattern regex = Pattern.compile(PATTERN); Matcher matcher = regex.matcher(contentRange); if (matcher.find()) { return ContentRange.builder() .start(Long.parseLong(matcher.group(1))) .end(Long.parseLong(matcher.group(2))) .total(Long.parseLong(matcher.group(3))) .build(); } return ContentRange.builder().start(EMPTY).end(EMPTY).total(EMPTY).build(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy