Class FileSender

java.lang.Object
  |
  +--FileSender

public class FileSender
extends java.lang.Object


Constructor Summary
FileSender(java.lang.String file)
          Obtains the name of the file to be sent across to the client.
 
Method Summary
 byte[] readFile(java.lang.String name)
          Reads in the data from the file specifited by String name into a byte array and returns it.
 void runServer()
          Initializes the server.
 void sendFile(java.io.DataOutputStream ops, byte[] buf)
          Sends the data contained in the byte array through the DataOutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSender

public FileSender(java.lang.String file)
Obtains the name of the file to be sent across to the client.

Parameters:
file - a string indicating the name of the file to be sent.
Method Detail

runServer

public void runServer()
Initializes the server. This method will wait for a connection from a client and establish a TCP/IP connection. Upon receiving a request from the client for a file, the byte array of the file will be sent by a call to the sendPic method.

Returns:
void

readFile

public byte[] readFile(java.lang.String name)
                throws java.io.IOException
Reads in the data from the file specifited by String name into a byte array and returns it.

Parameters:
name - the name of the file to be read
Returns:
the buffer containing the file data.
Throws:
java.io.IOException

sendFile

public void sendFile(java.io.DataOutputStream ops,
                     byte[] buf)
              throws java.io.IOException
Sends the data contained in the byte array through the DataOutputStream. An int representing the size of the byte array will be sent first. The actual data contained in the array will follow.

Parameters:
ops - the DataOutputStream buf[] the byte array to send
Returns:
void
Throws:
java.io.IOException