Return-Path: X-Original-To: apmail-hc-dev-archive@www.apache.org Delivered-To: apmail-hc-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 71E1D4430 for ; Thu, 2 Jun 2011 17:36:29 +0000 (UTC) Received: (qmail 14416 invoked by uid 500); 2 Jun 2011 17:36:29 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 14347 invoked by uid 500); 2 Jun 2011 17:36:29 -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 14339 invoked by uid 99); 2 Jun 2011 17:36:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jun 2011 17:36:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jun 2011 17:36:27 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id D2D1AF0042 for ; Thu, 2 Jun 2011 17:35:47 +0000 (UTC) Date: Thu, 2 Jun 2011 17:35:47 +0000 (UTC) From: "William R. Speirs (JIRA)" To: dev@hc.apache.org Message-ID: <1259670943.63441.1307036147860.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1713162332.63150.1307030270893.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (HTTPCORE-258) Add Offset and Length to ByteArrayEntity 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/HTTPCORE-258?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13042907#comment-13042907 ] William R. Speirs commented on HTTPCORE-258: -------------------------------------------- I attached diffs for the three files. Are there test cases for the HttpCore NIO stuff? If so, where? Thanks! > Add Offset and Length to ByteArrayEntity > ---------------------------------------- > > Key: HTTPCORE-258 > URL: https://issues.apache.org/jira/browse/HTTPCORE-258 > Project: HttpComponents HttpCore > Issue Type: Improvement > Components: HttpCore, HttpCore NIO > Environment: N/A > Reporter: William R. Speirs > Priority: Trivial > Fix For: 4.2-alpha1 > > Attachments: ByteArrayEntity.diff, NByteArrayEntity.diff, TestByteArrayEntity.diff > > > Currently the ByteArrayEntity only has a single constructor which will only accept a byte[]. I suggest this class be extended to handle an additional constructor which takes an offset and length. I have created the following first draft of a patch to the ByteArrayEntity class. Additional changes will need to be made to the test cases and the NByteArrayEntity class as well. > --- httpcore/src/main/java/org/apache/http/entity/ByteArrayEntity.java (revision 1130603) > +++ httpcore/src/main/java/org/apache/http/entity/ByteArrayEntity.java (working copy) > @@ -40,6 +40,7 @@ > public class ByteArrayEntity extends AbstractHttpEntity implements Cloneable { > protected final byte[] content; > + protected int off, len; > public ByteArrayEntity(final byte[] b) { > super(); > @@ -47,25 +48,43 @@ > throw new IllegalArgumentException("Source byte array may not be null"); > } > this.content = b; > + this.off = 0; > + this.len = this.content.length; > } > + public ByteArrayEntity(final byte[] b, int off, int len) { > + super(); > + if (b == null) { > + throw new IllegalArgumentException("Source byte array may not be null"); > + } > + if (off < 0) { > + throw new IllegalArgumentException("Offset cannot be negative"); > + } > + if(b.length - off >= len) { > + throw new IllegalArgumentException("Length cannot be longer than byte array"); > + } > + this.content = b; > + this.off = off; > + this.len = len; > + } > + > public boolean isRepeatable() { > return true; > } > public long getContentLength() { > - return this.content.length; > + return this.len - this.off; > } > public InputStream getContent() { > - return new ByteArrayInputStream(this.content); > + return new ByteArrayInputStream(this.content, this.off, this.len); > } > public void writeTo(final OutputStream outstream) throws IOException { > if (outstream == null) { > throw new IllegalArgumentException("Output stream may not be null"); > } > - outstream.write(this.content); > + outstream.write(this.content, this.off, this.len); > outstream.flush(); > } -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org