/** * Adds a <tt>Content-Type</tt> request header. * * @param state current state of http requests * @param conn the connection to use for I/O * * @throws IOException if an I/O (transport) error occurs. Some transport exceptions * can be recovered from. * @throws HttpException if a protocol exception occurs. Usually protocol exceptions * cannot be recovered from. * * @since 3.0 */ protected void addContentTypeRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { LOG.trace("enter EntityEnclosingMethod.addContentTypeRequestHeader(" + "HttpState, HttpConnection)"); if (!parameters.isEmpty()) { StringBuffer buffer = new StringBuffer(MULTIPART_FORM_CONTENT_TYPE); if (Part.getBoundary() != null) { buffer.append("; boundary="); buffer.append(Part.getBoundary()); } setRequestHeader("Content-Type", buffer.toString()); } }
/** * Write the content type header to the specified output stream * @param out The output stream * @throws IOException If an IO problem occurs. */ protected void sendContentTypeHeader(OutputStream out) throws IOException { LOG.trace("enter sendContentTypeHeader(OutputStream out)"); String contentType = getContentType(); if (contentType != null) { out.write(CRLF_BYTES); out.write(CONTENT_TYPE_BYTES); out.write(EncodingUtil.getAsciiBytes(contentType)); String charSet = getCharSet(); if (charSet != null) { out.write(CHARSET_BYTES); out.write(EncodingUtil.getAsciiBytes(charSet)); } } }
/** * Return the total sum of all parts and that of the last boundary * * @param parts The parts. * @return The total length * * @throws IOException If an I/O error occurs while writing the parts. */ public static long getLengthOfParts(Part[] parts) throws IOException { return getLengthOfParts(parts, DEFAULT_BOUNDARY_BYTES); }
/** * Return the full length of all the data. * If you override this method make sure to override * #send(OutputStream) as well * * @return long The length. * @throws IOException If an IO problem occurs */ public long length() throws IOException { LOG.trace("enter length()"); if (lengthOfData() < 0) { return -1; } ByteArrayOutputStream overhead = new ByteArrayOutputStream(); sendStart(overhead); sendDispositionHeader(overhead); sendContentTypeHeader(overhead); sendTransferEncodingHeader(overhead); sendEndOfHeader(overhead); sendEnd(overhead); return overhead.size() + lengthOfData(); }
for (int i = 0; i < parts.length; i++) { parts[i].setPartBoundary(partBoundary); long l = parts[i].length(); if (l < 0) { return -1;
/** * Return a string representation of this object. * @return A string representation of this object. * @see java.lang.Object#toString() */ public String toString() { return this.getName(); }
/** * Returns <code>true</code> if all parts are repeatable, <code>false</code> otherwise. * @see org.apache.commons.httpclient.methods.RequestEntity#isRepeatable() */ public boolean isRepeatable() { for (int i = 0; i < parts.length; i++) { if (!parts[i].isRepeatable()) { return false; } } return true; }
/** * Write the start to the specified output stream * @param out The output stream * @throws IOException If an IO problem occurs. */ protected void sendStart(OutputStream out) throws IOException { LOG.trace("enter sendStart(OutputStream out)"); out.write(EXTRA_BYTES); out.write(getPartBoundary()); out.write(CRLF_BYTES); }
/** * Write the content transfer encoding header to the specified * output stream * * @param out The output stream * @throws IOException If an IO problem occurs. */ protected void sendTransferEncodingHeader(OutputStream out) throws IOException { LOG.trace("enter sendTransferEncodingHeader(OutputStream out)"); String transferEncoding = getTransferEncoding(); if (transferEncoding != null) { out.write(CRLF_BYTES); out.write(CONTENT_TRANSFER_ENCODING_BYTES); out.write(EncodingUtil.getAsciiBytes(transferEncoding)); } }
/** * Return the full length of all the data. * If you override this method make sure to override * #send(OutputStream) as well * * @return long The length. * @throws IOException If an IO problem occurs */ public long length() throws IOException { LOG.trace("enter length()"); if (lengthOfData() < 0) { return -1; } ByteArrayOutputStream overhead = new ByteArrayOutputStream(); sendStart(overhead); sendDispositionHeader(overhead); sendContentTypeHeader(overhead); sendTransferEncodingHeader(overhead); sendEndOfHeader(overhead); sendEnd(overhead); return overhead.size() + lengthOfData(); }
for (int i = 0; i < parts.length; i++) { parts[i].setPartBoundary(partBoundary); long l = parts[i].length(); if (l < 0) { return -1;
/** * Write the content disposition header to the specified output stream * * @param out The output stream * @throws IOException If an IO problem occurs. */ protected void sendDispositionHeader(OutputStream out) throws IOException { LOG.trace("enter sendDispositionHeader(OutputStream out)"); out.write(CONTENT_DISPOSITION_BYTES); out.write(QUOTE_BYTES); out.write(EncodingUtil.getAsciiBytes(getName())); out.write(QUOTE_BYTES); }
/** * Returns <code>true</code> if all parts are repeatable, <code>false</code> otherwise. * @see org.apache.commons.httpclient.methods.RequestEntity#isRepeatable() */ public boolean isRepeatable() { for (int i = 0; i < parts.length; i++) { if (!parts[i].isRepeatable()) { return false; } } return true; }
/** * Write the start to the specified output stream * @param out The output stream * @throws IOException If an IO problem occurs. */ protected void sendStart(OutputStream out) throws IOException { LOG.trace("enter sendStart(OutputStream out)"); out.write(EXTRA_BYTES); out.write(getPartBoundary()); out.write(CRLF_BYTES); }
/** * Write the content transfer encoding header to the specified * output stream * * @param out The output stream * @throws IOException If an IO problem occurs. */ protected void sendTransferEncodingHeader(OutputStream out) throws IOException { LOG.trace("enter sendTransferEncodingHeader(OutputStream out)"); String transferEncoding = getTransferEncoding(); if (transferEncoding != null) { out.write(CRLF_BYTES); out.write(CONTENT_TRANSFER_ENCODING_BYTES); out.write(EncodingUtil.getAsciiBytes(transferEncoding)); } }
/** * Return the full length of all the data. * If you override this method make sure to override * #send(OutputStream) as well * * @return long The length. * @throws IOException If an IO problem occurs */ public long length() throws IOException { LOG.trace("enter length()"); if (lengthOfData() < 0) { return -1; } ByteArrayOutputStream overhead = new ByteArrayOutputStream(); sendStart(overhead); sendDispositionHeader(overhead); sendContentTypeHeader(overhead); sendTransferEncodingHeader(overhead); sendEndOfHeader(overhead); sendEnd(overhead); return overhead.size() + lengthOfData(); }
/** * Write the content type header to the specified output stream * @param out The output stream * @throws IOException If an IO problem occurs. */ protected void sendContentTypeHeader(OutputStream out) throws IOException { LOG.trace("enter sendContentTypeHeader(OutputStream out)"); String contentType = getContentType(); if (contentType != null) { out.write(CRLF_BYTES); out.write(CONTENT_TYPE_BYTES); out.write(EncodingUtil.getAsciiBytes(contentType)); String charSet = getCharSet(); if (charSet != null) { out.write(CHARSET_BYTES); out.write(EncodingUtil.getAsciiBytes(charSet)); } } }
for (int i = 0; i < parts.length; i++) { parts[i].setPartBoundary(partBoundary); long l = parts[i].length(); if (l < 0) { return -1;
/** * <p>Return the length of the request body.</p> * * <p>Once this method has been invoked, the request parameters cannot be * altered until the method is {@link #recycle recycled}.</p> * * @return The request content length. */ protected long getRequestContentLength() throws IOException { LOG.trace("enter MultipartPostMethod.getRequestContentLength()"); return Part.getLengthOfParts(getParts()); }
/** * Return a string representation of this object. * @return A string representation of this object. * @see java.lang.Object#toString() */ public String toString() { return this.getName(); }