Package ipsk.net
Class UploadCache
- java.lang.Object
-
- ipsk.net.UploadCache
-
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
HttpUploadCache,SplittingHttpUploadCache
public abstract class UploadCache extends java.lang.Object implements java.lang.RunnableCaches upload data and sends it to remote server.- Author:
- K.Jaensch, klausj@phonetik.uni-muenchen.de
- See Also:
Upload
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classUploadCache.EventTransformer
-
Field Summary
Fields Modifier and Type Field Description protected byte[]bufferprotected intbufSizeprotected floatbyteRateprotected static intCONNECT_RETRY_DELAYprotected booleanconnectedprotected longconnectedTimeInMillisprotected java.net.URLConnectionconnectionprotected UploadcurrentStreamprotected intcurrentStreamIndexprotected Upload[]currentUploadprotected static booleanDEBUGprotected static intDEBUG_DELAYstatic java.lang.StringDEF_CHECKSUM_ALGORITHMprotected static intDEFAULT_BUFSIZEprotected static intDEFAULT_CONNECT_RETRIESprotected UploadCache.EventTransformereventTransformerprotected longguessedToUploadLengthprotected longholdLengthprotected longholdSizeprotected booleanidleprotected booleanidleNotifiedprotected java.io.InputStreaminputStreamprotected static intON_IDLE_DELAYprotected java.io.OutputStreamoutputStreamprotected java.lang.StringrequestMethodprotected java.lang.StringresponseMessageprotected booleanrunningprotected longstartConnectprotected booleansyncedprotected longtotalLengthprotected longtotalUploadLengthprotected longtoUploadLengthprotected inttransferRateLimitprotected booleantransferRateLimitSupportedstatic intUNLIMITEDprotected static intUPLOAD_RETRIESprotected static intUPLOAD_RETRY_DELAYprotected intuploadRetryCount
-
Constructor Summary
Constructors Constructor Description UploadCache()Create new empty cache.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddUploadCacheListener(UploadCacheListener acl)Add listener.protected voidcalculateLength()voidclear()Clear all contents.voidclose()Close upload cache.protected voidfireConnected()protected voidfireDisconnected()protected voidfireFinished()protected voidfireStateChanged(Upload uvb)protected voidfireStateChangedWait(Upload uvb)protected voidfireTryConnect()floatgetByteRate()Get estimated upload byte rate.java.io.InputStream[]getCachedInputStream(java.net.URL[] urls)Try to get an input stream to cached data for the given URL.UploadgetCurrentUploadStream()Get the current upload.longgetGuessedToUploadLength()Get guessed bytes to upload.longgetHoldLength()Get current count of hold bytes.longgetHoldSize()Get maximum of bytes to hold in the cache.protected voidgetNextUpload()java.lang.StringgetRequestMethod()Get HTTP request method.intgetResponseCode()Get current HTTP response code.java.lang.StringgetResponseMessage()Get HTTP response message.longgetTotalLength()Get total length in bytes.longgetTotalUploadLength()Get total bytes already uploaded.longgetToUploadLength()Get bytes to upload.intgetTransferLimit()booleanisConnected()Get connected status.booleanisIdle()Get idle status.booleanisOverwrite()booleanisRunning()Get upload running status.booleanisTransferLimitSupported()voidremoveUploadCacheListener(UploadCacheListener acl)Remove listener.abstract voidrun()voidsetHoldSize(long l)Set maximum of bytes to hold in the cache.voidsetOverwrite(boolean overwrite)voidsetRequestMethod(java.lang.String string)Set HTTP request method.voidsetTransferLimit(int transferLimit)voidsetTransferLimitSupported(boolean transferLimitSupported)voidstart()Start upload.voidstop()Stop upload.voidupload(Upload[] vbs)Request an upload of the referenced data buffers to the given URLs.
-
-
-
Field Detail
-
DEF_CHECKSUM_ALGORITHM
public static final java.lang.String DEF_CHECKSUM_ALGORITHM
- See Also:
- Constant Field Values
-
DEBUG
protected static boolean DEBUG
-
UNLIMITED
public static final int UNLIMITED
- See Also:
- Constant Field Values
-
ON_IDLE_DELAY
protected static int ON_IDLE_DELAY
-
CONNECT_RETRY_DELAY
protected static int CONNECT_RETRY_DELAY
-
DEFAULT_CONNECT_RETRIES
protected static int DEFAULT_CONNECT_RETRIES
-
UPLOAD_RETRY_DELAY
protected static int UPLOAD_RETRY_DELAY
-
UPLOAD_RETRIES
protected static int UPLOAD_RETRIES
-
DEBUG_DELAY
protected static int DEBUG_DELAY
-
DEFAULT_BUFSIZE
protected static int DEFAULT_BUFSIZE
-
byteRate
protected float byteRate
-
connectedTimeInMillis
protected long connectedTimeInMillis
-
totalUploadLength
protected long totalUploadLength
-
connected
protected boolean connected
-
idle
protected boolean idle
-
idleNotified
protected boolean idleNotified
-
bufSize
protected int bufSize
-
outputStream
protected java.io.OutputStream outputStream
-
inputStream
protected java.io.InputStream inputStream
-
buffer
protected byte[] buffer
-
connection
protected java.net.URLConnection connection
-
requestMethod
protected java.lang.String requestMethod
-
currentUpload
protected Upload[] currentUpload
-
currentStream
protected Upload currentStream
-
currentStreamIndex
protected int currentStreamIndex
-
running
protected boolean running
-
eventTransformer
protected UploadCache.EventTransformer eventTransformer
-
startConnect
protected long startConnect
-
totalLength
protected long totalLength
-
toUploadLength
protected long toUploadLength
-
guessedToUploadLength
protected long guessedToUploadLength
-
holdLength
protected long holdLength
-
holdSize
protected long holdSize
-
synced
protected boolean synced
-
responseMessage
protected java.lang.String responseMessage
-
uploadRetryCount
protected int uploadRetryCount
-
transferRateLimitSupported
protected boolean transferRateLimitSupported
-
transferRateLimit
protected int transferRateLimit
-
-
Method Detail
-
calculateLength
protected void calculateLength()
-
upload
public void upload(Upload[] vbs) throws UploadException
Request an upload of the referenced data buffers to the given URLs.- Parameters:
vbs- the container of buffer references with data to upload- Throws:
UploadException
-
getCachedInputStream
public java.io.InputStream[] getCachedInputStream(java.net.URL[] urls) throws UploadExceptionTry to get an input stream to cached data for the given URL.- Parameters:
urls-- Returns:
- the input stream if the requested data was found in the cache
nullif the requested URL data was not found in the cache
- Throws:
UploadException
-
start
public void start()
Start upload.
-
stop
public void stop()
Stop upload.
-
getNextUpload
protected void getNextUpload()
-
run
public abstract void run()
- Specified by:
runin interfacejava.lang.Runnable
-
getCurrentUploadStream
public Upload getCurrentUploadStream()
Get the current upload.- Returns:
- current upload
-
isConnected
public boolean isConnected()
Get connected status.- Returns:
- true if connected
-
clear
public void clear()
Clear all contents.
-
close
public void close()
Close upload cache. Same as stop() and clear().
-
addUploadCacheListener
public void addUploadCacheListener(UploadCacheListener acl)
Add listener.- Parameters:
acl- listener to add
-
removeUploadCacheListener
public void removeUploadCacheListener(UploadCacheListener acl)
Remove listener.- Parameters:
acl- listener to remove
-
fireConnected
protected void fireConnected()
-
fireTryConnect
protected void fireTryConnect()
-
fireStateChanged
protected void fireStateChanged(Upload uvb)
-
fireStateChangedWait
protected void fireStateChangedWait(Upload uvb)
-
fireDisconnected
protected void fireDisconnected()
-
fireFinished
protected void fireFinished()
-
getTotalLength
public long getTotalLength()
Get total length in bytes.- Returns:
- total length of
-
getTotalUploadLength
public long getTotalUploadLength()
Get total bytes already uploaded.- Returns:
- uploaded count of bytes
-
isIdle
public boolean isIdle()
Get idle status.- Returns:
- idle status
-
getResponseCode
public int getResponseCode()
Get current HTTP response code.- Returns:
- HTTP response code
-
getResponseMessage
public java.lang.String getResponseMessage()
Get HTTP response message.- Returns:
- HTTP response message
-
getHoldSize
public long getHoldSize()
Get maximum of bytes to hold in the cache.- Returns:
- maximum hold size
-
setHoldSize
public void setHoldSize(long l)
Set maximum of bytes to hold in the cache.- Parameters:
l- maximum hold size
-
getHoldLength
public long getHoldLength()
Get current count of hold bytes.- Returns:
- bytes currently hold
-
getByteRate
public float getByteRate()
Get estimated upload byte rate.- Returns:
- byte rate in bytes/second
-
getToUploadLength
public long getToUploadLength()
Get bytes to upload. The current upload is ignored.- Returns:
- bytes to upload
- See Also:
getGuessedToUploadLength()
-
getGuessedToUploadLength
public long getGuessedToUploadLength()
Get guessed bytes to upload. The progress of the current upload can only be estimated.- Returns:
- estimated count of bytes not yet uploaded
-
getRequestMethod
public java.lang.String getRequestMethod()
Get HTTP request method.- Returns:
- request method
-
setRequestMethod
public void setRequestMethod(java.lang.String string)
Set HTTP request method.- Parameters:
string- request method
-
isRunning
public boolean isRunning()
Get upload running status.- Returns:
- true if upload thread is running.
-
isOverwrite
public boolean isOverwrite()
-
setOverwrite
public void setOverwrite(boolean overwrite)
-
getTransferLimit
public int getTransferLimit()
-
setTransferLimit
public void setTransferLimit(int transferLimit)
-
isTransferLimitSupported
public boolean isTransferLimitSupported()
-
setTransferLimitSupported
public void setTransferLimitSupported(boolean transferLimitSupported)
-
-