All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.metamx.common.guava.ResourceClosingSequence Maven / Gradle / Ivy

The newest version!
package com.metamx.common.guava;

import com.google.common.io.Closeables;

import java.io.Closeable;

/**
 */
public class ResourceClosingSequence extends YieldingSequenceBase
{
  private final Sequence baseSequence;
  private final Closeable closeable;

  public ResourceClosingSequence(Sequence baseSequence, Closeable closeable)
  {
    this.baseSequence = baseSequence;
    this.closeable = closeable;
  }

  @Override
  public  Yielder toYielder(
      OutType initValue, YieldingAccumulator accumulator
  )
  {
    final Yielder baseYielder;
    try {
      baseYielder = baseSequence.toYielder(initValue, accumulator);
    }
    catch (RuntimeException e) {
      Closeables.closeQuietly(closeable);
      throw e;
    }

    return new ResourceClosingYielder(baseYielder, closeable);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy