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 2005/03/26 19:17:11 UTC
svn commit: r159115 -
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl
Author: olegk
Date: Sat Mar 26 10:17:08 2005
New Revision: 159115
URL: http://svn.apache.org/viewcvs?view=rev&rev=159115
Log:
NIO socket based implementations of HttpDataTransmitter and HttpDataReceiver
Added:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java (with props)
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java (with props)
Modified:
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataReceiver.java
jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataTransmitter.java
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataReceiver.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataReceiver.java?view=diff&r1=159114&r2=159115
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataReceiver.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataReceiver.java Sat Mar 26 10:17:08 2005
@@ -87,10 +87,14 @@
return chardecoder;
}
- private int fillBuffer() throws IOException {
+ protected int fillBuffer() throws IOException {
int i = this.channel.read(this.buffer);
this.buffer.flip();
return i;
+ }
+
+ protected boolean hasDataInBuffer() {
+ return this.buffer.hasRemaining();
}
public int read(final byte[] b, int off, int len) throws IOException {
Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataTransmitter.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataTransmitter.java?view=diff&r1=159114&r2=159115
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataTransmitter.java (original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOHttpDataTransmitter.java Sat Mar 26 10:17:08 2005
@@ -81,7 +81,7 @@
this.charset = Charset.forName(protocolParams.getHttpElementCharset());
}
- private void flushBuffer() throws IOException {
+ protected void flushBuffer() throws IOException {
this.buffer.flip();
this.channel.write(this.buffer);
this.buffer.compact();
Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java?view=auto&rev=159115
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java (added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java Sat Mar 26 10:17:08 2005
@@ -0,0 +1,84 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed 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.http.impl;
+
+import java.io.IOException;
+import java.net.Socket;
+import java.net.SocketException;
+import java.net.SocketTimeoutException;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ *
+ * @since 4.0
+ */
+public class NIOSocketHttpDataReceiver extends NIOHttpDataReceiver {
+
+ private final Socket socket;
+
+ private static Socket validate(final Socket socket) {
+ if (socket == null) {
+ throw new IllegalArgumentException("Socket may not be null");
+ }
+ if (socket.getChannel() == null) {
+ throw new IllegalArgumentException("Socket does not implement NIO channel");
+ }
+ return socket;
+ }
+
+ protected NIOSocketHttpDataReceiver(final Socket socket) throws SocketException {
+ super(validate(socket).getChannel(), socket.getReceiveBufferSize());
+ this.socket = socket;
+ }
+
+ public boolean isDataAvailable(int timeout) throws IOException {
+ if (hasDataInBuffer()) {
+ return true;
+ } else {
+ boolean result = false;
+ int oldtimeout = this.socket.getSoTimeout();
+ try {
+ this.socket.setSoTimeout(timeout);
+ fillBuffer();
+ result = true;
+ } catch (SocketTimeoutException e) {
+ // no data available
+ } finally {
+ socket.setSoTimeout(oldtimeout);
+ }
+ return result;
+ }
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataReceiver.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java?view=auto&rev=159115
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java (added)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java Sat Mar 26 10:17:08 2005
@@ -0,0 +1,63 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed 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.http.impl;
+
+import java.net.Socket;
+import java.net.SocketException;
+
+/**
+ * <p>
+ * </p>
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ *
+ * @since 4.0
+ */
+public class NIOSocketHttpDataTransmitter extends NIOHttpDataTransmitter {
+
+ private final Socket socket;
+
+ private static Socket validate(final Socket socket) {
+ if (socket == null) {
+ throw new IllegalArgumentException("Socket may not be null");
+ }
+ if (socket.getChannel() == null) {
+ throw new IllegalArgumentException("Socket does not implement NIO channel");
+ }
+ return socket;
+ }
+
+ protected NIOSocketHttpDataTransmitter(final Socket socket) throws SocketException {
+ super(validate(socket).getChannel(), socket.getSendBufferSize());
+ this.socket = socket;
+ }
+
+}
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/NIOSocketHttpDataTransmitter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain