de.esprit.appsuite.io

## Class ProgressInputStream

- java.lang.Object
- - java.io.InputStream
  - - java.io.FilterInputStream
    - - java.io.BufferedInputStream
      - - de.esprit.appsuite.io.ProgressInputStream

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
  Direct Known Subclasses:
    DownloadStream

      public class ProgressInputStream
      extends java.io.BufferedInputStream

  This stream reads data from the given InputStream and generates a progress notification for each percentage read (max 100 in total). Note that the number of progress notifications actually depends on the buffer-size used by the stream. Thus if only few data is read, you may see less than 100 notifications, but you never will see more than 100 no matter large the stream is.
  Author:
    Rainer Buesch

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `STREAM_BUFF_SIZE`

    - ### Fields inherited from class java.io.BufferedInputStream

      `buf, count, marklimit, markpos, pos`

    - ### Fields inherited from class java.io.FilterInputStream

      `in`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ProgressInputStream(AsyncExecutable progressorTask, java.io.File file)`
    `ProgressInputStream(AsyncExecutable progressorTask, FileInfo fileInfo, java.io.InputStream inStream)`
    `ProgressInputStream(java.io.File file)`
    `ProgressInputStream(FileInfo fileInfo, java.io.InputStream inStream)`
    `ProgressInputStream(ResourceInfo resourceFileInfo)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `fireProgress(java.lang.Object result, long step, java.lang.String progressMsg)` Is called each time the progress-threshold is exceeded, thus 100 times per read.
    `long` | `getByteCount()` Returns the number of bytes already read from this stream
    `FileInfo` | `getFileInfo()`
    `int` | `getFireCount()`
    `AsyncExecutable` | `getProgressorTask()` Returns the `AsyncExecutable` which is executing this progress stream.
    `int` | `getReadPercentage()`
    `long` | `getTotalBytes()`
    `int` | `read()`
    `int` | `read(byte[] buffer, int offset, int length)`
    `void` | `setProgressorTask(AsyncExecutable progressorTask)` Sets the `AsyncExecutable` which receives PROGRESS notifications.
    `long` | `skip(long bytes)`

    - ### Methods inherited from class java.io.BufferedInputStream

      `available, close, mark, markSupported, reset`

    - ### Methods inherited from class java.io.FilterInputStream

      `read`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### STREAM_BUFF_SIZE

          public static final int STREAM_BUFF_SIZE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ProgressInputStream

          public ProgressInputStream(java.io.File file)
                              throws java.io.FileNotFoundException

      Throws:
        `java.io.FileNotFoundException`

    - #### ProgressInputStream

          public ProgressInputStream(ResourceInfo resourceFileInfo)
                              throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### ProgressInputStream

          public ProgressInputStream(FileInfo fileInfo,
                             java.io.InputStream inStream)

    - #### ProgressInputStream

          public ProgressInputStream(AsyncExecutable progressorTask,
                             java.io.File file)
                              throws java.io.FileNotFoundException

      Throws:
        `java.io.FileNotFoundException`

    - #### ProgressInputStream

          public ProgressInputStream(AsyncExecutable progressorTask,
                             FileInfo fileInfo,
                             java.io.InputStream inStream)

  - ### Method Detail

    - #### getFileInfo

          public final FileInfo getFileInfo()

    - #### getByteCount

          public final long getByteCount()

      Returns the number of bytes already read from this stream

    - #### getTotalBytes

          public final long getTotalBytes()

    - #### getFireCount

          public final int getFireCount()

    - #### getReadPercentage

          public final int getReadPercentage()

    - #### setProgressorTask

          public final void setProgressorTask(AsyncExecutable progressorTask)

      Sets the `AsyncExecutable` which receives PROGRESS notifications. If no progressorTask is set, then no PROGRESS notifications are issued.

    - #### getProgressorTask

          public final AsyncExecutable getProgressorTask()

      Returns the `AsyncExecutable` which is executing this progress stream.

    - #### skip

          public final long skip(long bytes)
                          throws java.io.IOException

      Overrides:
        `skip` in class `java.io.BufferedInputStream`
      Throws:
        `java.io.IOException`

    - #### read

          public final int read()
                         throws java.io.IOException

      Overrides:
        `read` in class `java.io.BufferedInputStream`
      Throws:
        `java.io.IOException`

    - #### read

          public final int read(byte[] buffer,
                 int offset,
                 int length)
                         throws java.io.IOException

      Overrides:
        `read` in class `java.io.BufferedInputStream`
      Throws:
        `java.io.IOException`

    - #### fireProgress

          protected void fireProgress(java.lang.Object result,
                          long step,
                          java.lang.String progressMsg)

      Is called each time the progress-threshold is exceeded, thus 100 times per read. Maybe overridden to modify the message or the info sent to actual progress receiver. Note that you need to have a progressorTask set with `setProgressorTask(AsyncExecutable)`.

Copyright © 2014 EsprIT-Systems. All Rights Reserved.