Methods Summary |
---|
private static byte[] | generateMultipartBoundary()Generates a random multipart boundary string.
Random rand = new Random();
byte[] bytes = new byte[rand.nextInt(11) + 30]; // a random size from 30 to 40
for (int i = 0; i < bytes.length; i++) {
bytes[i] = MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)];
}
return bytes;
|
public java.io.InputStream | getContent()
if(!isRepeatable() && this.contentConsumed ) {
throw new IllegalStateException("Content has been consumed");
}
this.contentConsumed = true;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Part.sendParts(baos, this.parts, this.multipartBoundary);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
return bais;
|
public long | getContentLength()
try {
return Part.getLengthOfParts(parts, getMultipartBoundary());
} catch (Exception e) {
log.error("An exception occurred while getting the length of the parts", e);
return 0;
}
|
public org.apache.http.Header | getContentType()
StringBuffer buffer = new StringBuffer(MULTIPART_FORM_CONTENT_TYPE);
buffer.append("; boundary=");
buffer.append(EncodingUtils.getAsciiString(getMultipartBoundary()));
return new BasicHeader(HTTP.CONTENT_TYPE, buffer.toString());
|
protected byte[] | getMultipartBoundary()Returns the MIME boundary string that is used to demarcate boundaries of
this part. The first call to this method will implicitly create a new
boundary string. To create a boundary string first the
HttpMethodParams.MULTIPART_BOUNDARY parameter is considered. Otherwise
a random one is generated.
if (multipartBoundary == null) {
String temp = null;
if (params != null) {
temp = (String) params.getParameter(MULTIPART_BOUNDARY);
}
if (temp != null) {
multipartBoundary = EncodingUtils.getAsciiBytes(temp);
} else {
multipartBoundary = generateMultipartBoundary();
}
}
return multipartBoundary;
|
public boolean | isRepeatable()Returns true if all parts are repeatable, false otherwise.
for (int i = 0; i < parts.length; i++) {
if (!parts[i].isRepeatable()) {
return false;
}
}
return true;
|
public boolean | isStreaming()
return false;
|
public void | writeTo(java.io.OutputStream out)
Part.sendParts(out, parts, getMultipartBoundary());
|