edu.virginia.cs.mng.hypercast
Class HTTP_ServerUtility
java.lang.Object
|
+--edu.virginia.cs.mng.hypercast.HTTP_ServerUtility
- public class HTTP_ServerUtility
- extends java.lang.Object
This class contains a set of static functions used by
UDP_HTTP_ServerAdapter and HTTP_Server for server transactions.
These functions translate a message from bytes into a string of
hexadecimal characters ('0'-'9' or 'A'-'F'), insert that string
into a CGI query, read the response, translate the response
back into a byte[] and return it.
|
Method Summary |
static java.lang.String |
decodeURLString(java.lang.String s)
This method takes a string from a URL (e.g. |
static java.lang.String |
encodeURLString(java.lang.String s)
This function encodes a string in a URL format. |
private static java.lang.String |
firstLineFromStream(java.io.InputStream response_is)
Reads the first line from the InputStream and returns it. |
static java.lang.String |
query(java.lang.String urlString)
Builds a simple query without a message and return the
response as a string. |
static byte[] |
query(java.lang.String server_query_prefix,
java.lang.String overlayID,
byte[] input_message)
Builds a query with a message and return the
response as another message. |
static byte[] |
toByteArray(java.lang.String s)
This is the inverse function of toHexString(). |
static java.lang.String |
toHexString(byte[] a)
|
| Methods inherited from class java.lang.Object |
,
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
registerNatives,
toString,
wait,
wait,
wait |
MAX_SERVER_RESPONSE_SIZE
public static final int MAX_SERVER_RESPONSE_SIZE
- Maximum size of a response coming from the server.
HTTP_ServerUtility
public HTTP_ServerUtility()
query
public static java.lang.String query(java.lang.String urlString)
throws java.net.MalformedURLException,
java.io.IOException
- Builds a simple query without a message and return the
response as a string.
query
public static byte[] query(java.lang.String server_query_prefix,
java.lang.String overlayID,
byte[] input_message)
throws java.net.MalformedURLException,
java.io.IOException
- Builds a query with a message and return the
response as another message.
firstLineFromStream
private static java.lang.String firstLineFromStream(java.io.InputStream response_is)
throws java.io.IOException
- Reads the first line from the InputStream and returns it.
toHexString
public static java.lang.String toHexString(byte[] a)
toByteArray
public static byte[] toByteArray(java.lang.String s)
- This is the inverse function of toHexString().
It takes a string of hexidecimal digits and returns a byte[].
The string can end with nothing, a newline character, or a carriage return.
Any extraneous characters causes an error message to be printed and
null returned.
decodeURLString
public static java.lang.String decodeURLString(java.lang.String s)
- This method takes a string from a URL (e.g. CGI forms request) and
converts it into a normal string. This means that '+' gets converted
into ' ', and for any '%', the next two characters are treated as
the hex encoding of an ASCII character.
WARNING: THIS IS POORLY CODED AND MAY NOT WORK ON NON-ASCII SYSTEMS!
encodeURLString
public static java.lang.String encodeURLString(java.lang.String s)
- This function encodes a string in a URL format. This means that
all ' ' become '+' and any of the characters "&=?+" are encoded
using '%' and the character encoded as the hexidecimal of their
ASCII value.