com.metamx.common.guava.ResourceClosingYielder Maven / Gradle / Ivy
The newest version!
package com.metamx.common.guava;
import java.io.Closeable;
import java.io.IOException;
/**
*/
public class ResourceClosingYielder implements Yielder
{
private final Yielder baseYielder;
private final Closeable closeable;
public ResourceClosingYielder(Yielder baseYielder, Closeable closeable)
{
this.baseYielder = baseYielder;
this.closeable = closeable;
}
@Override
public OutType get()
{
return baseYielder.get();
}
@Override
public Yielder next(OutType initValue)
{
return new ResourceClosingYielder(baseYielder.next(initValue), closeable);
}
@Override
public boolean isDone()
{
return baseYielder.isDone();
}
@Override
public void close() throws IOException
{
if (closeable != null) {
closeable.close();
}
baseYielder.close();
}
}