/**
   * Constructs a {@code MemoryCacheImageInputStream} that will read from a given {@code
   * InputStream}.
   *
   * @param stream an {@code InputStream} to read from.
   * @exception IllegalArgumentException if {@code stream} is {@code null}.
   */
  public MemoryCacheImageInputStream(InputStream stream) {
    if (stream == null) {
      throw new IllegalArgumentException("stream == null!");
    }
    this.stream = stream;

    disposerRecord = new StreamDisposerRecord(cache);
    if (getClass() == MemoryCacheImageInputStream.class) {
      disposerReferent = new Object();
      Disposer.addRecord(disposerReferent, disposerRecord);
    } else {
      disposerReferent = new StreamFinalizer(this);
    }
  }
Пример #2
0
  /**
   * Constructs a <code>FileImageInputStream</code> that will read from a given <code>
   * RandomAccessFile</code>.
   *
   * <p>The file contents must not change between the time this object is constructed and the time
   * of the last call to a read method.
   *
   * @param raf a <code>RandomAccessFile</code> to read from.
   * @exception IllegalArgumentException if <code>raf</code> is <code>null</code>.
   */
  public FileImageInputStream(RandomAccessFile raf) {
    if (raf == null) {
      throw new IllegalArgumentException("raf == null!");
    }
    this.raf = raf;

    disposerRecord = new CloseableDisposerRecord(raf);
    if (getClass() == FileImageInputStream.class) {
      disposerReferent = new Object();
      Disposer.addRecord(disposerReferent, disposerRecord);
    } else {
      disposerReferent = new StreamFinalizer(this);
    }
  }