001package com.box.sdkgen.managers.chunkeduploads;
002
003import static com.box.sdkgen.internal.utils.UtilsManager.mapOf;
004
005import java.util.Map;
006
007public class UploadFilePartByUrlHeaders {
008
009  /**
010   * The [RFC3230][1] message digest of the chunk uploaded.
011   *
012   * <p>Only SHA1 is supported. The SHA1 digest must be base64 encoded. The format of this header is
013   * as `sha=BASE64_ENCODED_DIGEST`.
014   *
015   * <p>To get the value for the `SHA` digest, use the openSSL command to encode the file part:
016   * `openssl sha1 -binary &lt;FILE_PART_NAME&gt; | base64`.
017   *
018   * <p>[1]: https://tools.ietf.org/html/rfc3230
019   */
020  public final String digest;
021
022  /**
023   * The byte range of the chunk.
024   *
025   * <p>Must not overlap with the range of a part already uploaded this session. Each part’s size
026   * must be exactly equal in size to the part size specified in the upload session that you
027   * created. One exception is the last part of the file, as this can be smaller.
028   *
029   * <p>When providing the value for `content-range`, remember that:
030   *
031   * <p>* The lower bound of each part's byte range must be a multiple of the part size. * The
032   * higher bound must be a multiple of the part size - 1.
033   */
034  public final String contentRange;
035
036  /** Extra headers that will be included in the HTTP request. */
037  public Map<String, String> extraHeaders;
038
039  public UploadFilePartByUrlHeaders(String digest, String contentRange) {
040    this.digest = digest;
041    this.contentRange = contentRange;
042    this.extraHeaders = mapOf();
043  }
044
045  protected UploadFilePartByUrlHeaders(Builder builder) {
046    this.digest = builder.digest;
047    this.contentRange = builder.contentRange;
048    this.extraHeaders = builder.extraHeaders;
049  }
050
051  public String getDigest() {
052    return digest;
053  }
054
055  public String getContentRange() {
056    return contentRange;
057  }
058
059  public Map<String, String> getExtraHeaders() {
060    return extraHeaders;
061  }
062
063  public static class Builder {
064
065    protected final String digest;
066
067    protected final String contentRange;
068
069    protected Map<String, String> extraHeaders;
070
071    public Builder(String digest, String contentRange) {
072      this.digest = digest;
073      this.contentRange = contentRange;
074    }
075
076    public Builder extraHeaders(Map<String, String> extraHeaders) {
077      this.extraHeaders = extraHeaders;
078      return this;
079    }
080
081    public UploadFilePartByUrlHeaders build() {
082      if (this.extraHeaders == null) {
083        this.extraHeaders = mapOf();
084      }
085      return new UploadFilePartByUrlHeaders(this);
086    }
087  }
088}