Package ipsk.net

Class UploadCache

  • All Implemented Interfaces:
    java.lang.Runnable
    Direct Known Subclasses:
    HttpUploadCache, SplittingHttpUploadCache

    public abstract class UploadCache
    extends java.lang.Object
    implements java.lang.Runnable
    Caches upload data and sends it to remote server.
    Author:
    K.Jaensch, klausj@phonetik.uni-muenchen.de
    See Also:
    Upload
    • Field Detail

      • DEF_CHECKSUM_ALGORITHM

        public static final java.lang.String DEF_CHECKSUM_ALGORITHM
        See Also:
        Constant Field Values
      • DEBUG

        protected static boolean DEBUG
      • 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
      • 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
    • Constructor Detail

      • UploadCache

        public UploadCache()
        Create new empty cache.
    • 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 UploadException
        Try 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
        • null if 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:
        run in interface java.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)