net.java.truecommons.io.AbstractSink Maven / Gradle / Ivy
Show all versions of truecommons-io Show documentation
/*
* Copyright (C) 2012 Schlichtherle IT Services.
* All rights reserved. Use is subject to license terms.
*/
package net.java.truecommons.io;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.channels.SeekableByteChannel;
/**
* An abstract provider for output streams or seekable byte channels.
*
* @author Christian Schlichtherle
*/
public abstract class AbstractSink implements Sink {
/**
* {@inheritDoc}
*
* The implementation in the class {@link AbstractSink} calls
* {@link #channel()} and wraps the result in a
* {@link ChannelOutputStream} adapter.
* Note that this violates the contract for this method unless you
* override either this method or {@link #channel()} with a valid
* implementation.
*/
@Override
public OutputStream stream() throws IOException {
return new ChannelOutputStream(channel());
}
/**
* {@inheritDoc}
*
* @throws UnsupportedOperationException the implementation in the class
* {@link AbstractSink} always throws an exception of
* this type.
*/
@Override
public SeekableByteChannel channel() throws IOException {
throw new UnsupportedOperationException();
}
}