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

com.belerweb.weixin.mp.ByteArrayPart Maven / Gradle / Ivy

There is a newer version: 1.0.0-preview-2
Show newest version
package com.belerweb.weixin.mp;

import java.io.IOException;
import java.io.OutputStream;

import org.apache.commons.httpclient.methods.multipart.PartBase;

public class ByteArrayPart extends PartBase {

  private byte[] mData;
  private String mName;

  public ByteArrayPart(byte[] data, String name, String type) throws IOException {
    super(name, type, "UTF-8", "binary");
    mName = name;
    mData = data;
  }

  protected void sendData(OutputStream out) throws IOException {
    out.write(mData);
  }

  protected long lengthOfData() throws IOException {
    return mData.length;
  }

  protected void sendDispositionHeader(OutputStream out) throws IOException {
    super.sendDispositionHeader(out);
    StringBuilder buf = new StringBuilder();
    buf.append("; filename=\"").append(mName).append("\"");
    out.write(buf.toString().getBytes());
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy