org.tranche.remote
Class RemoteUtil

java.lang.Object
  extended by org.tranche.remote.RemoteUtil

public class RemoteUtil
extends java.lang.Object

Utility methods for remote tranche server interaction.

Author:
Jayson Falkner - jfalkner@umich.edu, Bryan E. Smith - bryanesmith@gmail.com, James "Augie" Hill - augman85@gmail.com

Field Summary
static byte BYTE_FALSE
           
static byte BYTE_TRUE
           
 
Constructor Summary
RemoteUtil()
           
 
Method Summary
static java.io.InputStream bufferData(java.io.InputStream in)
          Helper method to read data
static void checkOK(java.io.InputStream in)
          Helper method that will throw an IOException if the input stream does not start with an Token.OK_STRING line.
static void checkOK(java.lang.String line, java.io.InputStream is)
          Helper method that will throw an IOException if the line is not an Token.OK_STRING
static boolean getBoolean(byte booleanByte)
           
static byte getByte(boolean byteBoolean)
           
static void handledError(java.lang.String responseLine, java.io.InputStream in)
          Helper method for handling errors.
static boolean isAvailable(java.io.InputStream is)
          Returns true if input stream doesn't have any available input, else false.
static byte[][] read2dData(java.io.InputStream in)
           
static byte[][][] read3dData(java.io.InputStream in)
           
static BigHash readBigHash(java.io.InputStream is)
           
static BigHash[] readBigHashArray(java.io.InputStream is)
           
static boolean readBoolean(java.io.InputStream is)
          Helper method to read an integer from an input stream.
static boolean[] readBooleanArray(java.io.InputStream is)
           
static byte readByte(java.io.InputStream in)
           
static byte[] readBytes(int length, java.io.InputStream in)
           
static java.io.InputStream readData(java.io.InputStream is)
          Helper method for reading data.
static byte[] readDataBytes(java.io.InputStream bis)
          Helper method to return all bytes from an input stream.
static int readInt(java.io.InputStream is)
          Helper method to read an integer from an input stream.
static java.lang.String readLine(java.io.InputStream is)
          Helper method to read a single line of unencoded text
static long readLong(java.io.InputStream is)
          Helper method to read a long from an input stream.
static Signature readSignature(java.io.InputStream in)
          Helper method to read a signature from an input stream.
static void write2dData(byte[][] data, java.io.OutputStream out)
           
static void write3dData(byte[][][] data, java.io.OutputStream out)
           
static void writeBigHash(BigHash hash, java.io.OutputStream os)
           
static void writeBigHashArray(BigHash[] hashes, java.io.OutputStream os)
           
static void writeBoolean(boolean b, java.io.OutputStream out)
          Helper method for writing an integer to an output stream.
static void writeBooleanArray(boolean[] booleanArray, java.io.OutputStream out)
           
static void writeByte(byte b, java.io.OutputStream out)
           
static void writeBytes(byte[] bytes, java.io.OutputStream out)
           
static void writeData(byte[] data, java.io.OutputStream out)
          Helper method for writing bytes to an output stream.
static void writeError(java.lang.String message, java.io.OutputStream out)
          Helper method to write out an error message to the output stream.
static void writeInt(int i, java.io.OutputStream out)
          Helper method for writing an integer to an output stream.
static void writeLine(java.lang.String s, java.io.OutputStream out)
          Write a line to an output stream.
static void writeLong(long l, java.io.OutputStream out)
          Helper method for writing a long to an output stream.
static void writeSignature(Signature sig, java.io.OutputStream bos)
          Helper method to write out a signature to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTE_FALSE

public static final byte BYTE_FALSE
See Also:
Constant Field Values

BYTE_TRUE

public static final byte BYTE_TRUE
See Also:
Constant Field Values
Constructor Detail

RemoteUtil

public RemoteUtil()
Method Detail

isAvailable

public static final boolean isAvailable(java.io.InputStream is)
                                 throws java.io.IOException

Returns true if input stream doesn't have any available input, else false.

Parameters:
is - the input stream
Returns:
true if the input stream does not have any available input; false otherwise
Throws:
java.io.IOException - if an input or output exception occurs

getBoolean

public static final boolean getBoolean(byte booleanByte)
                                throws java.io.IOException
Parameters:
booleanByte -
Returns:
Throws:
java.io.IOException

getByte

public static final byte getByte(boolean byteBoolean)
Parameters:
byteBoolean -
Returns:

writeBooleanArray

public static final void writeBooleanArray(boolean[] booleanArray,
                                           java.io.OutputStream out)
                                    throws java.io.IOException
Parameters:
booleanArray -
out -
Throws:
java.io.IOException

readBooleanArray

public static final boolean[] readBooleanArray(java.io.InputStream is)
                                        throws java.io.IOException
Parameters:
is -
Returns:
Throws:
java.io.IOException

writeBigHashArray

public static final void writeBigHashArray(BigHash[] hashes,
                                           java.io.OutputStream os)
                                    throws java.io.IOException
Parameters:
hashes -
os -
Throws:
java.io.IOException

readBigHashArray

public static final BigHash[] readBigHashArray(java.io.InputStream is)
                                        throws java.io.IOException
Parameters:
is -
Returns:
Throws:
java.io.IOException

readBigHash

public static final BigHash readBigHash(java.io.InputStream is)
                                 throws java.io.IOException
Parameters:
is -
Returns:
Throws:
java.io.IOException

writeBigHash

public static final void writeBigHash(BigHash hash,
                                      java.io.OutputStream os)
                               throws java.io.IOException
Parameters:
hash -
os -
Throws:
java.io.IOException

readLine

public static final java.lang.String readLine(java.io.InputStream is)
                                       throws java.io.IOException

Helper method to read a single line of unencoded text

Parameters:
is - the input stream
Returns:
the string equivalent of the byte array output stream
Throws:
java.io.IOException - if an input or output exception occurs

writeLine

public static final void writeLine(java.lang.String s,
                                   java.io.OutputStream out)
                            throws java.io.IOException

Write a line to an output stream.

Parameters:
s - the string
out - the output stream
Throws:
java.io.IOException - if an input or output exception occurs

bufferData

public static final java.io.InputStream bufferData(java.io.InputStream in)
                                            throws java.io.IOException

Helper method to read data

Parameters:
in - the input stream
Returns:
the byte array input stream containing the buffered data
Throws:
java.io.IOException - if an input or output exception occurs

handledError

public static final void handledError(java.lang.String responseLine,
                                      java.io.InputStream in)
                               throws java.io.IOException,
                                      java.lang.RuntimeException,
                                      java.security.GeneralSecurityException

Helper method for handling errors.

Parameters:
responseLine - the response consisting of an exception
in - the input stream
Throws:
java.io.IOException - if an input or output exception occurs
java.lang.RuntimeException - if a server doesn't support an operation or another runtime exception occurs
java.security.GeneralSecurityException

readData

public static final java.io.InputStream readData(java.io.InputStream is)
                                          throws java.io.IOException

Helper method for reading data.

Parameters:
is - the input stream
Returns:
the input stream of buffer data
Throws:
java.io.IOException - if an input or output exception occurs

readDataBytes

public static final byte[] readDataBytes(java.io.InputStream bis)
                                  throws java.io.IOException

Helper method to return all bytes from an input stream.

Parameters:
bis - the input stream
Returns:
the data bytes
Throws:
java.io.IOException - if an input or output exception occurs

writeData

public static final void writeData(byte[] data,
                                   java.io.OutputStream out)
                            throws java.io.IOException

Helper method for writing bytes to an output stream. Formats into two "lines", the first is the length of bytes plus Token.EOL, then the bytes plus Token.EOL.

Parameters:
data - the data bytes
out - the output stream
Throws:
java.io.IOException - if an input or output exception occurs

write2dData

public static final void write2dData(byte[][] data,
                                     java.io.OutputStream out)
                              throws java.io.IOException
Parameters:
data -
out -
Throws:
java.io.IOException

read2dData

public static final byte[][] read2dData(java.io.InputStream in)
                                 throws java.io.IOException
Parameters:
in -
Returns:
Throws:
java.io.IOException

write3dData

public static final void write3dData(byte[][][] data,
                                     java.io.OutputStream out)
                              throws java.io.IOException
Parameters:
data -
out -
Throws:
java.io.IOException

read3dData

public static final byte[][][] read3dData(java.io.InputStream in)
                                   throws java.io.IOException
Parameters:
in -
Returns:
Throws:
java.io.IOException

writeBytes

public static final void writeBytes(byte[] bytes,
                                    java.io.OutputStream out)
                             throws java.io.IOException
Parameters:
bytes -
out -
Throws:
java.io.IOException

readBytes

public static final byte[] readBytes(int length,
                                     java.io.InputStream in)
                              throws java.io.IOException
Parameters:
length -
in -
Returns:
Throws:
java.io.IOException

writeByte

public static final void writeByte(byte b,
                                   java.io.OutputStream out)
                            throws java.io.IOException
Parameters:
b -
out -
Throws:
java.io.IOException

readByte

public static final byte readByte(java.io.InputStream in)
                           throws java.io.IOException
Parameters:
in -
Returns:
Throws:
java.io.IOException

writeLong

public static final void writeLong(long l,
                                   java.io.OutputStream out)
                            throws java.io.IOException

Helper method for writing a long to an output stream.

Parameters:
l - the long to write
out - the output stream
Throws:
java.io.IOException - if an input or output exception occurs

readLong

public static final long readLong(java.io.InputStream is)
                           throws java.io.IOException

Helper method to read a long from an input stream.

Parameters:
is - the input stream
Returns:
the long read from the byte buffer
Throws:
java.io.IOException - if an input or output exception occurs

writeInt

public static final void writeInt(int i,
                                  java.io.OutputStream out)
                           throws java.io.IOException

Helper method for writing an integer to an output stream.

Parameters:
i - the integer to write
out - the output stream
Throws:
java.io.IOException - if an input or output exception occurs

readInt

public static final int readInt(java.io.InputStream is)
                         throws java.io.IOException

Helper method to read an integer from an input stream.

Parameters:
is - the input stream
Returns:
the int read from the byte buffer
Throws:
java.io.IOException - if an input or output exception occurs

writeBoolean

public static final void writeBoolean(boolean b,
                                      java.io.OutputStream out)
                               throws java.io.IOException

Helper method for writing an integer to an output stream.

Parameters:
b - the boolean to write
out - the output stream
Throws:
java.io.IOException - if an input or output exception occurs

readBoolean

public static final boolean readBoolean(java.io.InputStream is)
                                 throws java.io.IOException

Helper method to read an integer from an input stream.

Parameters:
is - the input stream
Returns:
the int read from the byte buffer
Throws:
java.io.IOException - if an input or output exception occurs

writeError

public static final void writeError(java.lang.String message,
                                    java.io.OutputStream out)
                             throws java.io.IOException

Helper method to write out an error message to the output stream.

Parameters:
message - the message to output as an error
out - the output stream
Throws:
java.io.IOException - if an input or output exception occurs

writeSignature

public static final void writeSignature(Signature sig,
                                        java.io.OutputStream bos)
                                 throws java.lang.Exception

Helper method to write out a signature to an output stream.

Parameters:
sig - the signature
bos - the output stream
Throws:
java.lang.Exception - if any exception occurs

readSignature

public static final Signature readSignature(java.io.InputStream in)
                                     throws java.lang.Exception

Helper method to read a signature from an input stream.

Parameters:
in - the input stream
Returns:
the signature
Throws:
java.lang.Exception - if any exception occurs

checkOK

public static final void checkOK(java.io.InputStream in)
                          throws java.io.IOException,
                                 java.security.GeneralSecurityException

Helper method that will throw an IOException if the input stream does not start with an Token.OK_STRING line.

Parameters:
in - the input stream
Throws:
java.io.IOException - if an input or output exception occurs
java.security.GeneralSecurityException

checkOK

public static final void checkOK(java.lang.String line,
                                 java.io.InputStream is)
                          throws java.io.IOException,
                                 java.security.GeneralSecurityException

Helper method that will throw an IOException if the line is not an Token.OK_STRING

Parameters:
line - the line checked for errors
is - the input stream
Throws:
java.io.IOException - if an input or output exception occurs
java.security.GeneralSecurityException


This code is free for use both commercially and non-commercially as stated in the project's license