com.foxsmart.ic.io
Class HttpFileLoader

java.lang.Object
  extended by com.foxsmart.ic.io.FileLoaderImpl
      extended by com.foxsmart.ic.io.HttpFileLoader
All Implemented Interfaces:
FileLoader

public class HttpFileLoader
extends FileLoaderImpl

This class provides a FileLoader which uses the HTTP protocol as the mechanism to load files from a server.


Constructor Summary
HttpFileLoader()
           
 
Method Summary
 void connect(java.lang.String hostname, java.lang.String port, java.lang.String username, java.lang.String password)
          This method determines if the server is accessible.
 void disconnect()
          Disconnects from server.
 long getFileSize(java.lang.String path, java.lang.String filename)
          This method returns the size of a given 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.
static void main(java.lang.String[] args)
          Test Driver.
 
Methods inherited from class com.foxsmart.ic.io.FileLoaderImpl
createFileLoader, loadFile, writeFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpFileLoader

public HttpFileLoader()
Method Detail

connect

public void connect(java.lang.String hostname,
                    java.lang.String port,
                    java.lang.String username,
                    java.lang.String password)
             throws java.lang.Exception
This method determines if the server is accessible. Since HTTP is a connectionless protocol, there is no actual connection which needs to occur.

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

public void disconnect()
                throws java.lang.Exception
Disconnects from server.

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

isConnected

public 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

public long getFileSize(java.lang.String path,
                        java.lang.String filename)
                 throws java.lang.Exception
This method returns the size of a given 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

public 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.

main

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

Parameters:
args - the arguments


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