@@ -0,0 +1,1934 @@
+/*%0A * Copyright 2010 Ning, Inc.%0A *%0A * Ning licenses this file to you under the Apache License, version 2.0%0A * (the %22License%22); you may not use this file except in compliance with the%0A * License.  You may obtain a copy of the License at:%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS, WITHOUT%0A * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the%0A * License for the specific language governing permissions and limitations%0A * under the License.%0A *%0A */%0Apackage com.ning.http.client.generators;%0A%0Aimport com.ning.http.client.Body;%0Aimport com.ning.http.client.BodyGenerator;%0A%0Aimport java.io.IOException;%0Aimport java.nio.ByteBuffer;%0A%0Apublic class ByteArrayBodyGenerator implements BodyGenerator %7B%0A%0A    private final byte%5B%5D bytes;%0A    private boolean eof = false;%0A    private int lastPosition = 0;%0A%0A    public ByteArrayBodyGenerator(byte%5B%5D bytes) %7B%0A        this.bytes = bytes;%0A    %7D%0A%0A    protected final class ByteBody implements Body %7B%0A%0A        public long getContentLength() %7B%0A            return bytes.length;%0A        %7D%0A%0A        public long read(ByteBuffer byteBuffer) throws IOException %7B%0A            %0A            if (eof) %7B%0A                return -1;%0A            %7D%0A%0A            if (bytes.length - lastPosition %3C= byteBuffer.capacity()) %7B%0A                byteBuffer.put(bytes, lastPosition, bytes.length);%0A                eof = true;%0A            %7D else %7B%0A                byteBuffer.put(bytes, lastPosition, byteBuffer.capacity());%0A                lastPosition = bytes.length - byteBuffer.capacity();%0A            %7D%0A            return bytes.length;%0A        %7D%0A%0A        public void close() throws IOException %7B%0A            lastPosition = 0;%0A            eof = false;%0A        %7D%0A    %7D%0A%0A    public Body createBody() throws IOException %7B%0A        return new ByteBody();%0A    %7D%0A%7D%0A

Add a BodyGenerator backed by a byte array