|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread wjhk.jupload2.upload.DefaultFileUploadThread
public abstract class DefaultFileUploadThread
This class is based on the FileUploadThread
class. It's an abstract
class that contains the default implementation for the
FileUploadThread
interface.
It contains the following abstract methods, which must be implemented in the
children classes. These methods are called in this order:
startRequest(long, boolean, int, boolean)
: start of the UploadRequest.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
Thread.State, Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
(package private) UploadFileData[] |
filesToUpload
The array that contains the current packet to upload. |
(package private) FileUploadManagerThread |
fileUploadManagerThread
The upload manager. |
protected String |
responseBody
The response message from the application. |
protected String |
responseMsg
The full response message from the server, if any. |
static long |
TIME_BEFORE_CHECKING_NEXT_PACKET
Number of milliseconds that this thread will wait between two calls to FileUploadManagerThread.getNextPacket() . |
protected UploadPolicy |
uploadPolicy
The upload policy contains all parameters needed to define the way files should be uploaded, including the URL. |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
DefaultFileUploadThread(String threadName,
UploadPolicy uploadPolicy,
FileUploadManagerThread fileUploadManagerThread)
Creates a new instance. |
Method Summary | |
---|---|
(package private) abstract void |
afterFile(int index)
Idem as beforeFile(int) , but is called after each file (and each
chunks for each file). |
(package private) abstract void |
beforeFile(int index)
This method is called before sending the bytes corresponding to the file whose index is given in argument. |
(package private) abstract void |
beforeRequest()
This method is called before starting of each request. |
(package private) abstract void |
cleanAll()
Clean any used resource, like a 'permanent' connection. |
(package private) abstract void |
cleanRequest()
Clean any used resource of the last executed request. |
void |
close()
Closes the connection to the server and releases resources. |
(package private) abstract int |
finishRequest()
This method is called at the end of each request. |
(package private) abstract long |
getAdditionnalBytesForUpload(int indexFile)
This method is called before the upload. |
(package private) abstract OutputStream |
getOutputStream()
Get the output stream where the files should be written for upload. |
String |
getResponseBody()
Return the the body for the server response. |
String |
getResponseMsg()
Get the server Output. |
(package private) abstract void |
interruptionReceived()
Reaction of the upload thread, when an interruption has been received. |
String |
normalizeCRLF(String s)
Replace single \r and \n by uniform end of line characters (CRLF). |
String |
quoteCRLF(String s)
Replace \r and \n by correctly displayed end of line characters. |
void |
run()
This method loops on the FileUploadManagerThread.getNextPacket()
method, until a set of files is ready. |
void |
setFileUploadThreadManager(FileUploadManagerThread fileUploadManagerThread)
Changes the FileUploadManagerThread. |
(package private) void |
setResponseBody(String body)
Unused Store the String that contains the server response body. |
(package private) void |
setResponseMsg(String msg)
Add a String that has been read from the server response. |
(package private) abstract void |
startRequest(long contentLength,
boolean bChunkEnabled,
int chunkPart,
boolean bLastChunk)
This method is called for each upload request to the server. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface wjhk.jupload2.upload.FileUploadThread |
---|
getState, interrupt, isAlive, join, join, start |
Field Detail |
---|
public static final long TIME_BEFORE_CHECKING_NEXT_PACKET
FileUploadManagerThread.getNextPacket()
.
UploadFileData[] filesToUpload
FileUploadManagerThread.getNextPacket()
FileUploadManagerThread fileUploadManagerThread
FileUploadManagerThread
protected UploadPolicy uploadPolicy
protected String responseMsg
protected String responseBody
Constructor Detail |
---|
public DefaultFileUploadThread(String threadName, UploadPolicy uploadPolicy, FileUploadManagerThread fileUploadManagerThread)
threadName
- The name of the thread, that will be displayed in the
debugger and in the logs.uploadPolicy
- The upload policy to be applied.fileUploadManagerThread
- The thread that is managing the upload.Method Detail |
---|
abstract long getAdditionnalBytesForUpload(int indexFile) throws JUploadIOException
FileData.beforeUpload()
method for all files to upload, and
prepares the progressBar bar (if any), with total number of bytes to
upload.
final private void beforeUpload() throws JUploadException { for (int i =
0; i < this.filesToUpload.length &&
!this.fileUploadManager.isUploadStopped(); i++) {
this.filesToUpload[i].beforeUpload(); } }
/** This methods upload overhead for the file number indexFile in the
filesDataParam given to the constructor. For instance, in HTTP, the
upload contains a head and a tail for each files.
indexFile
- The index of the file in the filesDataParam array, whose
addtional length is asked.
JUploadIOException
abstract void beforeRequest() throws JUploadException
filesToUpload
array.
JUploadException
abstract void startRequest(long contentLength, boolean bChunkEnabled, int chunkPart, boolean bLastChunk) throws JUploadException
getOutputStream()
methods is then
called to know where the uploaded files should be written.
contentLength
- The total number of bytes for the files (or the
chunk) to upload in this query.bChunkEnabled
- True if this upload is part of a file (can occurs
only if the maxChunkSize applet parameter is set). False
otherwise.chunkPart
- The chunk number. Should be ignored if bChunkEnabled is
false.bLastChunk
- True if in chunk mode, and this upload is the last one.
Should be ignored if bChunkEnabled is false.
JUploadException
abstract int finishRequest() throws JUploadException
JUploadException
startRequest(long, boolean, int, boolean)
abstract void interruptionReceived()
abstract void beforeFile(int index) throws JUploadException
index
- The index of the file that will be sent just after
JUploadException
abstract void afterFile(int index) throws JUploadException
beforeFile(int)
, but is called after each file (and each
chunks for each file).
index
- The index of the file that was just sent.
JUploadException
abstract void cleanRequest() throws JUploadException
JUploadException
abstract void cleanAll() throws JUploadException
JUploadException
abstract OutputStream getOutputStream() throws JUploadException
JUploadException
public String getResponseBody()
public String getResponseMsg()
getResponseMsg
in interface FileUploadThread
void setResponseBody(String body)
body
- The response body that has been read.void setResponseMsg(String msg)
msg
- The status message from the first line of the response (e.g.
"200 OK").public final void run()
FileUploadManagerThread.getNextPacket()
method, until a set of files is ready. Then, it calls the doUpload()
method, to send these files to the server.
run
in interface Runnable
run
in class Thread
public void close()
FileUploadThread
close
in interface FileUploadThread
FileUploadThread.close()
public final String normalizeCRLF(String s)
s
- The original string
public final String quoteCRLF(String s)
s
- The original string
public void setFileUploadThreadManager(FileUploadManagerThread fileUploadManagerThread) throws JUploadException
setFileUploadThreadManager
in interface FileUploadThread
JUploadException
FileUploadManagerThread
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |