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

net.java.truevfs.comp.inst.InstrumentingInputSocket Maven / Gradle / Ivy

There is a newer version: 0.14.0
Show newest version
/*
 * Copyright (C) 2005-2015 Schlichtherle IT Services.
 * All rights reserved. Use is subject to license terms.
 */
package net.java.truevfs.comp.inst;

import java.io.IOException;
import java.io.InputStream;
import java.nio.channels.SeekableByteChannel;
import java.util.Objects;
import javax.annotation.CheckForNull;
import javax.annotation.concurrent.Immutable;
import net.java.truecommons.cio.DecoratingInputSocket;
import net.java.truecommons.cio.Entry;
import net.java.truecommons.cio.InputSocket;
import net.java.truecommons.cio.OutputSocket;

/**
 * @param   the type of the mediator.
 * @param   the type of the {@linkplain #target() target entry} for I/O
 *         operations.
 * @see    InstrumentingOutputSocket
 * @author Christian Schlichtherle
 */
@Immutable
public class InstrumentingInputSocket<
        M extends Mediator,
        E extends Entry>
extends DecoratingInputSocket {

    protected final M mediator;

    public InstrumentingInputSocket(
            final M mediator,
            final InputSocket socket) {
        super(socket);
        this.mediator = Objects.requireNonNull(mediator);
    }

    @Override
    public InputStream stream(@CheckForNull OutputSocket peer)
    throws IOException {
        return mediator.instrument(this, socket.stream(peer));
    }

    @Override
    public SeekableByteChannel channel(
            @CheckForNull OutputSocket peer)
    throws IOException {
        return mediator.instrument(this, socket.channel(peer));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy