Package com.luciad.io

Class TLcdFailureCachingInputStreamFactory

java.lang.Object
com.luciad.io.TLcdFailureCachingInputStreamFactory
All Implemented Interfaces:
ILcdInputStreamFactory

public final class TLcdFailureCachingInputStreamFactory extends Object implements ILcdInputStreamFactory
This class implements a decorator for another ILcdInputStreamFactory (the delegate), and remembers for which sources the delegate failed to create an InputStream.

When asked to createInputStream(String), it checks whether a previous attempt "recently" failed. If there is a recent failure, the exception from that previous attempt is thrown. If there is no such recent failure, the delegate is asked to create an InputStream for the source. The amount of time considered "recent" is configured via the constructor arguments.

Recent failures do not affect canCreateInputStream(String): it always asks the delegate.

Wrapping an ILcdInputStreamFactory is useful when you expect that many input streams will be created for the same source(s), and it is likely that some of them are not available. As an example, this happens when lazily decoding a model consisting of many files, and you do not know beforehand which files actually exist.

This class is thread-safe if the delegate is.

Since:
2022.1
  • Constructor Details

    • TLcdFailureCachingInputStreamFactory

      public TLcdFailureCachingInputStreamFactory(ILcdInputStreamFactory aDelegate, long aRetryPeriod, TimeUnit aTimeUnit)
      Creates a new instance that decorates the delegate.

      The retry period controls how long this input stream factory will wait before attempting to connect to a source that previously failed. If attempts are made before the retry period has passed, the previous exception will be rethrown without trying to connect.

      Parameters:
      aDelegate - the delegate
      aRetryPeriod - the retry period, strictly positive
      aTimeUnit - unit of aRetryPeriod
  • Method Details

    • canCreateInputStream

      public boolean canCreateInputStream(String aSource)
      Description copied from interface: ILcdInputStreamFactory
      Checks whether this input stream factory can provide access to aSource. It is acceptable for this method to return true for a source while createInputStream throws an exception for that same source.

      For performance reasons, we strongly recommend that implementations perform only a simple test. For example: check the structure of aSource to see if it is a URI with a specific scheme, but do not verify that aSource really is accessible.

      The default implementation of this method returns true. Make sure to override this method if you can easily reject sources. This can help avoid pointless invocations of createInputStream which would have to throw exceptions for unsupported sources.

      Specified by:
      canCreateInputStream in interface ILcdInputStreamFactory
      Parameters:
      aSource - the data source to be verified; typically a file name or a URL.
      Returns:
      true if this input stream factory can likely access the source, false otherwise.
      See Also:
    • createInputStream

      public InputStream createInputStream(String aSource) throws IOException
      Description copied from interface: ILcdInputStreamFactory
      Creates an InputStream from aSource.
      Specified by:
      createInputStream in interface ILcdInputStreamFactory
      Parameters:
      aSource - an accessible data source.
      Returns:
      an InputStream from the data source.
      Throws:
      IOException - when aSource is not accepted by canCreateInputStream or is not accessible.
      See Also: