You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2016/02/01 17:56:28 UTC
svn commit: r1727971 [1/2] - in /httpcomponents/httpcore/trunk: ./
httpcore5-h2/ httpcore5-h2/src/ httpcore5-h2/src/main/
httpcore5-h2/src/main/java/ httpcore5-h2/src/main/java/org/
httpcore5-h2/src/main/java/org/apache/ httpcore5-h2/src/main/java/org/...
Author: olegk
Date: Mon Feb 1 16:56:27 2016
New Revision: 1727971
URL: http://svn.apache.org/viewvc?rev=1727971&view=rev
Log:
HTTP frame primitives; session input / output buffers for blocking HTTP/2 connections
Added:
httpcomponents/httpcore/trunk/httpcore5-h2/
httpcomponents/httpcore/trunk/httpcore5-h2/pom.xml
- copied, changed from r1727970, httpcomponents/httpcore/trunk/httpcore5/pom.xml
httpcomponents/httpcore/trunk/httpcore5-h2/src/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2ConnectionException.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2CorruptFrameException.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2Error.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2StreamException.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/ByteBufferFrame.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/Frame.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameFlag.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameType.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/BasicHttp2TransportMetrics.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionInputBufferImpl.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionOutputBufferImpl.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/Http2TransportMetrics.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionInputBuffer.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionOutputBuffer.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Setting.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Settings.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/test/
httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/
httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/
httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/
httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/
httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/
httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/
httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/
httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/io/
httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/io/MultiByteArrayInputStream.java (with props)
httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/io/TestSessionInOutBuffers.java (with props)
Modified:
httpcomponents/httpcore/trunk/httpcore5/pom.xml
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionInputBuffer.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/io/SessionOutputBuffer.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/SessionInputBuffer.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/nio/SessionOutputBuffer.java
httpcomponents/httpcore/trunk/pom.xml
Copied: httpcomponents/httpcore/trunk/httpcore5-h2/pom.xml (from r1727970, httpcomponents/httpcore/trunk/httpcore5/pom.xml)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/pom.xml?p2=httpcomponents/httpcore/trunk/httpcore5-h2/pom.xml&p1=httpcomponents/httpcore/trunk/httpcore5/pom.xml&r1=1727970&r2=1727971&rev=1727971&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/pom.xml (original)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/pom.xml Mon Feb 1 16:56:27 2016
@@ -30,15 +30,20 @@
<artifactId>httpcore5-parent</artifactId>
<version>5.0-alpha2-SNAPSHOT</version>
</parent>
- <artifactId>httpcore5</artifactId>
- <name>Apache HttpComponents Core</name>
- <inceptionYear>2005</inceptionYear>
- <description>Apache HttpComponents Core</description>
+ <artifactId>httpcore5-h2</artifactId>
+ <name>Apache HttpComponents Core HTTP/2</name>
+ <description>Apache HttpComponents HTTP/2 core components</description>
<url>http://hc.apache.org/httpcomponents-core-ga</url>
<packaging>jar</packaging>
<dependencies>
<dependency>
+ <groupId>org.apache.httpcomponents.core5</groupId>
+ <artifactId>httpcore5</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
@@ -55,75 +60,10 @@
</dependency>
</dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.6</version>
- <executions>
- <execution>
- <goals>
- <goal>test-jar</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.rat</groupId>
- <artifactId>apache-rat-plugin</artifactId>
- <executions>
- <execution>
- <phase>verify</phase>
- <goals>
- <goal>check</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <excludes>
- <exclude>.externalToolBuilders/**</exclude>
- <exclude>.pmd</exclude>
- <exclude>maven-eclipse.xml</exclude>
- </excludes>
- </configuration>
- </plugin>
- </plugins>
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- <filtering>true</filtering>
- <includes>
- <include>**/*.properties</include>
- </includes>
- </resource>
- </resources>
- </build>
-
<reporting>
<plugins>
<plugin>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>${hc.javadoc.version}</version>
- <configuration>
- <!-- reduce console output. Can override with -Dquiet=false -->
- <quiet>true</quiet>
- <source>${maven.compiler.source}</source>
- <links>
- <link>http://docs.oracle.com/javase/7/docs/api/</link>
- </links>
- </configuration>
- <reportSets>
- <reportSet>
- <reports>
- <report>javadoc</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
-
- <plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>${hc.project-info.version}</version>
<inherited>false</inherited>
@@ -138,16 +78,6 @@
</reportSets>
</plugin>
- <plugin>
- <artifactId>maven-jxr-plugin</artifactId>
- <version>${hc.jxr.version}</version>
- </plugin>
-
- <plugin>
- <artifactId>maven-surefire-report-plugin</artifactId>
- <version>${hc.surefire-report.version}</version>
- </plugin>
-
</plugins>
</reporting>
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2ConnectionException.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2ConnectionException.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2ConnectionException.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2ConnectionException.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,62 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2;
+
+import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.util.Args;
+
+public class H2ConnectionException extends ProtocolException {
+
+ private static final long serialVersionUID = -2014204317155428658L;
+
+ private final int code;
+ private final long streamId;
+
+ public H2ConnectionException(final H2Error error, final long streamId, final String message) {
+ super(message);
+ Args.notNull(error, "H2 Error code may not be null");
+ Args.positive(streamId, "H2 stream id may not be negative or zero");
+ this.code = error.getCode();
+ this.streamId = streamId;
+ }
+
+ public H2ConnectionException(final int code, final long streamId, final String message) {
+ super(message);
+ Args.positive(streamId, "H2 stream id may not be negative or zero");
+ this.code = code;
+ this.streamId = streamId;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public long getStreamId() {
+ return streamId;
+ }
+
+};
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2ConnectionException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2ConnectionException.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2ConnectionException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2CorruptFrameException.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2CorruptFrameException.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2CorruptFrameException.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2CorruptFrameException.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,37 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2;
+
+import java.io.IOException;
+
+public class H2CorruptFrameException extends IOException {
+
+ public H2CorruptFrameException(final String message) {
+ super(message);
+ }
+
+};
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2CorruptFrameException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2CorruptFrameException.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2CorruptFrameException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2Error.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2Error.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2Error.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2Error.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,141 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2;
+
+public enum H2Error {
+
+ /**
+ * Graceful shutdown
+ * <p>
+ * The associated condition is not as a result of an error.
+ */
+ NO_ERROR (0x00),
+
+ /**
+ * Protocol error detected
+ * <p>
+ * The endpoint detected an unspecific protocol error. This error is for use when a more
+ * specific error code is not available
+ */
+ PROTOCOL_ERROR (0x01),
+
+ /**
+ * Implementation fault
+ * <p>
+ * The endpoint encountered an unexpected internal error.
+ */
+ INTERNAL_ERROR (0x02),
+
+ /**
+ * Flow control limits exceeded.
+ * <p>
+ * The endpoint detected that its peer violated the flow control protocol.
+ */
+ FLOW_CONTROL_ERROR (0x03),
+
+ /**
+ * Settings not acknowledged.
+ * <p>
+ * The endpoint sent a SETTINGS frame, but did not receive a response in a timely manner.
+ */
+ SETTINGS_TIMEOUT (0x04),
+
+ /**
+ * Frame received for closed stream.
+ * <p>
+ * The endpoint received a frame after a stream was half closed.
+ */
+ STREAM_CLOSED (0x05),
+
+ /**
+ * Frame size incorrect.
+ * <p>
+ * The endpoint received a frame with an invalid size.
+ */
+ FRAME_SIZE_ERROR (0x06),
+
+ /**
+ * Stream not processed
+ * <p>
+ * The endpoint refuses the stream prior to performing any application processing.
+ */
+ REFUSED_STREAM (0x07),
+
+ /**
+ * Stream canceled.
+ * <p>
+ * Used by the endpoint to indicate that the stream is no longer needed
+ */
+ CANCEL (0x08),
+
+ /**
+ * Compression state not updated.
+ * <p>
+ * The endpoint is unable to maintain the header compression context for the connection.
+ */
+ COMPRESSION_ERROR (0x09),
+
+ /**
+ * TCP connection error.
+ * <p>
+ * The connection established in response to a CONNECT request was reset or abnormally closed.
+ */
+ CONNECT_ERROR (0x0a),
+
+ /**
+ * Processing capacity exceeded.
+ * <p>
+ * The endpoint detected that its peer is exhibiting a behavior that might be generating
+ * excessive load.
+ */
+ ENHANCE_YOUR_CALM (0x0b),
+
+ /**
+ * Negotiated TLS parameters not acceptable.
+ * <p>
+ * The underlying transport has properties that do not meet minimum security requirements.
+ */
+ INADEQUATE_SECURITY (0x0c),
+
+ /**
+ * Use HTTP/1.1 for the request.
+ * <p>
+ * The endpoint requires that HTTP/1.1 be used instead of HTTP/2.
+ */
+ HTTP_1_1_REQUIRED (0x0d);
+
+ int code;
+
+ H2Error(final int code) {
+ this.code = code;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+};
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2Error.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2Error.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2Error.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2StreamException.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2StreamException.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2StreamException.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2StreamException.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,62 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2;
+
+import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.util.Args;
+
+public class H2StreamException extends ProtocolException {
+
+ private static final long serialVersionUID = 6321637486572232180L;
+
+ private final int code;
+ private final long streamId;
+
+ public H2StreamException(final H2Error error, final long streamId, final String message) {
+ super(message);
+ Args.notNull(error, "H2 Error code may not be null");
+ Args.positive(streamId, "H2 stream id may not be negative or zero");
+ this.code = error.getCode();
+ this.streamId = streamId;
+ }
+
+ public H2StreamException(final int code, final long streamId, final String message) {
+ super(message);
+ Args.positive(streamId, "H2 stream id may not be negative or zero");
+ this.code = code;
+ this.streamId = streamId;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public long getStreamId() {
+ return streamId;
+ }
+
+};
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2StreamException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2StreamException.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/H2StreamException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/ByteBufferFrame.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/ByteBufferFrame.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/ByteBufferFrame.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/ByteBufferFrame.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,45 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2.frame;
+
+import java.nio.ByteBuffer;
+
+public final class ByteBufferFrame extends Frame<ByteBuffer> {
+
+ private final ByteBuffer payload;
+
+ public ByteBufferFrame(final int type, final int flags, final long streamId, final ByteBuffer payload) {
+ super(type, flags, streamId);
+ this.payload = payload;
+ }
+
+ @Override
+ public ByteBuffer getPayload() {
+ return payload;
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/ByteBufferFrame.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/ByteBufferFrame.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/ByteBufferFrame.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/Frame.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/Frame.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/Frame.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/Frame.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,74 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2.frame;
+
+public abstract class Frame<T> {
+
+ private final int type;
+ private final int flags;
+ private final long streamId;
+
+ public Frame(final int type, final int flags, final long streamId) {
+ this.type = type;
+ this.flags = flags;
+ this.streamId = streamId;
+ }
+
+ public boolean isType(final FrameType type) {
+ return getType() == type.value;
+ }
+
+ public boolean isFlagSet(final FrameFlag flag) {
+ return (getFlags() & flag.value) != 0;
+ }
+
+ public int getType() {
+ return type;
+ }
+
+ public int getFlags() {
+ return flags;
+ }
+
+ public long getStreamId() {
+ return streamId;
+ }
+
+ public abstract T getPayload();
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("[");
+ sb.append("type=").append(type);
+ sb.append(", flags=").append(flags);
+ sb.append(", streamId=").append(streamId);
+ sb.append(", payoad=").append(getPayload());
+ sb.append(']');
+ return sb.toString();
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/Frame.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/Frame.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/Frame.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,34 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2.frame;
+
+public final class FrameConsts {
+
+ public final static int HEAD_LEN = 9;
+ public final static int MAX_PADDING = 255;
+
+};
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameConsts.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameFlag.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameFlag.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameFlag.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameFlag.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,55 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2.frame;
+
+public enum FrameFlag {
+
+ END_STREAM (0x01),
+ ACK (0x01),
+ END_HEADERS (0x04),
+ PADDED (0x08),
+ PRIORITY (0x20);
+
+ int value;
+
+ FrameFlag(final int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public static int of(final FrameFlag... flags) {
+ int value = 0;
+ for (FrameFlag flag: flags) {
+ value |= flag.value;
+ }
+ return value;
+ }
+
+};
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameFlag.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameFlag.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameFlag.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameType.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameType.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameType.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameType.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,66 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2.frame;
+
+public enum FrameType {
+
+ DATA (0x00),
+ HEADERS (0x01),
+ PRIORITY (0x02),
+ RST_STREAM (0x03),
+ SETTINGS (0x04),
+ PUSH_PROMISE (0x05),
+ PING (0x06),
+ GOAWAY (0x07),
+ WINDOW_UPDATE (0x08),
+ CONTINUATION (0x09);
+
+ int value;
+
+ FrameType(final int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ private static final FrameType[] LOOKUP_TABLE = new FrameType[10];
+ static {
+ for (FrameType frameType: FrameType.values()) {
+ LOOKUP_TABLE[frameType.value] = frameType;
+ }
+ }
+
+ public static FrameType valueOf(final int value) {
+ if (value < 0 || value >= LOOKUP_TABLE.length) {
+ return null;
+ }
+ return LOOKUP_TABLE[value];
+ }
+
+};
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameType.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameType.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/frame/FrameType.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/BasicHttp2TransportMetrics.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/BasicHttp2TransportMetrics.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/BasicHttp2TransportMetrics.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/BasicHttp2TransportMetrics.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,59 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.impl;
+
+import org.apache.hc.core5.annotation.NotThreadSafe;
+import org.apache.hc.core5.http.impl.BasicHttpTransportMetrics;
+import org.apache.hc.core5.http2.io.Http2TransportMetrics;
+
+/**
+ * Default implementation of {@link Http2TransportMetrics}.
+ *
+ * @since 5.0
+ */
+@NotThreadSafe
+public class BasicHttp2TransportMetrics extends BasicHttpTransportMetrics implements Http2TransportMetrics {
+
+ private long framesTransferred;
+
+ @Override
+ public long getFramesTransferred() {
+ return framesTransferred;
+ }
+
+ public void incrementFramesTransferred() {
+ framesTransferred++;
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ this.framesTransferred = 0;
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/BasicHttp2TransportMetrics.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/BasicHttp2TransportMetrics.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/BasicHttp2TransportMetrics.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionInputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionInputBufferImpl.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionInputBufferImpl.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionInputBufferImpl.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,146 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.impl.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+
+import org.apache.hc.core5.annotation.NotThreadSafe;
+import org.apache.hc.core5.http.ConnectionClosedException;
+import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.http2.H2ConnectionException;
+import org.apache.hc.core5.http2.H2CorruptFrameException;
+import org.apache.hc.core5.http2.H2Error;
+import org.apache.hc.core5.http2.frame.ByteBufferFrame;
+import org.apache.hc.core5.http2.frame.Frame;
+import org.apache.hc.core5.http2.frame.FrameConsts;
+import org.apache.hc.core5.http2.frame.FrameFlag;
+import org.apache.hc.core5.http2.impl.BasicHttp2TransportMetrics;
+import org.apache.hc.core5.http2.io.Http2TransportMetrics;
+import org.apache.hc.core5.http2.io.SessionInputBuffer;
+import org.apache.hc.core5.util.Args;
+
+/**
+ *
+ * @since 5.0
+ */
+@NotThreadSafe
+public class SessionInputBufferImpl implements SessionInputBuffer {
+
+ private final BasicHttp2TransportMetrics metrics;
+ private final int maxFramePayloadSize;
+ private final byte[] buffer;
+
+ private int off;
+ private int dataLen;
+
+ SessionInputBufferImpl(final BasicHttp2TransportMetrics metrics, final int bufferLen, final int maxFramePayloadSize) {
+ Args.notNull(metrics, "HTTP2 transport metrcis");
+ Args.positive(maxFramePayloadSize, "Buffer size");
+ this.metrics = metrics;
+ this.maxFramePayloadSize = maxFramePayloadSize;
+ this.buffer = new byte[bufferLen];
+ this.dataLen = 0;
+ }
+
+ public SessionInputBufferImpl(final BasicHttp2TransportMetrics metrics, final int maxFramePayloadSize) {
+ this(metrics, FrameConsts.HEAD_LEN + maxFramePayloadSize + FrameConsts.MAX_PADDING + 1, maxFramePayloadSize);
+ }
+
+ public SessionInputBufferImpl(final int maxFramePayloadSize) {
+ this(new BasicHttp2TransportMetrics(), maxFramePayloadSize);
+ }
+
+ private void fillBuffer(final InputStream instream, final int requiredLen)throws IOException {
+ while (dataLen < requiredLen) {
+ if (off > 0) {
+ System.arraycopy(buffer, off, buffer, 0, dataLen);
+ off = 0;
+ }
+ final int bytesRead = instream.read(buffer, off + dataLen, buffer.length - dataLen);
+ if (bytesRead == -1) {
+ if (dataLen > 0) {
+ throw new H2CorruptFrameException("Corrupt or incomplete HTTP2 frame");
+ } else {
+ throw new ConnectionClosedException("Connection closed");
+ }
+ } else {
+ dataLen += bytesRead;
+ this.metrics.incrementBytesTransferred(bytesRead);
+ }
+ }
+ }
+
+ public Frame<ByteBuffer> readFrame(final InputStream instream) throws ProtocolException, IOException {
+
+ fillBuffer(instream, FrameConsts.HEAD_LEN);
+ int payloadOff = FrameConsts.HEAD_LEN;
+
+ final int payloadLen = (buffer[off] & 0xff) << 16 | (buffer[off + 1] & 0xff) << 8 | (buffer[off + 2] & 0xff);
+ final int type = buffer[off + 3] & 0xff;
+ final int flags = buffer[off + 4] & 0xff;
+ final long streamId = (buffer[off + 5] & 0xff) << 24 | (buffer[off + 6] & 0xff << 16) | (buffer[off + 7] & 0xff) << 8 | (buffer[off + 8] & 0xff);
+ if (payloadLen > maxFramePayloadSize) {
+ throw new H2ConnectionException(H2Error.FRAME_SIZE_ERROR, streamId, "Frame size exceeds maximum");
+ }
+
+ final int padding;
+ if ((flags & FrameFlag.PADDED.getValue()) == 0) {
+ padding = 0;
+ } else {
+ fillBuffer(instream, FrameConsts.HEAD_LEN + 1);
+ payloadOff = FrameConsts.HEAD_LEN + 1;
+ padding = (buffer[off + 9] & 0xff);
+ }
+
+ final int frameLen = payloadOff + payloadLen + padding;
+ fillBuffer(instream, frameLen);
+
+ final ByteBuffer payload;
+ if (payloadLen > 0) {
+ payload = ByteBuffer.wrap(buffer, off + payloadOff, payloadLen).asReadOnlyBuffer();
+ } else {
+ payload = null;
+ }
+
+ final ByteBufferFrame frame = new ByteBufferFrame(type, flags, streamId, payload);
+
+ off += frameLen;
+ dataLen -= frameLen;
+
+ this.metrics.incrementFramesTransferred();
+
+ return frame;
+ }
+
+ public Http2TransportMetrics getMetrics() {
+ return metrics;
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionInputBufferImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionInputBufferImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionInputBufferImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionOutputBufferImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionOutputBufferImpl.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionOutputBufferImpl.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionOutputBufferImpl.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,119 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.impl.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+
+import org.apache.hc.core5.annotation.NotThreadSafe;
+import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.http2.H2ConnectionException;
+import org.apache.hc.core5.http2.H2Error;
+import org.apache.hc.core5.http2.frame.Frame;
+import org.apache.hc.core5.http2.frame.FrameConsts;
+import org.apache.hc.core5.http2.frame.FrameFlag;
+import org.apache.hc.core5.http2.impl.BasicHttp2TransportMetrics;
+import org.apache.hc.core5.http2.io.Http2TransportMetrics;
+import org.apache.hc.core5.http2.io.SessionOutputBuffer;
+import org.apache.hc.core5.util.Args;
+
+/**
+ * Session output buffer for HTTP/2 blocking connections.
+ *
+ * @since 5.0
+ */
+@NotThreadSafe
+public class SessionOutputBufferImpl implements SessionOutputBuffer {
+
+ private final BasicHttp2TransportMetrics metrics;
+ private final int maxFramePayloadSize;
+ private final byte[] buffer;
+
+ public SessionOutputBufferImpl(final BasicHttp2TransportMetrics metrics, final int maxFramePayloadSize) {
+ super();
+ Args.notNull(metrics, "HTTP2 transport metrcis");
+ Args.positive(maxFramePayloadSize, "Buffer size");
+ this.metrics = metrics;
+ this.maxFramePayloadSize = maxFramePayloadSize;
+ this.buffer = new byte[FrameConsts.HEAD_LEN + maxFramePayloadSize + FrameConsts.MAX_PADDING + 1];
+ }
+
+ public SessionOutputBufferImpl(final int maxFramePayloadSize) {
+ this(new BasicHttp2TransportMetrics(), maxFramePayloadSize);
+ }
+
+ public void write(final Frame<ByteBuffer> frame, final OutputStream outstream) throws ProtocolException, IOException {
+ if (frame == null) {
+ return;
+ }
+ final int type = frame.getType();
+ final long streamId = frame.getStreamId();
+ final int flags = frame.getFlags();
+ final ByteBuffer payload = frame.getPayload();
+ final int payloadLen = payload != null ? payload.remaining() : 0;
+ if (payload != null && payload.remaining() > maxFramePayloadSize) {
+ throw new H2ConnectionException(H2Error.FRAME_SIZE_ERROR, streamId, "Frame size exceeds maximum");
+ }
+ buffer[0] = (byte) (payloadLen >> 16 & 0xff);
+ buffer[1] = (byte) (payloadLen >> 8 & 0xff);
+ buffer[2] = (byte) (payloadLen & 0xff);
+
+ buffer[3] = (byte) (type & 0xff);
+ buffer[4] = (byte) (flags & 0xff);
+
+ buffer[5] = (byte) (streamId >> 24 & 0xff);
+ buffer[6] = (byte) (streamId >> 16 & 0xff);
+ buffer[7] = (byte) (streamId >> 8 & 0xff);;
+ buffer[8] = (byte) (streamId & 0xff);
+
+ int frameLen = FrameConsts.HEAD_LEN;
+ int padding = 0;
+ if ((flags & FrameFlag.PADDED.getValue()) > 0) {
+ padding = 16;
+ buffer[9] = (byte) (padding & 0xff);
+ frameLen++;
+ }
+ if (payload != null) {
+ payload.get(buffer, frameLen, payload.remaining());
+ frameLen += payloadLen;
+ }
+ for (int i = 0; i < padding; i++) {
+ buffer[frameLen++] = 0;
+ }
+ outstream.write(buffer, 0, frameLen);
+
+ metrics.incrementFramesTransferred();
+ metrics.incrementBytesTransferred(frameLen);
+ }
+
+ public Http2TransportMetrics getMetrics() {
+ return metrics;
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionOutputBufferImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionOutputBufferImpl.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/impl/io/SessionOutputBufferImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/Http2TransportMetrics.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/Http2TransportMetrics.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/Http2TransportMetrics.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/Http2TransportMetrics.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,41 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.io;
+
+import org.apache.hc.core5.http.io.HttpTransportMetrics;
+
+/**
+ * The point of access to connection statistics.
+ *
+ * @since 5.0
+ */
+public interface Http2TransportMetrics extends HttpTransportMetrics {
+
+ long getFramesTransferred();
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/Http2TransportMetrics.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/Http2TransportMetrics.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/Http2TransportMetrics.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionInputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionInputBuffer.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionInputBuffer.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionInputBuffer.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,50 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+
+import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.http2.frame.Frame;
+
+/**
+ * Session input buffer for HTTP/2 blocking connections.
+ * <p>
+ * This interface provides methods for reading HTTP frames.
+ *
+ * @since 5.0
+ */
+public interface SessionInputBuffer {
+
+ Frame<ByteBuffer> readFrame(InputStream instream) throws ProtocolException, IOException;
+
+ Http2TransportMetrics getMetrics();
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionInputBuffer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionInputBuffer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionInputBuffer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionOutputBuffer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionOutputBuffer.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionOutputBuffer.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionOutputBuffer.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,50 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+
+import org.apache.hc.core5.http.ProtocolException;
+import org.apache.hc.core5.http2.frame.Frame;
+
+/**
+ * Session output buffer for HTTP/2 blocking connections.
+ * <p>
+ * This interface provides methods for writing out HTTP frames.
+ *
+ * @since 5.0
+ */
+public interface SessionOutputBuffer {
+
+ void write(Frame<ByteBuffer> frame, OutputStream outstream) throws ProtocolException, IOException;
+
+ Http2TransportMetrics getMetrics();
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionOutputBuffer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionOutputBuffer.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/io/SessionOutputBuffer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Setting.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Setting.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Setting.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Setting.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,78 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2.setting;
+
+import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.LangUtils;
+
+public final class H2Setting {
+
+ private final int code;
+ private final long value;
+
+ public H2Setting(final int code, final long value) {
+ Args.positive(code, "Setting code must be a positive value");
+ Args.notNegative(value, "Setting value must be a non-negative value");
+ this.code = code;
+ this.value = value;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public long getValue() {
+ return value;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof H2Setting) {
+ final H2Setting that = (H2Setting) obj;
+ return this.code == that.code;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = LangUtils.HASH_SEED;
+ hash = LangUtils.hashCode(hash, this.code);
+ return hash;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder()
+ .append("[").append(code).append(":").append(value).append(']');
+ return sb.toString();
+ }
+};
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Setting.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Setting.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Setting.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Settings.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Settings.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Settings.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Settings.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,55 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http2.setting;
+
+public enum H2Settings {
+
+ HEADER_TABLE_SIZE (0x1, 4096),
+ ENABLE_PUSH (0x2, 1),
+ MAX_CONCURRENT_STREAMS (0x3, Long.MAX_VALUE),
+ INITIAL_WINDOW_SIZE (0x4, 65535),
+ MAX_FRAME_SIZE (0x5, 16384),
+ MAX_HEADER_LIST_SIZE (0x6, Long.MAX_VALUE);
+
+ int code;
+
+ long initialValue;
+
+ H2Settings(final int code, final long initialValue) {
+ this.code = code;
+ this.initialValue = initialValue;
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public long getInitialValue() {
+ return initialValue;
+ }
+
+};
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Settings.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Settings.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/main/java/org/apache/hc/core5/http2/setting/H2Settings.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/io/MultiByteArrayInputStream.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/io/MultiByteArrayInputStream.java?rev=1727971&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/io/MultiByteArrayInputStream.java (added)
+++ httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/io/MultiByteArrayInputStream.java Mon Feb 1 16:56:27 2016
@@ -0,0 +1,115 @@
+/*
+ * ====================================================================
+ * 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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.hc.core5.http2.impl.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayDeque;
+import java.util.Queue;
+
+class MultiByteArrayInputStream extends InputStream {
+
+ private final Queue<byte[]> bufs;
+ private byte[] current;
+ private int pos;
+
+ public MultiByteArrayInputStream(final byte[]... bufs) {
+ super();
+ this.bufs = new ArrayDeque<>();
+ for (byte[] buf: bufs) {
+ if (buf.length > 0) {
+ this.bufs.add(buf);
+ }
+ }
+ }
+
+ private void advance() {
+ if (this.current != null) {
+ if (this.pos >= this.current.length) {
+ this.current = null;
+ }
+ }
+ if (this.current == null) {
+ this.current = this.bufs.poll();
+ this.pos = 0;
+ }
+ }
+
+ @Override
+ public int read() throws IOException {
+ advance();
+ if (this.current == null) {
+ return -1;
+ }
+ return this.current[this.pos++];
+ }
+
+ @Override
+ public int read(final byte b[], final int off, final int len) throws IOException {
+ if (b == null) {
+ throw new NullPointerException();
+ } else if ((off < 0) || (off > b.length) || (len < 0) ||
+ ((off + len) > b.length) || ((off + len) < 0)) {
+ throw new IndexOutOfBoundsException();
+ }
+ advance();
+ if (this.current == null) {
+ return -1;
+ }
+ final int chunk = Math.min(this.current.length - this.pos, len);
+ if (chunk <= 0) {
+ return 0;
+ }
+ System.arraycopy(this.current, this.pos, b, off, chunk);
+ this.pos += chunk;
+ return chunk;
+ }
+
+ @Override
+ public long skip(final long n) {
+ advance();
+ final int chunk = Math.min(this.current.length - this.pos, (int) n);
+ if (chunk <= 0) {
+ return 0;
+ }
+ this.pos += chunk;
+ return chunk;
+ }
+
+ @Override
+ public int available() {
+ advance();
+ return this.current != null ? this.current.length - this.pos : 0;
+ }
+
+ @Override
+ public boolean markSupported() {
+ return false;
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/io/MultiByteArrayInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/io/MultiByteArrayInputStream.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore5-h2/src/test/java/org/apache/hc/core5/http2/impl/io/MultiByteArrayInputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain