You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sm...@apache.org on 2006/05/19 08:00:56 UTC
svn commit: r407724 [9/11] - in /incubator/harmony/enhanced/classlib/trunk:
make/ modules/rmi/make/ modules/rmi/src/main/java/java/rmi/
modules/rmi/src/main/java/java/rmi/registry/
modules/rmi/src/main/java/java/rmi/server/ modules/rmi/src/main/java/or...
Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpInputStream.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpInputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpInputStream.java Thu May 18 23:00:52 2006
@@ -1,307 +1,307 @@
-/*
-* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
-*
-* 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.
-*/
-package ar.org.fitc.rmi.transport.http;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * This class is used for client and server purposes. <br>
- * Implements a byte array stream in which the data is read. On the other side,
- * the constructor receive a socket's input stream. <br>
- * Fills only once the internal buffer of the wrapped input stream (at the time
- * that requeries any operation from it) with the http's content and delegates the
- * all the calls to such input stream.
- *
- * @author Diego Raúl Mercado
- */
-abstract class HttpInputStream extends InputStream {
-
- /** Exposed buffer */
- private byte[] buffer;
-
- /** Available int to read */
- private int available;
-
- /** Wrapped ByteArrayInputStream */
- private ByteArrayInputStream bais;
-
- /** Indicates CARRY-RETURN */
- private static final int CR = 0xa;
-
- /** Indicates LINE-FEEDBACK */
- private static final int LF = 0xd;
-
- /** Stores the header's value that has been parsed */
- private Map<HttpHeaders, String> headers;
-
- /** If true, indicates that the buffer has been filled */
- private boolean isBufferFilled;
-
- /** The socket's input stream */
- private InputStream socketInputStream;
-
- /** The path that is specified in the request line */
- protected String requestPath;
-
- /**
- * Statically stores the exception that may thrown if cannot parse the
- * http's headers
- */
- protected static final IOException HEADERS_EXCEPTION = new IOException(
- "Cannot parse http headers");
-
- /**
- * Initializes the inherit's buffer and the map <code>headers</code>.
- * Then, calls <code>fillBuffer()</code> method
- *
- * @param is
- * the socket's input stream
- */
- public HttpInputStream(InputStream is) {
- headers = new ConcurrentHashMap<HttpHeaders, String>();
- isBufferFilled = false;
- socketInputStream = is;
- }
-
- /**
- * Parses any http's headers and fill the inherits' buffer with the http's
- * content
- *
- * @throws IOException
- * if an I/O exception ocurrs or cannot parse the http's header
- */
- private synchronized final void fillBuffer() throws IOException {
- if (isBufferFilled == false) {
- String line;
- String value;
- boolean isCRLFPresent = false;
- int contentLength = 0;
-
- /*
- * READ REQUEST/STATUS LINE
- */
-
- line = readLine(socketInputStream).trim();
- readFirstLine(line);
-
- /*
- * READ HEADERS
- */
- while ((line = readLine(socketInputStream).trim()) != null) {
- if (line.equals("")) { // if CRLF
- isCRLFPresent = true;
-
- // contentLength
- value = headers.get(HttpHeaders.CONTENT_LENGTH_HEADER);
- if (value == null) {
- contentLength = socketInputStream.available();
- } else {
- contentLength = Integer.parseInt(value);
- if (contentLength < 0) {
- throw HEADERS_EXCEPTION;
- }
- }
-
- break;
- }
-
- if (!line.contains(":")) {
- throw HEADERS_EXCEPTION;
- }
- putValueInHeader(headers, line.substring(0,
- line.indexOf(":")).trim(), // header
- (line.substring(line.indexOf(":") + 1)).trim()); // value
- }
-
- if (!isCRLFPresent) {
- throw new IOException("HTTP POST must have content");
- }
-
- /*
- * READ BODY
- */
-
- int readCount = contentLength;
- byte[] bytes = new byte[readCount];
- int temp = readCount;
- while (readCount > 0) {
- bytes[temp - readCount] = (byte) socketInputStream.read();
- readCount--;
- }
-
- // Initializes the buffer of the wrapped input stream
- buffer = new byte[contentLength];
- bais = new ByteArrayInputStream(buffer);
-
- // copy the content into the buffer
- System.arraycopy(bytes, 0, buffer, 0, bytes.length);
- available = bytes.length;
- isBufferFilled = true;
- }
- }
-
- /**
- * If the header is a known Enum then inserts into <code>headers</code>
- * its <code>value</code> with the correspondent HttpHeaders' type as key
- *
- * @param headers
- * the name of the Enum
- * @param header
- * the key to add
- * @param value
- * the value of the Header
- */
- private static final void putValueInHeader(Map<HttpHeaders, String> headers,
- String header, String value) {
- HttpHeaders hc = HttpHeaders.getEnum(header);
- if (hc != null) {
- // recognized type..
- headers.put(hc, value);
- }
- }
-
- /**
- * Reads a line from this <code>is<code> and returns it
- *
- * @param is
- * the socket's input stream
- * @return
- * a line from this <code>is<code>
- * @throws IOException
- * If cannot read an CRLF
- */
- private static final String readLine(InputStream is) throws IOException {
- StringBuilder sb = new StringBuilder();
- int actual;
- int last = is.read();
-
- while ((actual = is.read()) != -1) {
- if (last == LF && actual == CR) {
- return sb.toString();
- }
- sb.append((char) last);
- last = actual;
- }
- throw HEADERS_EXCEPTION;
- }
-
- /**
- * This method must be overriden in order to parse the first line (status/request
- * line) of the http's header because the behaviour differs if it's a client or
- * server socket side
- *
- * @param line the line that has been read from this inputstream
- */
- protected abstract void readFirstLine(String line) throws IOException;
-
- /**
- * @return the path that has been specified in the http's status/request
- * line
- */
- public final String getRequestPath() {
- return requestPath;
- }
-
- @Override
- public final int available() throws IOException {
- fillBuffer();
- return available;
- }
-
- @Override
- public final void close() throws IOException {
- fillBuffer();
- bais.close();
- }
-
- @Override
- public final void mark(int arg0) {
- bais.mark(arg0);
- }
-
- @Override
- public final boolean markSupported() {
- return bais.markSupported();
- }
-
- @Override
- public final void reset() throws IOException {
- fillBuffer();
- bais.reset();
- }
-
- @Override
- public final long skip(long arg0) throws IOException {
- fillBuffer();
- return bais.skip(arg0);
- }
-
- /**
- * @throws IOException
- * @ar.org.fitc.spec_ref
- */
- @Override
- public synchronized final int read() throws IOException {
- fillBuffer();
- if (available == 0) {
- try {
- wait();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- available--;
- if (available > 0) {
- notify();
- }
- return bais.read();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final int read(byte[] arg0) throws IOException {
- return read(arg0, 0, arg0.length);
- }
-
- /**
- * @throws IOException
- * @ar.org.fitc.spec_ref
- */
- @Override
- public synchronized final int read(byte[] arg0, int arg1, int arg2)
- throws IOException {
- fillBuffer();
- if (available == 0) {
- try {
- wait();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
- if (available > 0) {
- notify();
- }
- int bytesRead = bais.read(arg0, arg1, arg2);
- available -= bytesRead;
- return bytesRead;
- }
+/*
+* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+*
+* 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.
+*/
+package org.apache.harmony.rmi.internal.transport.http;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * This class is used for client and server purposes. <br>
+ * Implements a byte array stream in which the data is read. On the other side,
+ * the constructor receive a socket's input stream. <br>
+ * Fills only once the internal buffer of the wrapped input stream (at the time
+ * that requeries any operation from it) with the http's content and delegates the
+ * all the calls to such input stream.
+ *
+ * @author Diego Raúl Mercado
+ */
+abstract class HttpInputStream extends InputStream {
+
+ /** Exposed buffer */
+ private byte[] buffer;
+
+ /** Available int to read */
+ private int available;
+
+ /** Wrapped ByteArrayInputStream */
+ private ByteArrayInputStream bais;
+
+ /** Indicates CARRY-RETURN */
+ private static final int CR = 0xa;
+
+ /** Indicates LINE-FEEDBACK */
+ private static final int LF = 0xd;
+
+ /** Stores the header's value that has been parsed */
+ private Map<HttpHeaders, String> headers;
+
+ /** If true, indicates that the buffer has been filled */
+ private boolean isBufferFilled;
+
+ /** The socket's input stream */
+ private InputStream socketInputStream;
+
+ /** The path that is specified in the request line */
+ protected String requestPath;
+
+ /**
+ * Statically stores the exception that may thrown if cannot parse the
+ * http's headers
+ */
+ protected static final IOException HEADERS_EXCEPTION = new IOException(
+ "Cannot parse http headers");
+
+ /**
+ * Initializes the inherit's buffer and the map <code>headers</code>.
+ * Then, calls <code>fillBuffer()</code> method
+ *
+ * @param is
+ * the socket's input stream
+ */
+ public HttpInputStream(InputStream is) {
+ headers = new ConcurrentHashMap<HttpHeaders, String>();
+ isBufferFilled = false;
+ socketInputStream = is;
+ }
+
+ /**
+ * Parses any http's headers and fill the inherits' buffer with the http's
+ * content
+ *
+ * @throws IOException
+ * if an I/O exception ocurrs or cannot parse the http's header
+ */
+ private synchronized final void fillBuffer() throws IOException {
+ if (isBufferFilled == false) {
+ String line;
+ String value;
+ boolean isCRLFPresent = false;
+ int contentLength = 0;
+
+ /*
+ * READ REQUEST/STATUS LINE
+ */
+
+ line = readLine(socketInputStream).trim();
+ readFirstLine(line);
+
+ /*
+ * READ HEADERS
+ */
+ while ((line = readLine(socketInputStream).trim()) != null) {
+ if (line.equals("")) { // if CRLF
+ isCRLFPresent = true;
+
+ // contentLength
+ value = headers.get(HttpHeaders.CONTENT_LENGTH_HEADER);
+ if (value == null) {
+ contentLength = socketInputStream.available();
+ } else {
+ contentLength = Integer.parseInt(value);
+ if (contentLength < 0) {
+ throw HEADERS_EXCEPTION;
+ }
+ }
+
+ break;
+ }
+
+ if (!line.contains(":")) {
+ throw HEADERS_EXCEPTION;
+ }
+ putValueInHeader(headers, line.substring(0,
+ line.indexOf(":")).trim(), // header
+ (line.substring(line.indexOf(":") + 1)).trim()); // value
+ }
+
+ if (!isCRLFPresent) {
+ throw new IOException("HTTP POST must have content");
+ }
+
+ /*
+ * READ BODY
+ */
+
+ int readCount = contentLength;
+ byte[] bytes = new byte[readCount];
+ int temp = readCount;
+ while (readCount > 0) {
+ bytes[temp - readCount] = (byte) socketInputStream.read();
+ readCount--;
+ }
+
+ // Initializes the buffer of the wrapped input stream
+ buffer = new byte[contentLength];
+ bais = new ByteArrayInputStream(buffer);
+
+ // copy the content into the buffer
+ System.arraycopy(bytes, 0, buffer, 0, bytes.length);
+ available = bytes.length;
+ isBufferFilled = true;
+ }
+ }
+
+ /**
+ * If the header is a known Enum then inserts into <code>headers</code>
+ * its <code>value</code> with the correspondent HttpHeaders' type as key
+ *
+ * @param headers
+ * the name of the Enum
+ * @param header
+ * the key to add
+ * @param value
+ * the value of the Header
+ */
+ private static final void putValueInHeader(Map<HttpHeaders, String> headers,
+ String header, String value) {
+ HttpHeaders hc = HttpHeaders.getEnum(header);
+ if (hc != null) {
+ // recognized type..
+ headers.put(hc, value);
+ }
+ }
+
+ /**
+ * Reads a line from this <code>is<code> and returns it
+ *
+ * @param is
+ * the socket's input stream
+ * @return
+ * a line from this <code>is<code>
+ * @throws IOException
+ * If cannot read an CRLF
+ */
+ private static final String readLine(InputStream is) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ int actual;
+ int last = is.read();
+
+ while ((actual = is.read()) != -1) {
+ if (last == LF && actual == CR) {
+ return sb.toString();
+ }
+ sb.append((char) last);
+ last = actual;
+ }
+ throw HEADERS_EXCEPTION;
+ }
+
+ /**
+ * This method must be overriden in order to parse the first line (status/request
+ * line) of the http's header because the behaviour differs if it's a client or
+ * server socket side
+ *
+ * @param line the line that has been read from this inputstream
+ */
+ protected abstract void readFirstLine(String line) throws IOException;
+
+ /**
+ * @return the path that has been specified in the http's status/request
+ * line
+ */
+ public final String getRequestPath() {
+ return requestPath;
+ }
+
+ @Override
+ public final int available() throws IOException {
+ fillBuffer();
+ return available;
+ }
+
+ @Override
+ public final void close() throws IOException {
+ fillBuffer();
+ bais.close();
+ }
+
+ @Override
+ public final void mark(int arg0) {
+ bais.mark(arg0);
+ }
+
+ @Override
+ public final boolean markSupported() {
+ return bais.markSupported();
+ }
+
+ @Override
+ public final void reset() throws IOException {
+ fillBuffer();
+ bais.reset();
+ }
+
+ @Override
+ public final long skip(long arg0) throws IOException {
+ fillBuffer();
+ return bais.skip(arg0);
+ }
+
+ /**
+ * @throws IOException
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public synchronized final int read() throws IOException {
+ fillBuffer();
+ if (available == 0) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ available--;
+ if (available > 0) {
+ notify();
+ }
+ return bais.read();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final int read(byte[] arg0) throws IOException {
+ return read(arg0, 0, arg0.length);
+ }
+
+ /**
+ * @throws IOException
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public synchronized final int read(byte[] arg0, int arg1, int arg2)
+ throws IOException {
+ fillBuffer();
+ if (available == 0) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (available > 0) {
+ notify();
+ }
+ int bytesRead = bais.read(arg0, arg1, arg2);
+ available -= bytesRead;
+ return bytesRead;
+ }
}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpOutputStream.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpOutputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpOutputStream.java Thu May 18 23:00:52 2006
@@ -1,161 +1,161 @@
-/*
-* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
-*
-* 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.
-*/
-package ar.org.fitc.rmi.transport.http;
-
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-
-import ar.org.fitc.rmi.utils.PropertiesReader;
-
-/**
- * This class is used for client and server purposes.
- * <br>
- * Implements a byte array stream in which the data is written. On the other
- * side, the constructor receive a socket's output stream.
- * <br>
- * All the data is written in the byte array's buffer until the
- * {@link #flush()} method is invoked. Then, a http's POST/RESPONSE
- * header is attached at the beginning of the socket's stream and all the buffered
- * bytes are written as the content of this header.
- *
- * @author Diego Raúl Mercado
- */
-abstract class HttpOutputStream extends ByteArrayOutputStream {
-
- private final static String CRLF = String.valueOf("\r\n");
-
- private final static String DEFAULT_ENCODING_CONTENT_TYPE =
- String.valueOf("application/octet-stream");
-
- private final static String DEFAULT_ACCEPT =
- String.valueOf("text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2");
-
- /** The value of the http's tag <code>User-Agent</code> */
- private final static String JAVA_VERSION =
- PropertiesReader.readString("java.version");
-
- /**
- * The value of the http's header field <code>host</code> that is specified
- * at the constructor of this object
- */
- private String localHostAddress;
-
- /** The http's status/resquest line that must be set at any of the subclasses */
- protected String header;
-
- /** The stream of the socket that is specified in this constructor */
- protected OutputStream socketOutput;
-
- /**
- * Indicates if this object has been flushed. The <code>reset()</code>
- * method initializes this value
- */
- private boolean isFlushed;
-
- /**
- * Constructor.
- *
- * @param socketOutput
- * the socket's output stream
- * @param localHostAddress
- * the localHostAddress attached in the http's HOST header
- */
- protected HttpOutputStream(OutputStream socketOutput,
- String localHostAddress) {
- this.socketOutput = socketOutput;
- this.localHostAddress = localHostAddress;
- }
-
- /**
- * @ar.org.fitc.spec_ref
- * Attaches a http's post header at the beginning of the socket's stream and
- * all the buffered bytes are written as the content of this http's
- * POST/RESPONSE header. Then, invoke the <code>flush</code> method of
- * the socket's stream
- */
- @Override
- public synchronized final void flush() throws IOException {
- if (!isFlushed) {
- writeOnSocket();
- isFlushed = true;
- }
- }
-
- /**
- * @ar.org.fitc.spec_ref
- * Resets this stream and sets the variable <code>isFlushed</code> to
- * false
- */
- @Override
- public final void reset() {
- super.reset();
- isFlushed = false;
- }
-
- /**
- * Writes the http's POST/RESPONSE into the socket's output stream
- * @throws IOException if cannot write the header
- */
- private final void writeOnSocket() throws IOException {
- try {
- BufferedOutputStream writer = new BufferedOutputStream(socketOutput);
-
- writer.write((header
- + CRLF
- + HttpHeaders.CONTENT_TYPE_HEADER
- + ": "
- + DEFAULT_ENCODING_CONTENT_TYPE
- + CRLF
- + HttpHeaders.CACHE_CONTROL_HEADER
- + ": "
- + "no-cache"
- + CRLF
- + HttpHeaders.PRAGMA_HEADER
- + ": "
- + "no-cache"
- + CRLF
- + HttpHeaders.USER_AGENT_HEADER
- + ": Java/"
- + JAVA_VERSION
- + CRLF
- + HttpHeaders.HOST_HEADER
- + ": "
- + localHostAddress
- + CRLF
- + HttpHeaders.CONTENT_LENGTH_HEADER
- + ": "
- + super.toByteArray().length
- + CRLF
- + HttpHeaders.ACCEPT_HEADER
- + ": "
- + DEFAULT_ACCEPT
- + CRLF
- + HttpHeaders.CONNECTION_HEADER + ": "
- + "keep-alive"
- + CRLF
- + CRLF)
- .getBytes());
-
- writer.write(super.toByteArray());
- writer.flush();
- } catch (UnsupportedEncodingException e) {
- new AssertionError(e);
- }
- }
-}
+/*
+* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+*
+* 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.
+*/
+package org.apache.harmony.rmi.internal.transport.http;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+
+import org.apache.harmony.rmi.internal.utils.PropertiesReader;
+
+/**
+ * This class is used for client and server purposes.
+ * <br>
+ * Implements a byte array stream in which the data is written. On the other
+ * side, the constructor receive a socket's output stream.
+ * <br>
+ * All the data is written in the byte array's buffer until the
+ * {@link #flush()} method is invoked. Then, a http's POST/RESPONSE
+ * header is attached at the beginning of the socket's stream and all the buffered
+ * bytes are written as the content of this header.
+ *
+ * @author Diego Raúl Mercado
+ */
+abstract class HttpOutputStream extends ByteArrayOutputStream {
+
+ private final static String CRLF = String.valueOf("\r\n");
+
+ private final static String DEFAULT_ENCODING_CONTENT_TYPE =
+ String.valueOf("application/octet-stream");
+
+ private final static String DEFAULT_ACCEPT =
+ String.valueOf("text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2");
+
+ /** The value of the http's tag <code>User-Agent</code> */
+ private final static String JAVA_VERSION =
+ PropertiesReader.readString("java.version");
+
+ /**
+ * The value of the http's header field <code>host</code> that is specified
+ * at the constructor of this object
+ */
+ private String localHostAddress;
+
+ /** The http's status/resquest line that must be set at any of the subclasses */
+ protected String header;
+
+ /** The stream of the socket that is specified in this constructor */
+ protected OutputStream socketOutput;
+
+ /**
+ * Indicates if this object has been flushed. The <code>reset()</code>
+ * method initializes this value
+ */
+ private boolean isFlushed;
+
+ /**
+ * Constructor.
+ *
+ * @param socketOutput
+ * the socket's output stream
+ * @param localHostAddress
+ * the localHostAddress attached in the http's HOST header
+ */
+ protected HttpOutputStream(OutputStream socketOutput,
+ String localHostAddress) {
+ this.socketOutput = socketOutput;
+ this.localHostAddress = localHostAddress;
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ * Attaches a http's post header at the beginning of the socket's stream and
+ * all the buffered bytes are written as the content of this http's
+ * POST/RESPONSE header. Then, invoke the <code>flush</code> method of
+ * the socket's stream
+ */
+ @Override
+ public synchronized final void flush() throws IOException {
+ if (!isFlushed) {
+ writeOnSocket();
+ isFlushed = true;
+ }
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ * Resets this stream and sets the variable <code>isFlushed</code> to
+ * false
+ */
+ @Override
+ public final void reset() {
+ super.reset();
+ isFlushed = false;
+ }
+
+ /**
+ * Writes the http's POST/RESPONSE into the socket's output stream
+ * @throws IOException if cannot write the header
+ */
+ private final void writeOnSocket() throws IOException {
+ try {
+ BufferedOutputStream writer = new BufferedOutputStream(socketOutput);
+
+ writer.write((header
+ + CRLF
+ + HttpHeaders.CONTENT_TYPE_HEADER
+ + ": "
+ + DEFAULT_ENCODING_CONTENT_TYPE
+ + CRLF
+ + HttpHeaders.CACHE_CONTROL_HEADER
+ + ": "
+ + "no-cache"
+ + CRLF
+ + HttpHeaders.PRAGMA_HEADER
+ + ": "
+ + "no-cache"
+ + CRLF
+ + HttpHeaders.USER_AGENT_HEADER
+ + ": Java/"
+ + JAVA_VERSION
+ + CRLF
+ + HttpHeaders.HOST_HEADER
+ + ": "
+ + localHostAddress
+ + CRLF
+ + HttpHeaders.CONTENT_LENGTH_HEADER
+ + ": "
+ + super.toByteArray().length
+ + CRLF
+ + HttpHeaders.ACCEPT_HEADER
+ + ": "
+ + DEFAULT_ACCEPT
+ + CRLF
+ + HttpHeaders.CONNECTION_HEADER + ": "
+ + "keep-alive"
+ + CRLF
+ + CRLF)
+ .getBytes());
+
+ writer.write(super.toByteArray());
+ writer.flush();
+ } catch (UnsupportedEncodingException e) {
+ new AssertionError(e);
+ }
+ }
+}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpServerInputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpServerInputStream.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpServerInputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpServerInputStream.java Thu May 18 23:00:52 2006
@@ -1,57 +1,57 @@
-/*
-* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
-*
-* 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.
-*/
-package ar.org.fitc.rmi.transport.http;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Specializes <code>HttpInputStream</code> for the server socket side
- *
- * @author Diego Raúl Mercado
- */
-class HttpServerInputStream extends HttpInputStream {
-
- /**
- * Constructor. Calls <code>HttpInputStream(InputStream)</code>
- * constructor.
- *
- * @param is
- * the socket's input stream
- */
- public HttpServerInputStream(InputStream is) {
- super(is);
- }
-
- /**
- * Parse the first line (request line) of the http's header.
- * Sets {@link HttpInputStream#requestPath requestPath} value
- *
- * @param line
- * the line that has been read from the socket's input stream
- */
- @Override
- protected void readFirstLine(String line) throws IOException {
- //LINE: REQUEST_PATH + " " + HTTP_VERSION
- String[] splitLine = line.split(" ");
- if (splitLine[0].contains("/")) {
- requestPath = splitLine[0].trim();
- } else {
- throw HEADERS_EXCEPTION;
- }
- }
-
-}
+/*
+* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+*
+* 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.
+*/
+package org.apache.harmony.rmi.internal.transport.http;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Specializes <code>HttpInputStream</code> for the server socket side
+ *
+ * @author Diego Raúl Mercado
+ */
+class HttpServerInputStream extends HttpInputStream {
+
+ /**
+ * Constructor. Calls <code>HttpInputStream(InputStream)</code>
+ * constructor.
+ *
+ * @param is
+ * the socket's input stream
+ */
+ public HttpServerInputStream(InputStream is) {
+ super(is);
+ }
+
+ /**
+ * Parse the first line (request line) of the http's header.
+ * Sets {@link HttpInputStream#requestPath requestPath} value
+ *
+ * @param line
+ * the line that has been read from the socket's input stream
+ */
+ @Override
+ protected void readFirstLine(String line) throws IOException {
+ //LINE: REQUEST_PATH + " " + HTTP_VERSION
+ String[] splitLine = line.split(" ");
+ if (splitLine[0].contains("/")) {
+ requestPath = splitLine[0].trim();
+ } else {
+ throw HEADERS_EXCEPTION;
+ }
+ }
+
+}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpServerOutputStream.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpServerOutputStream.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpServerOutputStream.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpServerOutputStream.java Thu May 18 23:00:52 2006
@@ -1,45 +1,45 @@
-/*
-* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
-*
-* 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.
-*/
-package ar.org.fitc.rmi.transport.http;
-
-import java.io.OutputStream;
-
-/**
- * Concrete class that additionally sets the <code>header</code> required
- * for the http's status line (RESPONSE)
- *
- * @author Diego Raúl Mercado
- */
-final class HttpServerOutputStream extends HttpOutputStream {
-
- /**
- * Calls the inherit constructor with the parameters
- * <code>socketOutput</code> and <code>localHostAddress</code>. <br>
- * Then, sets <code>header</code> required for the http's status line
- * (RESPONSE)
- *
- * @param socketOutput
- * the socket's output stream
- * @param localHostAddress
- * the localHostAddress attached in the http's host header
- */
- protected HttpServerOutputStream(OutputStream socketOutput,
- String localHostAddress) {
- super(socketOutput, localHostAddress);
- header = "HTTP/1.0 200 OK";
- }
-
-}
+/*
+* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+*
+* 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.
+*/
+package org.apache.harmony.rmi.internal.transport.http;
+
+import java.io.OutputStream;
+
+/**
+ * Concrete class that additionally sets the <code>header</code> required
+ * for the http's status line (RESPONSE)
+ *
+ * @author Diego Raúl Mercado
+ */
+final class HttpServerOutputStream extends HttpOutputStream {
+
+ /**
+ * Calls the inherit constructor with the parameters
+ * <code>socketOutput</code> and <code>localHostAddress</code>. <br>
+ * Then, sets <code>header</code> required for the http's status line
+ * (RESPONSE)
+ *
+ * @param socketOutput
+ * the socket's output stream
+ * @param localHostAddress
+ * the localHostAddress attached in the http's host header
+ */
+ protected HttpServerOutputStream(OutputStream socketOutput,
+ String localHostAddress) {
+ super(socketOutput, localHostAddress);
+ header = "HTTP/1.0 200 OK";
+ }
+
+}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpSocketClientSide.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpSocketClientSide.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpSocketClientSide.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpSocketClientSide.java Thu May 18 23:00:52 2006
@@ -1,96 +1,96 @@
-/*
-* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
-*
-* 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.
-*/
-package ar.org.fitc.rmi.transport.http;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.Socket;
-import java.net.URL;
-import java.net.UnknownHostException;
-
-/**
- * For client purposes. Specify other functionality overriding the methods
- * <code>getInputStream()</code> and <code>getOutputStream()</code>.
- *
- * @author Diego Raúl Mercado
- */
-public final class HttpSocketClientSide extends Socket {
-
- /** The socket's input stream */
- private InputStream input;
-
- /** The socket's output stream */
- private OutputStream output;
-
- /**
- * It's required for the constructor of this object and the http's request
- * line
- */
- private URL url;
-
- /**
- * Constructor.
- *
- * @param url
- * it's used for socket connection and http's request line
- * @throws UnknownHostException
- * indicate that the IP address of a host could not be
- * determined
- * @throws IOException
- * if an I/O error occurs when creating this socket
- */
- public HttpSocketClientSide(URL url) throws UnknownHostException,
- IOException {
- super(url.getHost(), url.getPort());
- this.url = url;
- }
-
- /**
- * @ar.org.fitc.spec_ref returns a <code>HTTPInputStream</code> instance
- * with the input stream of the superclass of this
- * object as the constructor parameter
- */
- @Override
- public synchronized final InputStream getInputStream() throws IOException {
- if (input == null) {
- input = new HttpClientInputStream(super.getInputStream());
- }
- return input;
- }
-
- /**
- * @ar.org.fitc.spec_ref returns a <code>HTTPClientOutputStream</code>
- * instance with the input stream of the superclass of
- * this object as one of the constructor parameters
- */
- @Override
- public synchronized final OutputStream getOutputStream() throws IOException {
- if (output == null) {
- if (url.getQuery() == null) {
- // proxy... (serverPath: http://90.0.0.1:1099/)
- output = new HttpClientOutputStream(super.getOutputStream(),
- url.getPath(), getInetAddress().getHostAddress());
- } else {
- // proxy + cgi... (serverPath:
- // http://90.0.0.1:80/cgi-bin/java-rmi?forward=1099)
- output = new HttpClientOutputStream(super.getOutputStream(),
- url.getFile(), getInetAddress().getHostAddress());
- }
- }
- return output;
- }
-}
+/*
+* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+*
+* 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.
+*/
+package org.apache.harmony.rmi.internal.transport.http;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.net.URL;
+import java.net.UnknownHostException;
+
+/**
+ * For client purposes. Specify other functionality overriding the methods
+ * <code>getInputStream()</code> and <code>getOutputStream()</code>.
+ *
+ * @author Diego Raúl Mercado
+ */
+public final class HttpSocketClientSide extends Socket {
+
+ /** The socket's input stream */
+ private InputStream input;
+
+ /** The socket's output stream */
+ private OutputStream output;
+
+ /**
+ * It's required for the constructor of this object and the http's request
+ * line
+ */
+ private URL url;
+
+ /**
+ * Constructor.
+ *
+ * @param url
+ * it's used for socket connection and http's request line
+ * @throws UnknownHostException
+ * indicate that the IP address of a host could not be
+ * determined
+ * @throws IOException
+ * if an I/O error occurs when creating this socket
+ */
+ public HttpSocketClientSide(URL url) throws UnknownHostException,
+ IOException {
+ super(url.getHost(), url.getPort());
+ this.url = url;
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref returns a <code>HTTPInputStream</code> instance
+ * with the input stream of the superclass of this
+ * object as the constructor parameter
+ */
+ @Override
+ public synchronized final InputStream getInputStream() throws IOException {
+ if (input == null) {
+ input = new HttpClientInputStream(super.getInputStream());
+ }
+ return input;
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref returns a <code>HTTPClientOutputStream</code>
+ * instance with the input stream of the superclass of
+ * this object as one of the constructor parameters
+ */
+ @Override
+ public synchronized final OutputStream getOutputStream() throws IOException {
+ if (output == null) {
+ if (url.getQuery() == null) {
+ // proxy... (serverPath: http://90.0.0.1:1099/)
+ output = new HttpClientOutputStream(super.getOutputStream(),
+ url.getPath(), getInetAddress().getHostAddress());
+ } else {
+ // proxy + cgi... (serverPath:
+ // http://90.0.0.1:80/cgi-bin/java-rmi?forward=1099)
+ output = new HttpClientOutputStream(super.getOutputStream(),
+ url.getFile(), getInetAddress().getHostAddress());
+ }
+ }
+ return output;
+ }
+}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpSocketServerSide.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpSocketServerSide.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpSocketServerSide.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/http/HttpSocketServerSide.java Thu May 18 23:00:52 2006
@@ -1,398 +1,398 @@
-/*
-* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
-*
-* 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.
-*/
-package ar.org.fitc.rmi.transport.http;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.net.SocketException;
-import java.nio.channels.SocketChannel;
-
-/**
- * For server purposes. Acts as a wrapper for a socket that is specified at the
- * constructor. Overrides all the socket's methods and delegates to the wrapped
- * socket. Specify other functionality overriding the methods
- * <code>getInputStream()</code> and <code>getOutputStream()</code>.
- *
- * @author Diego Raúl Mercado
- */
-public final class HttpSocketServerSide extends Socket {
-
- /** The socket's input stream */
- private InputStream input;
-
- /** The socket's output stream */
- private OutputStream output;
-
- /** The wrapped socket */
- private Socket serverSocket;
-
- /**
- * Constructor.
- *
- * @param socket
- * the socket to be wrapped
- */
- public HttpSocketServerSide(Socket socket) {
- serverSocket = socket;
- }
-
- /**
- * @ar.org.fitc.spec_ref returns a <code>HTTPInputStream</code> instance
- * with the input stream of the wrapped socket as the
- * constructor parameter
- */
- @Override
- public synchronized final InputStream getInputStream() throws IOException {
- if (input == null) {
- input = new HttpServerInputStream(serverSocket.getInputStream());
- }
- return input;
- }
-
- /**
- * @ar.org.fitc.spec_ref returns a <code>HTTPClientOutputStream</code>
- * instance with the input stream of the wrapped
- * socket as one of the constructor parameters
- */
- @Override
- public synchronized final OutputStream getOutputStream() throws IOException {
- if (output == null) {
- output = new HttpServerOutputStream(serverSocket.getOutputStream(),
- getLocalAddress().isAnyLocalAddress() ? "127.0.0.1"
- : getLocalAddress().getHostAddress());
- }
- return output;
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void bind(SocketAddress arg0) throws IOException {
- serverSocket.bind(arg0);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public synchronized final void close() throws IOException {
- serverSocket.close();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void connect(SocketAddress arg0, int arg1) throws IOException {
- serverSocket.connect(arg0, arg1);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void connect(SocketAddress arg0) throws IOException {
- serverSocket.connect(arg0);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final SocketChannel getChannel() {
- return serverSocket.getChannel();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final InetAddress getInetAddress() {
- return serverSocket.getInetAddress();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final boolean getKeepAlive() throws SocketException {
- return serverSocket.getKeepAlive();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final InetAddress getLocalAddress() {
- return serverSocket.getLocalAddress();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final int getLocalPort() {
- return serverSocket.getLocalPort();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final SocketAddress getLocalSocketAddress() {
- return serverSocket.getLocalSocketAddress();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final boolean getOOBInline() throws SocketException {
- return serverSocket.getOOBInline();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final int getPort() {
- return serverSocket.getPort();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final synchronized int getReceiveBufferSize() throws SocketException {
- return serverSocket.getReceiveBufferSize();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final SocketAddress getRemoteSocketAddress() {
- return serverSocket.getRemoteSocketAddress();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final boolean getReuseAddress() throws SocketException {
- return serverSocket.getReuseAddress();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final synchronized int getSendBufferSize() throws SocketException {
- return serverSocket.getSendBufferSize();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final int getSoLinger() throws SocketException {
- return serverSocket.getSoLinger();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final synchronized int getSoTimeout() throws SocketException {
- return serverSocket.getSoTimeout();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final boolean getTcpNoDelay() throws SocketException {
- return serverSocket.getTcpNoDelay();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final int getTrafficClass() throws SocketException {
- return serverSocket.getTrafficClass();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final boolean isBound() {
- return serverSocket.isBound();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final boolean isClosed() {
- return serverSocket.isClosed();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final boolean isConnected() {
- return serverSocket.isConnected();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final boolean isInputShutdown() {
- return serverSocket.isInputShutdown();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final boolean isOutputShutdown() {
- return serverSocket.isOutputShutdown();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void sendUrgentData(int arg0) throws IOException {
- serverSocket.sendUrgentData(arg0);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void setKeepAlive(boolean arg0) throws SocketException {
- serverSocket.setKeepAlive(arg0);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void setOOBInline(boolean arg0) throws SocketException {
- serverSocket.setOOBInline(arg0);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void setPerformancePreferences(int arg0, int arg1, int arg2) {
- serverSocket.setPerformancePreferences(arg0, arg1, arg2);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public synchronized final void setReceiveBufferSize(int arg0)
- throws SocketException {
- serverSocket.setReceiveBufferSize(arg0);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void setReuseAddress(boolean arg0) throws SocketException {
- serverSocket.setReuseAddress(arg0);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public synchronized void setSendBufferSize(int arg0) throws SocketException {
- serverSocket.setSendBufferSize(arg0);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void setSoLinger(boolean arg0, int arg1)
- throws SocketException {
- serverSocket.setSoLinger(arg0, arg1);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public synchronized final void setSoTimeout(int arg0)
- throws SocketException {
- serverSocket.setSoTimeout(arg0);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void setTcpNoDelay(boolean arg0) throws SocketException {
- serverSocket.setTcpNoDelay(arg0);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void setTrafficClass(int arg0) throws SocketException {
- serverSocket.setTrafficClass(arg0);
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void shutdownInput() throws IOException {
- serverSocket.shutdownInput();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final void shutdownOutput() throws IOException {
- serverSocket.shutdownOutput();
- }
-
- /**
- * @ar.org.fitc.spec_ref
- */
- @Override
- public final String toString() {
- return serverSocket.toString();
- }
-}
+/*
+* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+*
+* 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.
+*/
+package org.apache.harmony.rmi.internal.transport.http;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.nio.channels.SocketChannel;
+
+/**
+ * For server purposes. Acts as a wrapper for a socket that is specified at the
+ * constructor. Overrides all the socket's methods and delegates to the wrapped
+ * socket. Specify other functionality overriding the methods
+ * <code>getInputStream()</code> and <code>getOutputStream()</code>.
+ *
+ * @author Diego Raúl Mercado
+ */
+public final class HttpSocketServerSide extends Socket {
+
+ /** The socket's input stream */
+ private InputStream input;
+
+ /** The socket's output stream */
+ private OutputStream output;
+
+ /** The wrapped socket */
+ private Socket serverSocket;
+
+ /**
+ * Constructor.
+ *
+ * @param socket
+ * the socket to be wrapped
+ */
+ public HttpSocketServerSide(Socket socket) {
+ serverSocket = socket;
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref returns a <code>HTTPInputStream</code> instance
+ * with the input stream of the wrapped socket as the
+ * constructor parameter
+ */
+ @Override
+ public synchronized final InputStream getInputStream() throws IOException {
+ if (input == null) {
+ input = new HttpServerInputStream(serverSocket.getInputStream());
+ }
+ return input;
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref returns a <code>HTTPClientOutputStream</code>
+ * instance with the input stream of the wrapped
+ * socket as one of the constructor parameters
+ */
+ @Override
+ public synchronized final OutputStream getOutputStream() throws IOException {
+ if (output == null) {
+ output = new HttpServerOutputStream(serverSocket.getOutputStream(),
+ getLocalAddress().isAnyLocalAddress() ? "127.0.0.1"
+ : getLocalAddress().getHostAddress());
+ }
+ return output;
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void bind(SocketAddress arg0) throws IOException {
+ serverSocket.bind(arg0);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public synchronized final void close() throws IOException {
+ serverSocket.close();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void connect(SocketAddress arg0, int arg1) throws IOException {
+ serverSocket.connect(arg0, arg1);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void connect(SocketAddress arg0) throws IOException {
+ serverSocket.connect(arg0);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final SocketChannel getChannel() {
+ return serverSocket.getChannel();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final InetAddress getInetAddress() {
+ return serverSocket.getInetAddress();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final boolean getKeepAlive() throws SocketException {
+ return serverSocket.getKeepAlive();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final InetAddress getLocalAddress() {
+ return serverSocket.getLocalAddress();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final int getLocalPort() {
+ return serverSocket.getLocalPort();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final SocketAddress getLocalSocketAddress() {
+ return serverSocket.getLocalSocketAddress();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final boolean getOOBInline() throws SocketException {
+ return serverSocket.getOOBInline();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final int getPort() {
+ return serverSocket.getPort();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final synchronized int getReceiveBufferSize() throws SocketException {
+ return serverSocket.getReceiveBufferSize();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final SocketAddress getRemoteSocketAddress() {
+ return serverSocket.getRemoteSocketAddress();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final boolean getReuseAddress() throws SocketException {
+ return serverSocket.getReuseAddress();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final synchronized int getSendBufferSize() throws SocketException {
+ return serverSocket.getSendBufferSize();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final int getSoLinger() throws SocketException {
+ return serverSocket.getSoLinger();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final synchronized int getSoTimeout() throws SocketException {
+ return serverSocket.getSoTimeout();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final boolean getTcpNoDelay() throws SocketException {
+ return serverSocket.getTcpNoDelay();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final int getTrafficClass() throws SocketException {
+ return serverSocket.getTrafficClass();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final boolean isBound() {
+ return serverSocket.isBound();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final boolean isClosed() {
+ return serverSocket.isClosed();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final boolean isConnected() {
+ return serverSocket.isConnected();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final boolean isInputShutdown() {
+ return serverSocket.isInputShutdown();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final boolean isOutputShutdown() {
+ return serverSocket.isOutputShutdown();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void sendUrgentData(int arg0) throws IOException {
+ serverSocket.sendUrgentData(arg0);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void setKeepAlive(boolean arg0) throws SocketException {
+ serverSocket.setKeepAlive(arg0);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void setOOBInline(boolean arg0) throws SocketException {
+ serverSocket.setOOBInline(arg0);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void setPerformancePreferences(int arg0, int arg1, int arg2) {
+ serverSocket.setPerformancePreferences(arg0, arg1, arg2);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public synchronized final void setReceiveBufferSize(int arg0)
+ throws SocketException {
+ serverSocket.setReceiveBufferSize(arg0);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void setReuseAddress(boolean arg0) throws SocketException {
+ serverSocket.setReuseAddress(arg0);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public synchronized void setSendBufferSize(int arg0) throws SocketException {
+ serverSocket.setSendBufferSize(arg0);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void setSoLinger(boolean arg0, int arg1)
+ throws SocketException {
+ serverSocket.setSoLinger(arg0, arg1);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public synchronized final void setSoTimeout(int arg0)
+ throws SocketException {
+ serverSocket.setSoTimeout(arg0);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void setTcpNoDelay(boolean arg0) throws SocketException {
+ serverSocket.setTcpNoDelay(arg0);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void setTrafficClass(int arg0) throws SocketException {
+ serverSocket.setTrafficClass(arg0);
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void shutdownInput() throws IOException {
+ serverSocket.shutdownInput();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final void shutdownOutput() throws IOException {
+ serverSocket.shutdownOutput();
+ }
+
+ /**
+ * @ar.org.fitc.spec_ref
+ */
+ @Override
+ public final String toString() {
+ return serverSocket.toString();
+ }
+}
Modified: incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/jrmp/ClientProtocolHandler.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/jrmp/ClientProtocolHandler.java?rev=407724&r1=407183&r2=407724&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/jrmp/ClientProtocolHandler.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/internal/transport/jrmp/ClientProtocolHandler.java Thu May 18 23:00:52 2006
@@ -1,204 +1,204 @@
-/*
-* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
-*
-* 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.
-*/
-package ar.org.fitc.rmi.transport.jrmp;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.rmi.MarshalException;
-import java.rmi.UnmarshalException;
-import java.rmi.server.ObjID;
-import java.rmi.server.UID;
-
-import ar.org.fitc.rmi.transport.EndpointID;
-import ar.org.fitc.rmi.transport.ProtocolException;
-
-/**
- * Implements the management Client view of the messages of the JRMP protocol.
- * Each of the methods here represent a message or a protocol handshake.
- *
- * @author Gustavo Petri
- */
-public class ClientProtocolHandler {
-
- /**
- * The local
- * {@link java.io.InputStream}
- * to interact with the server
- */
- private DataInputStream in;
-
- /**
- * The local
- * {@link java.io.OutputStream}
- * to interact with the server.
- */
- private DataOutputStream out;
-
- /**
- * Constructor of {@link ClientProtocolHandler}
- *
- * @param in
- * the
- * {@link ar.org.fitc.rmi.transport.RMIObjectInputStream RMIObjectInputStream}
- * @param out
- * the
- * {@link ar.org.fitc.rmi.transport.RMIObjectOutputStream RMIObjectOutputStream}
- */
- public ClientProtocolHandler(DataInputStream in, DataOutputStream out) {
- this.out = out;
- this.in = in;
- }
-
- /**
- * Reads the {@link HeaderResponse#PROTOCOL_ACK PROTOCOL_ACK}.
- *
- * @throws UnmarshalException
- * if an I/O exceptions or a read of an unexpected byte ocurrs
- */
- public final void readHandshakeResponse() throws UnmarshalException {
-
- HeaderResponse rep;
- try {
- rep = HeaderResponse.createHeaderResponse(in.readByte());
- } catch (IOException e) {
- throw new UnmarshalException("Exception reading the Header response", e);
- }
- if (!rep.equals(HeaderResponse.PROTOCOL_ACK)) {
- throw new UnmarshalException("Protocol Not Supported");
- } }
-
- /**
- * Reads the {@link MessageResponse#PING_ACK PING_ACK}.
- *
- * @throws ProtocolException
- * if an I/O exceptions or a read of an unexpected byte ocurrs
- */
- public final void readPingAck() throws ProtocolException {
- try {
- MessageResponse msgResp = MessageResponse.createMessageResponse(in
- .readByte());
- if (!msgResp.equals(MessageResponse.PING_ACK)) {
- throw new ProtocolException("I/O Error Reading PingAck");
- }
- } catch (IOException e) {
- throw new ProtocolException("I/O Error PingAck", e);
- }
- }
-
- /**
- * Constructs a ReturnMessage object and sets its returns value. <br>
- *
- * Then, calls the
- * {@link ReturnMessage#read(DataInputStream) read(DataInputStream)} method
- * in order to set this object which is finally returned.
- *
- * @param waitResult
- * to set the <code>ReturnMessage</code> object
- * @return
- * the <code>ReturnMessage</code> object
- * @throws Exception
- * any exception
- */
- public final ReturnMessage readResult(boolean waitResult) throws Exception {
- ReturnMessage result = new ReturnMessage();
- result.setReturnsValue(waitResult);
- result.read(in);
- return result;
- }
-
- /**
- * Constructs a message with this parameters and writes the Call
- *
- * @param objId
- * the object ID
- * @param hash
- * the hash
- * @param args
- * the arguments to invoke
- * @throws Exception
- * any exception
- */
- public final void writeCall(ObjID objId, long hash, Object[] args)
- throws Exception {
- new Message(objId, hash, args).writeExternal(out);
- }
-
- /**
- * Constructs a message with the <code>uid</code> and then, writes the
- * DGCAck.
- *
- * @param uid
- * a unique identifier
- * @throws ProtocolException
- * if an I/O exceptions ocurrs
- */
- public final void writeDGCAck(UID uid) throws ProtocolException {
-
- try {
- new Message(uid).writeExternal(out);
- } catch (IOException e) {
- throw new ProtocolException("Error while sending DGCAck", e);
- }
- }
-
- /**
- * Writes the protocol header, version and type of connection
- *
- * @param type
- * the protocol's type
- * @throws MarshalException
- * if an I/O exceptions ocurrs
- */
- public final void writeHandshake(ProtocolType type) throws MarshalException {
-
- Header header = new Header(type);
- try {
- header.writeExternal(out);
- } catch (IOException e) {
- throw new MarshalException("Exception marshaling JRMP Header", e);
- }
- }
-
- /**
- * Writes the host and port
- *
- * @throws ProtocolException
- * if an I/O exceptions ocurrs
- */
- public final void writeHandshakeResponse() throws ProtocolException {
- try {
- new EndpointID().write(out);
- } catch (IOException e) {
- throw new ProtocolException(
- "Error marshaling the protocolHandshake response", e);
- }
- }
-
- /**
- * Writes the Ping request.
- *
- * @throws ProtocolException
- * if an I/O exceptions ocurrs
- */
- public final void writePing() throws ProtocolException {
- try {
- new Message().writeExternal(out);
- } catch (IOException e) {
- throw new ProtocolException("Socket Closed while pinging", e);
- }
- }
+/*
+* Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+*
+* 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.
+*/
+package org.apache.harmony.rmi.internal.transport.jrmp;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.rmi.MarshalException;
+import java.rmi.UnmarshalException;
+import java.rmi.server.ObjID;
+import java.rmi.server.UID;
+
+import org.apache.harmony.rmi.internal.transport.EndpointID;
+import org.apache.harmony.rmi.internal.transport.ProtocolException;
+
+/**
+ * Implements the management Client view of the messages of the JRMP protocol.
+ * Each of the methods here represent a message or a protocol handshake.
+ *
+ * @author Gustavo Petri
+ */
+public class ClientProtocolHandler {
+
+ /**
+ * The local
+ * {@link java.io.InputStream}
+ * to interact with the server
+ */
+ private DataInputStream in;
+
+ /**
+ * The local
+ * {@link java.io.OutputStream}
+ * to interact with the server.
+ */
+ private DataOutputStream out;
+
+ /**
+ * Constructor of {@link ClientProtocolHandler}
+ *
+ * @param in
+ * the
+ * {@link org.apache.harmony.rmi.internal.transport.RMIObjectInputStream RMIObjectInputStream}
+ * @param out
+ * the
+ * {@link org.apache.harmony.rmi.internal.transport.RMIObjectOutputStream RMIObjectOutputStream}
+ */
+ public ClientProtocolHandler(DataInputStream in, DataOutputStream out) {
+ this.out = out;
+ this.in = in;
+ }
+
+ /**
+ * Reads the {@link HeaderResponse#PROTOCOL_ACK PROTOCOL_ACK}.
+ *
+ * @throws UnmarshalException
+ * if an I/O exceptions or a read of an unexpected byte ocurrs
+ */
+ public final void readHandshakeResponse() throws UnmarshalException {
+
+ HeaderResponse rep;
+ try {
+ rep = HeaderResponse.createHeaderResponse(in.readByte());
+ } catch (IOException e) {
+ throw new UnmarshalException("Exception reading the Header response", e);
+ }
+ if (!rep.equals(HeaderResponse.PROTOCOL_ACK)) {
+ throw new UnmarshalException("Protocol Not Supported");
+ } }
+
+ /**
+ * Reads the {@link MessageResponse#PING_ACK PING_ACK}.
+ *
+ * @throws ProtocolException
+ * if an I/O exceptions or a read of an unexpected byte ocurrs
+ */
+ public final void readPingAck() throws ProtocolException {
+ try {
+ MessageResponse msgResp = MessageResponse.createMessageResponse(in
+ .readByte());
+ if (!msgResp.equals(MessageResponse.PING_ACK)) {
+ throw new ProtocolException("I/O Error Reading PingAck");
+ }
+ } catch (IOException e) {
+ throw new ProtocolException("I/O Error PingAck", e);
+ }
+ }
+
+ /**
+ * Constructs a ReturnMessage object and sets its returns value. <br>
+ *
+ * Then, calls the
+ * {@link ReturnMessage#read(DataInputStream) read(DataInputStream)} method
+ * in order to set this object which is finally returned.
+ *
+ * @param waitResult
+ * to set the <code>ReturnMessage</code> object
+ * @return
+ * the <code>ReturnMessage</code> object
+ * @throws Exception
+ * any exception
+ */
+ public final ReturnMessage readResult(boolean waitResult) throws Exception {
+ ReturnMessage result = new ReturnMessage();
+ result.setReturnsValue(waitResult);
+ result.read(in);
+ return result;
+ }
+
+ /**
+ * Constructs a message with this parameters and writes the Call
+ *
+ * @param objId
+ * the object ID
+ * @param hash
+ * the hash
+ * @param args
+ * the arguments to invoke
+ * @throws Exception
+ * any exception
+ */
+ public final void writeCall(ObjID objId, long hash, Object[] args)
+ throws Exception {
+ new Message(objId, hash, args).writeExternal(out);
+ }
+
+ /**
+ * Constructs a message with the <code>uid</code> and then, writes the
+ * DGCAck.
+ *
+ * @param uid
+ * a unique identifier
+ * @throws ProtocolException
+ * if an I/O exceptions ocurrs
+ */
+ public final void writeDGCAck(UID uid) throws ProtocolException {
+
+ try {
+ new Message(uid).writeExternal(out);
+ } catch (IOException e) {
+ throw new ProtocolException("Error while sending DGCAck", e);
+ }
+ }
+
+ /**
+ * Writes the protocol header, version and type of connection
+ *
+ * @param type
+ * the protocol's type
+ * @throws MarshalException
+ * if an I/O exceptions ocurrs
+ */
+ public final void writeHandshake(ProtocolType type) throws MarshalException {
+
+ Header header = new Header(type);
+ try {
+ header.writeExternal(out);
+ } catch (IOException e) {
+ throw new MarshalException("Exception marshaling JRMP Header", e);
+ }
+ }
+
+ /**
+ * Writes the host and port
+ *
+ * @throws ProtocolException
+ * if an I/O exceptions ocurrs
+ */
+ public final void writeHandshakeResponse() throws ProtocolException {
+ try {
+ new EndpointID().write(out);
+ } catch (IOException e) {
+ throw new ProtocolException(
+ "Error marshaling the protocolHandshake response", e);
+ }
+ }
+
+ /**
+ * Writes the Ping request.
+ *
+ * @throws ProtocolException
+ * if an I/O exceptions ocurrs
+ */
+ public final void writePing() throws ProtocolException {
+ try {
+ new Message().writeExternal(out);
+ } catch (IOException e) {
+ throw new ProtocolException("Socket Closed while pinging", e);
+ }
+ }
}