QJCC homepage

biz.chitec.quarterback.gjsa.server
Class FileUploadExecutor

java.lang.Object
  extended bybiz.chitec.quarterback.gjsa.server.CommandExecutor
      extended bybiz.chitec.quarterback.gjsa.server.FileUploadExecutor

public class FileUploadExecutor
extends CommandExecutor

Executor which can be used as base for an upload scheme. It implements the basic scheme of receiving the file to be uploaded part by part using the FILEPART command. The transmission must be ended by sending the FILECOMPLETE command after everything has been transmitted.

FileUploadExecutor should be added in its own server state. On successful file transfer, it leaves the new state automatically after the FILECOMPLETE command, or after the FILEABORT command has been sent.

This executor does not control the permission of the client to upload a file. It gets the filename in the executor and starts immediately by opening it. The constructor can be given two Runnables as callbacks for upload success or failure.

Version:
$Id: 5b7c84a37920c3569be9546258719df34571b9a1 $
Author:
cantamen/Dirk Hillbrecht 2004. Distributed under the terms of the GNU LGPL.

Nested Class Summary
static interface FileUploadExecutor.ReturnValueRunnable
          Special interface for successful callback If the callback given to the executor's constructor implements this interface, the executor will call the runWithReturnValue() method instead of the standard run() and return the result in the command answer
 
Field Summary
private  java.lang.Runnable failrun
           
private  boolean successful
           
private  java.lang.Runnable succrun
           
private  java.io.File targetfile
           
private  java.io.OutputStream targetstream
           
 
Fields inherited from class biz.chitec.quarterback.gjsa.server.CommandExecutor
myserv, mythreadbase, rb
 
Constructor Summary
FileUploadExecutor(ServerThreadBase thethreadbase, java.io.File targetx, java.lang.Runnable succrunx, java.lang.Runnable failrunx)
          Constructor for the FileUploadExecutor
 
Method Summary
 void leavingActions()
          Closes the file, deletes it on any failure, runs callback Runnables.
 ServerReply query(ServerRequest sq)
          Main query method
 
Methods inherited from class biz.chitec.quarterback.gjsa.server.CommandExecutor
getServerThreadBase, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

targetfile

private java.io.File targetfile

targetstream

private java.io.OutputStream targetstream

successful

private boolean successful

succrun

private java.lang.Runnable succrun

failrun

private java.lang.Runnable failrun
Constructor Detail

FileUploadExecutor

public FileUploadExecutor(ServerThreadBase thethreadbase,
                          java.io.File targetx,
                          java.lang.Runnable succrunx,
                          java.lang.Runnable failrunx)
                   throws java.io.IOException
Constructor for the FileUploadExecutor

Parameters:
thethreadbase - thread base object to be linked in
targetx - File to write transferred data in, will be overwritten
succrunx - Runnable to call if upload was successful, may be null
failrunx - Runnable to call if upload failed, may be null
Method Detail

query

public ServerReply query(ServerRequest sq)
Main query method

Overrides:
query in class CommandExecutor
Parameters:
sq - The query to handle
Returns:
ServerReply of the executed command, null if command could not be handled

leavingActions

public void leavingActions()
Closes the file, deletes it on any failure, runs callback Runnables.

Overrides:
leavingActions in class CommandExecutor

QJCC homepage