Return-Path: Delivered-To: apmail-hc-dev-archive@www.apache.org Received: (qmail 47329 invoked from network); 16 Oct 2010 17:28:47 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 16 Oct 2010 17:28:47 -0000 Received: (qmail 98893 invoked by uid 500); 16 Oct 2010 17:28:47 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 98834 invoked by uid 500); 16 Oct 2010 17:28:46 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 98824 invoked by uid 99); 16 Oct 2010 17:28:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Oct 2010 17:28:46 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Oct 2010 17:28:45 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o9GHSPgB025090 for ; Sat, 16 Oct 2010 17:28:25 GMT Message-ID: <12470032.3111287250105021.JavaMail.jira@thor> Date: Sat, 16 Oct 2010 13:28:25 -0400 (EDT) From: "Oleg Kalnichevski (JIRA)" To: dev@hc.apache.org Subject: [jira] Resolved: (HTTPCLIENT-1014) ByteArrayBody as an alternative to InputStreamBody In-Reply-To: <7135224.140101287053255182.JavaMail.jira@thor> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/HTTPCLIENT-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Oleg Kalnichevski resolved HTTPCLIENT-1014. ------------------------------------------- Resolution: Fixed Fix Version/s: 4.1 Alpha3 Committed to the SVN trunk. Many thanks, Axel. Oleg > ByteArrayBody as an alternative to InputStreamBody > -------------------------------------------------- > > Key: HTTPCLIENT-1014 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1014 > Project: HttpComponents HttpClient > Issue Type: New Feature > Components: HttpClient > Affects Versions: 4.1 Alpha2 > Reporter: Axel Fontaine > Fix For: 4.1 Alpha3 > > > InputStreamBody can not determine the content length, which in turn causes requests to be sent with a content length of 0, even though the content is there. .NET Servers have trouble dealing with this. > ByteArrayBody provides an alternative that alliviates this limitation. > Source: > > import java.io.IOException; > import java.io.OutputStream; > import org.apache.http.entity.mime.MIME; > import org.apache.http.entity.mime.content.AbstractContentBody; > /** > * Body part that is built using a byte array containing a file. > * > * @author Axel Fontaine > */ > public class ByteArrayBody extends AbstractContentBody { > /** > * The contents of the file contained in this part. > */ > private byte[] data; > /** > * The name of the file contained in this part. > */ > private String filename; > > /** > * Creates a new ByteArrayBody. > * > * @param data The contents of the file contained in this part. > * @param mimeType The mime type of the file contained in this part. > * @param filename The name of the file contained in this part. > */ > public ByteArrayBody(final byte[] data, final String mimeType, final String filename) { > super(mimeType); > if (data == null) { > throw new IllegalArgumentException("byte[] may not be null"); > } > this.data = data; > this.filename = filename; > } > /** > * Creates a new ByteArrayBody. > * > * @param data The contents of the file contained in this part. > * @param filename The name of the file contained in this part. > */ > public ByteArrayBody(final byte[] data, final String filename) { > this(data, "application/octet-stream", filename); > } > @Override > public String getFilename() { > return filename; > } > @Override > public void writeTo(OutputStream out) throws IOException { > out.write(data); > } > @Override > public String getCharset() { > return null; > } > @Override > public String getTransferEncoding() { > return MIME.ENC_BINARY; > } > @Override > public long getContentLength() { > return data.length; > } > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org