com.foxsmart.ic.io
Interface FileLoader

All Known Implementing Classes:
FileLoaderImpl, HttpFileLoader

public interface FileLoader

This interface defines a mechanism to load files from a server to the local machine. An interface is provide so multiple file loader implementations are possible.


Method Summary
 void connect(java.lang.String hostname, java.lang.String port, java.lang.String username, java.lang.String password)
          This method initiates a connection from the client to the server.
 void disconnect()
          This method should terminate a connection to the server.
 long getFileSize(java.lang.String path, java.lang.String filename)
          This method should return the size of a file on the server
 boolean isConnected()
          Determines if the file loader is connected to a server.
 byte[] loadFile(java.lang.String path, java.lang.String filename, int increment, java.awt.event.ActionListener listener)
          This method will load a file from the server into a byte array.
 int writeFile(java.io.File file, int increment, byte[] byteArray, java.awt.event.ActionListener listener)
          This method will write a file from a byte array.
 

Method Detail

connect

void connect(java.lang.String hostname,
             java.lang.String port,
             java.lang.String username,
             java.lang.String password)
             throws java.lang.Exception
This method initiates a connection from the client to the server. It should verify that the server is reachable and perform any authentication which needs to occur in order to ensure a successful connection can be established. If the server requires no authentication, the username and password fields can be ignored. The port can also be ignored if it is not applicable.

Parameters:
hostname - The hostname to connect to
port - The port to connect to
username - The username to log into the server
password - The password to log into the server
Throws:
java.lang.Exception - if a successful connection could not be established.

disconnect

void disconnect()
                throws java.lang.Exception
This method should terminate a connection to the server.

Throws:
java.lang.Exception - if the connection could not be properly terminated.

isConnected

boolean isConnected()
Determines if the file loader is connected to a server.

Returns:
True if the file loader is connected or False if not.

getFileSize

long getFileSize(java.lang.String path,
                 java.lang.String filename)
                 throws java.lang.Exception
This method should return the size of a file on the server

Parameters:
path - The path to the file. All paths should be passed using a forward slash ("/") as a directory seperator. If this parameter is null, the current working directory on the server will be assumed.
filename - The filename on the server.
Returns:
The size of the file.
Throws:
java.lang.Exception - if the file size could not be determined.

loadFile

byte[] loadFile(java.lang.String path,
                java.lang.String filename,
                int increment,
                java.awt.event.ActionListener listener)
                throws java.lang.Exception
This method will load a file from the server into a byte array.

Parameters:
path - The path to the file. All paths should be passed using a forward slash ("/") as a directory seperator. If this parameter is null, the current working directory on the server will be assumed.
filename - The filename on the server.
increment - The prefered number of bytes to read during each pass before the action listener is called. Note that this parameter is a preference, but the actual number of bytes read during each pass is not guarunteed. A parameter of 0 indicates no preference.
listener - An action listener which will be notified whenever a portion of the file has been loaded. The 'command' part of this action event should contain the number of bytes which has been loaded since the last action event. Although it is not required that intermediate events be generated, it is preferred so the caller has a chance to provide user feedback. If this parameter is null, no action events will be generated.
Returns:
The contents of the file in a byte array.
Throws:
java.lang.Exception - if the file could not be loaded.

writeFile

int writeFile(java.io.File file,
              int increment,
              byte[] byteArray,
              java.awt.event.ActionListener listener)
              throws java.lang.Exception
This method will write a file from a byte array. Any directories which do not exist to the specified path should be automatically created. If a file already exists, it will be overwritten.

Parameters:
file - The file to write to.
increment - The prefered number of bytes to read during each pass before the action listener is called. Note that this parameter is a preference, but the actual number of bytes read during each pass is not guarunteed. A parameter of 0 indicates no preference.
byteArray - The byte array of files to be written.
listener - An action listener which will be notified whenever a portion of the file has been written. The 'command' part of this action event should contain the number of bytes which has been written since the last action event. Although it is not required that intermediate events be generated, it is preferred so the caller has a chance to provide user feedback. If this parameter is null, no action events will be generated.
Returns:
The total number of bytes written.
Throws:
java.lang.Exception - if the file could not be successfully written.


Copyright © 2005-2008 Fox Smart, Inc. All Rights Reserved.