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

org.asynchttpclient.request.body.multipart.part.FileLikeMultipartPart Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package org.asynchttpclient.request.body.multipart.part;

import org.asynchttpclient.request.body.multipart.FileLikePart;

import static java.nio.charset.StandardCharsets.*;

public abstract class FileLikeMultipartPart extends MultipartPart {

  /**
   * Attachment's file name as a byte array
   */
  private static final byte[] FILE_NAME_BYTES = "; filename=".getBytes(US_ASCII);

  FileLikeMultipartPart(T part, byte[] boundary) {
    super(part, boundary);
  }

  protected void visitDispositionHeader(PartVisitor visitor) {
    super.visitDispositionHeader(visitor);
    if (part.getFileName() != null) {
      visitor.withBytes(FILE_NAME_BYTES);
      visitor.withByte(QUOTE_BYTE);
      visitor.withBytes(part.getFileName().getBytes(part.getCharset() != null ? part.getCharset() : UTF_8));
      visitor.withByte(QUOTE_BYTE);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy