Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 74930200C56 for ; Fri, 14 Apr 2017 13:14:40 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 733DD160B8C; Fri, 14 Apr 2017 11:14:40 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9608E160B80 for ; Fri, 14 Apr 2017 13:14:39 +0200 (CEST) Received: (qmail 5312 invoked by uid 500); 14 Apr 2017 11:14:38 -0000 Mailing-List: contact commits-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 commits@hc.apache.org Received: (qmail 5303 invoked by uid 99); 14 Apr 2017 11:14:38 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Apr 2017 11:14:38 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 410FA3A16CA for ; Fri, 14 Apr 2017 11:14:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1791356 - in /httpcomponents/httpcore/trunk/httpcore5/src: main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityConsumer.java test/java/org/apache/hc/core5/http/nio/entity/TestAbstractBinAsyncEntityConsumer.java Date: Fri, 14 Apr 2017 11:14:38 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170414111438.410FA3A16CA@svn01-us-west.apache.org> archived-at: Fri, 14 Apr 2017 11:14:40 -0000 Author: olegk Date: Fri Apr 14 11:14:38 2017 New Revision: 1791356 URL: http://svn.apache.org/viewvc?rev=1791356&view=rev Log: Added BasicAsyncEntityConsumer Added: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityConsumer.java (with props) Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractBinAsyncEntityConsumer.java Added: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityConsumer.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityConsumer.java?rev=1791356&view=auto ============================================================================== --- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityConsumer.java (added) +++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityConsumer.java Fri Apr 14 11:14:38 2017 @@ -0,0 +1,79 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.hc.core5.http.nio.entity; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpException; +import org.apache.hc.core5.util.ByteArrayBuffer; + +public class BasicAsyncEntityConsumer extends AbstractBinAsyncEntityConsumer { + + + private final ByteArrayBuffer buffer; + + public BasicAsyncEntityConsumer() { + super(); + this.buffer = new ByteArrayBuffer(1024); + } + + @Override + protected void streamStart(final ContentType contentType) throws HttpException, IOException { + } + + @Override + protected int capacity() { + return Integer.MAX_VALUE; + } + + @Override + protected void data(final ByteBuffer src, final boolean endOfStream) throws IOException { + if (src == null) { + return; + } + if (src.hasArray()) { + buffer.append(src.array(), src.arrayOffset() + src.position(), src.remaining()); + } else { + while (src.hasRemaining()) { + buffer.append(src.get()); + } + } + } + + @Override + protected byte[] generateContent() throws IOException { + return buffer.toByteArray(); + } + + @Override + public void releaseResources() { + } + +} Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityConsumer.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityConsumer.java ------------------------------------------------------------------------------ svn:keywords = Date Revision Propchange: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/entity/BasicAsyncEntityConsumer.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractBinAsyncEntityConsumer.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractBinAsyncEntityConsumer.java?rev=1791356&r1=1791355&r2=1791356&view=diff ============================================================================== --- httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractBinAsyncEntityConsumer.java (original) +++ httpcomponents/httpcore/trunk/httpcore5/src/test/java/org/apache/hc/core5/http/nio/entity/TestAbstractBinAsyncEntityConsumer.java Fri Apr 14 11:14:38 2017 @@ -35,42 +35,20 @@ import org.apache.hc.core5.concurrent.Fu import org.apache.hc.core5.http.ContentType; import org.apache.hc.core5.http.HttpException; import org.apache.hc.core5.http.impl.BasicEntityDetails; -import org.apache.hc.core5.http.impl.nio.ExpandableBuffer; import org.apache.hc.core5.http.nio.AsyncEntityConsumer; +import org.apache.hc.core5.util.ByteArrayBuffer; import org.junit.Assert; import org.junit.Test; public class TestAbstractBinAsyncEntityConsumer { - private static class InternalBuffer extends ExpandableBuffer { - - InternalBuffer(final int bufferSize) { - super(bufferSize); - } - - void write(final ByteBuffer src) { - setInputMode(); - final int requiredCapacity = buffer().position() + src.remaining(); - ensureCapacity(requiredCapacity); - buffer().put(src); - } - - byte[] toByteArray() { - setOutputMode(); - final byte[] bytes = new byte[buffer().remaining()]; - buffer().get(bytes); - return bytes; - } - - } - static private class ByteArrayAsyncEntityConsumer extends AbstractBinAsyncEntityConsumer { - private final InternalBuffer buffer; + private final ByteArrayBuffer buffer; public ByteArrayAsyncEntityConsumer() { super(); - this.buffer = new InternalBuffer(1024); + this.buffer = new ByteArrayBuffer(1024); } @Override @@ -84,7 +62,16 @@ public class TestAbstractBinAsyncEntityC @Override protected void data(final ByteBuffer src, final boolean endOfStream) throws IOException { - buffer.write(src); + if (src == null) { + return; + } + if (src.hasArray()) { + buffer.append(src.array(), src.arrayOffset() + src.position(), src.remaining()); + } else { + while (src.hasRemaining()) { + buffer.append(src.get()); + } + } } @Override