Class InputStreamImageLink

java.lang.Object
org.jtrim2.image.async.InputStreamImageLink
All Implemented Interfaces:
AsyncDataLink<ImageResult>

public final class InputStreamImageLink extends Object implements AsyncDataLink<ImageResult>
Defines an AsyncDataLink providing images read from an InputStream. The InputStream is provided by a InputStreamOpener. To load the image, the ImageIO library of Java is used and therefore the meta data of the retrieved image is a JavaIIOMetaData.

The InputStreamImageLink is able to retrieve partially retrieved image and even the meta data without the image until the complete image is available. This however carries a certain amount of overhead because the partial image needs to be copied before being published. Therefore, users of InputStreamImageLink has to specify how much overhead they can tolerate, in order to display partially read images. The overhead is specified as a percentage of the time of the whole image reading process.

Thread safety

The methods of this class are safe to be accessed by multiple threads concurrently.

Synchronization transparency

The methods of this class are not synchronization transparent.
See Also:
  • Constructor Details

    • InputStreamImageLink

      public InputStreamImageLink(TaskExecutor executor, InputStreamOpener streamOpener, double allowedIntermediateRatio)
      Creates a new InputStreamImageLink which reads the image read from the specified InputStreamOpener on the given TaskExecutor.
      Parameters:
      executor - the TaskExecutor on which the image will be read from the input stream. This argument cannot be null.
      streamOpener - the InputStreamOpener providing the image to be loaded. This argument cannot be null.
      allowedIntermediateRatio - defines the approximate ratio (percentage divided by 100) of the overhead to be tolerated in order to provide intermediate images. Providing too high value for this argument might decrease performance considerably. That is, the overhead defined by this argument is likely to come true. For example: Specifying 0.5 for this argument will likely increase the time needed to read the complete image to twice the needed amount. This argument should be between 0.0 and 1.0 but the actual value of this argument is not verified. Specifying less than zero is equivalent to specifying zero, while specifying more than one, is equivalent to specifying one.
      Throws:
      NullPointerException - thrown if any of the arguments is null
  • Method Details

    • getData

      public AsyncDataController getData(CancellationToken cancelToken, AsyncDataListener<? super ImageResult> dataListener)

      Implementation note: This method will submit a task to retrieve the image to the executor specified at construction time.

      Specified by:
      getData in interface AsyncDataLink<ImageResult>
    • toString

      public String toString()
      Returns the string representation of this AsyncDataLink in no particular format

      This method is intended to be used for debugging only.

      Overrides:
      toString in class Object
      Returns:
      the string representation of this object in no particular format. This method never returns null.