If you think the Android project volley listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.android.volley.toolbox.multipart;
/*fromwww.java2s.com*/import org.apache.http.util.ByteArrayBuffer;
import org.apache.http.util.EncodingUtils;
/**
* Parent class for FilePart and StringPart.
*
* @author <a href="mailto:vit at cleverua.com">Vitaliy Khudenko</a>
*//* package */abstractclass BasePart implements Part {
protectedstaticfinalbyte[] CRLF = EncodingUtils.getAsciiBytes(MultipartEntity.CRLF);
protectedinterface IHeadersProvider {
public String getContentDisposition();
public String getContentType();
public String getContentTransferEncoding();
}
protected IHeadersProvider headersProvider; // must be initialized in descendant constructor
privatebyte[] header;
protectedbyte[] getHeader(Boundary boundary) {
if (header == null) {
header = generateHeader(boundary); // lazy init
}
return header;
}
privatebyte[] generateHeader(Boundary boundary) {
if (headersProvider == null) {
thrownew RuntimeException("Uninitialized headersProvider"); //$NON-NLS-1$
}
final ByteArrayBuffer buf = new ByteArrayBuffer(256);
append(buf, boundary.getStartingBoundary());
append(buf, headersProvider.getContentDisposition());
append(buf, CRLF);
append(buf, headersProvider.getContentType());
append(buf, CRLF);
append(buf, headersProvider.getContentTransferEncoding());
append(buf, CRLF);
append(buf, CRLF);
return buf.toByteArray();
}
privatestaticvoid append(ByteArrayBuffer buf, String data) {
append(buf, EncodingUtils.getAsciiBytes(data));
}
privatestaticvoid append(ByteArrayBuffer buf, byte[] data) {
buf.append(data, 0, data.length);
}
}