Partition.java

  1. package com.renomad.minum.web;

  2. import com.renomad.minum.utils.StringUtils;

  3. import java.util.Arrays;
  4. import java.util.Objects;

  5. /**
  6.  * Represents a single partition in a multipart/form-data body response
  7.  */
  8. public final class Partition {

  9.     private final Headers headers;
  10.     private final byte[] content;
  11.     private final ContentDisposition contentDisposition;

  12.     public Partition(Headers headers, byte[] content, ContentDisposition contentDisposition) {
  13.         this.headers = headers;
  14.         this.content = content;
  15.         this.contentDisposition = contentDisposition;
  16.     }

  17.     public Headers getHeaders() {
  18.         return headers;
  19.     }

  20.     public ContentDisposition getContentDisposition() {
  21.         return contentDisposition;
  22.     }

  23.     public byte[] getContent() {
  24.         return content.clone();
  25.     }
  26.     public String getContentAsString() {
  27.         return StringUtils.byteArrayToString(content);
  28.     }

  29.     @Override
  30.     public boolean equals(Object o) {
  31.         if (this == o) return true;
  32.         if (o == null || getClass() != o.getClass()) return false;
  33.         Partition partition = (Partition) o;
  34.         return Objects.equals(headers, partition.headers) && Arrays.equals(content, partition.content) && Objects.equals(contentDisposition, partition.contentDisposition);
  35.     }

  36.     @Override
  37.     public int hashCode() {
  38.         int result = Objects.hash(headers, contentDisposition);
  39.         result = 31 * result + Arrays.hashCode(content);
  40.         return result;
  41.     }

  42.     @Override
  43.     public String toString() {
  44.         return "Partition{" +
  45.                 "headers=" + headers +
  46.                 ", contentDisposition=" + contentDisposition +
  47.                 '}';
  48.     }
  49. }