Oracle

com.compoze.util
Class TemporaryFileClient

java.lang.Object
  extended by com.compoze.util.TemporaryFileClient

public class TemporaryFileClient
extends java.lang.Object

This is a client that connects to a temporary file server to write some data. It may be used to gain access to a file on the machine where the temporary file server is running, which is useful when you wish to pass data to a program running on another machine that may only read from local resources. The process for connecting to the server is as follows:

  1. Open the connection.
  2. Read the header from the server and pass it an SHA digest of the password plus the 64 byte random challenge that it presents.
  3. Tell the server whether we want to use a specific filename or if a generated name is OK.
  4. Get the full filename from the server.
  5. Write the data to the server.
  6. Do any processing required with the remote file.
  7. Optionally read data back from the server (in case the server wrote to it).
  8. Notify the server that we're done with the file.
  9. Close the connection.

Methods should be called in this order:
  1. connect()
  2. write()
  3. ...(do any processing required with the remote file)
  4. dataComplete();
  5. getInputStream(); // optional to read data from server, close() in InputStream // closes the connection to the server
  6. close(); // only if getInputStream was not used

When running the main() method in this class (primarily just for testing purposes), Java system properties may be specified to configure the client. The following table describes the effect of the different properties:

Property Description Required? Default
password Sets the password that the client uses to gain access to the server. Yes N/A
file Sets a local file to send to the server. Yes N/A
ip Sets the IP address of the server. Yes N/A
port Sets the port of the server. No 2112

See Also:
TemporaryFileServer

Field Summary
static int COMMAND_ACCOUNTTOSID
           
static int COMMAND_SIDTOACCOUNT
           
static int COMMAND_TEMPFILE
           
 
Constructor Summary
TemporaryFileClient(java.net.InetAddress address, int iPort, java.lang.String sPassword, boolean bSSL)
          Constructor.
TemporaryFileClient(java.net.InetAddress address, int iPort, java.lang.String sPassword, java.lang.String sRequestedFilename, boolean bSSL)
          Constructor.
 
Method Summary
 void close()
          Closes the connection to the server, and indicates that the temporary file on the server is no longer in use.
 void connect()
          Connects to the server.
 void connect(int iCommand, java.lang.String sArgument)
          Connects to the server.
 java.lang.String dataComplete()
          Indicates that all data has been written and gets the filename on the server.
 java.io.InputStream getInputStream()
          Gets an InputStream to the data on the server.
static void main(java.lang.String[] args)
          Main.
 void write(byte[] array)
          Writes a byte array (flush is performed).
 void write(byte[] array, int iOffset, int iLength)
          Writes a byte array (flush is performed).
 void write(java.io.File file)
          Writes data from a file.
 void write(java.io.InputStream is)
          Writes data from an InputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMAND_TEMPFILE

public static final int COMMAND_TEMPFILE
See Also:
Constant Field Values

COMMAND_ACCOUNTTOSID

public static final int COMMAND_ACCOUNTTOSID
See Also:
Constant Field Values

COMMAND_SIDTOACCOUNT

public static final int COMMAND_SIDTOACCOUNT
See Also:
Constant Field Values
Constructor Detail

TemporaryFileClient

public TemporaryFileClient(java.net.InetAddress address,
                           int iPort,
                           java.lang.String sPassword,
                           boolean bSSL)
                    throws java.security.NoSuchAlgorithmException,
                           java.io.UnsupportedEncodingException
Constructor. Uses a default filename on the server.

Parameters:
address - the IP address of the server
iPort - the server port
sPassword - the server password
Throws:
java.security.NoSuchAlgorithmException - if algorithm not supported
java.io.UnsupportedEncodingException - if UTF-8 not supported

TemporaryFileClient

public TemporaryFileClient(java.net.InetAddress address,
                           int iPort,
                           java.lang.String sPassword,
                           java.lang.String sRequestedFilename,
                           boolean bSSL)
                    throws java.security.NoSuchAlgorithmException,
                           java.io.UnsupportedEncodingException
Constructor.

Parameters:
address - the IP address of the server
iPort - the server port
sPassword - the server password
sRequestedFilename - the filename to request that the server use
Throws:
java.security.NoSuchAlgorithmException - if algorithm not supported
java.io.UnsupportedEncodingException - if UTF-8 not supported
Method Detail

connect

public void connect()
             throws java.io.IOException,
                    java.security.NoSuchAlgorithmException,
                    java.lang.ClassNotFoundException
Connects to the server.

Parameters:
iCommand - the command
Throws:
java.io.IOException - if an i/o error occurred
java.security.NoSuchAlgorithmException - if the algorithm does not exist
java.lang.ClassNotFoundException - if the server sent an invalid class (should never happen)

connect

public void connect(int iCommand,
                    java.lang.String sArgument)
             throws java.io.IOException,
                    java.security.NoSuchAlgorithmException,
                    java.lang.ClassNotFoundException
Connects to the server.

Parameters:
iCommand - the command
sArgument - argument to the command
Throws:
java.io.IOException - if an i/o error occurred
java.security.NoSuchAlgorithmException - if the algorithm does not exist
java.lang.ClassNotFoundException - if the server sent an invalid class (should never happen)

write

public void write(java.io.File file)
           throws java.io.IOException
Writes data from a file. Must be connected.

Parameters:
file - the file to write
Throws:
java.io.IOException - if an i/o error occurred

write

public void write(java.io.InputStream is)
           throws java.io.IOException
Writes data from an InputStream. Must be connected.

Parameters:
is - the InputStream to read data from
Throws:
java.io.IOException - if an i/o error occurred

write

public void write(byte[] array)
           throws java.io.IOException
Writes a byte array (flush is performed). Must be connected.

Parameters:
array - the array to write, or null to write no data
Throws:
java.io.IOException - if an i/o error occurred

write

public void write(byte[] array,
                  int iOffset,
                  int iLength)
           throws java.io.IOException
Writes a byte array (flush is performed). Must be connected.

Parameters:
array - the array to write, or null to write no data
iOffset - the offset in the array to write from
iLength - the number of bytes to write
Throws:
java.io.IOException - if an i/o error occurred

dataComplete

public java.lang.String dataComplete()
                              throws java.io.IOException
Indicates that all data has been written and gets the filename on the server.

Returns:
the name of the file on the server for the TEMPFILE command, or some other response for another command
Throws:
java.io.IOException - if an i/o error occurred, or the server command failed for some other reason

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Gets an InputStream to the data on the server. This method may be called after dataComplete to get the data from the server. However, when the InputStream is closed the connection to the server is closed, so close must be called.

Returns:
an InputStream to the data
Throws:
java.io.IOException - if an i/o error occurred

close

public void close()
Closes the connection to the server, and indicates that the temporary file on the server is no longer in use.


main

public static void main(java.lang.String[] args)
Main.

Parameters:
args - command line arguments

Oracle

Copyright ©1999-2008 Oracle All rights reserved.