Top Description Inners Fields Constructors Methods
org.jruby.util.io

public abstract Class ChannelHelper

extends Object
Class Inheritance
Imports
org.jruby.RubyInstanceConfig, org.jruby.javasupport.Java, java.io.ByteArrayInputStream, .FilterInputStream, .FilterOutputStream, .IOException, .InputStream, .OutputStream, java.lang.reflect.Field, java.nio.ByteBuffer, java.nio.channels.Channels, .ReadableByteChannel, .WritableByteChannel, java.nio.channels.spi.AbstractInterruptibleChannel

Helper that attempts to improve Channels' static helpers.
Author
kares

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final Field
private static final Field

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static boolean
public static ReadableByteChannel
readableChannel(final InputStream inputStream)

public static OutputStream

Returns:

An unwrapped stream, presumably unbuffered
unwrapBufferedStream
(OutputStream
The stream to unwrap
filteredStream
)

Unwrap all filtering streams between the given stream and its actual unfiltered stream.

public static InputStream

Returns:

An unwrapped stream, presumably unbuffered
unwrapBufferedStream
(InputStream
The stream to unwrap
filteredStream
)

Unwrap all filtering streams between the given stream and its actual unfiltered stream.

private static OutputStream
private static InputStream
public static InputStream

Returns:

the deeped non-FilterInputStream stream, or filterInputStream if it is not a FilterInputStream to begin with.
unwrapFilterInputStream
(InputStream
a stream to be unwrapped, if it is a FilterInputStream
filteredStream
)

Unwrap the given stream to its first non-FilterInputStream.

public static OutputStream

Returns:

the deeped non-FilterOutputStream stream, or filterOutputStream if it is not a FilterOutputStream to begin with.
unwrapFilterOutputStream
(OutputStream
a stream to be unwrapped, if it is a FilterOutputStream
filteredStream
)

Unwrap the given stream to its first non-FilterOutputStream.

public static WritableByteChannel
writableChannel(final OutputStream outputStream)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

filterInFieldback to summary
private static final Field filterInField
filterOutFieldback to summary
private static final Field filterOutField

Constructor Detail

ChannelHelperback to summary
private ChannelHelper()

Method Detail

isDripSwitchableback to summary
private static boolean isDripSwitchable(Object stream)
readableChannelback to summary
public static ReadableByteChannel readableChannel(final InputStream inputStream)
unwrapBufferedStreamback to summary
public static OutputStream unwrapBufferedStream(OutputStream filteredStream)

Unwrap all filtering streams between the given stream and its actual unfiltered stream. This is primarily to unwrap streams that have buffers that would interfere with interactivity.

Parameters
filteredStream:OutputStream

The stream to unwrap

Returns:OutputStream

An unwrapped stream, presumably unbuffered

unwrapBufferedStreamback to summary
public static InputStream unwrapBufferedStream(InputStream filteredStream)

Unwrap all filtering streams between the given stream and its actual unfiltered stream. This is primarily to unwrap streams that have buffers that would interfere with interactivity.

Parameters
filteredStream:InputStream

The stream to unwrap

Returns:InputStream

An unwrapped stream, presumably unbuffered

unwrapDripStreamback to summary
private static OutputStream unwrapDripStream(OutputStream stream)
unwrapDripStreamback to summary
private static InputStream unwrapDripStream(InputStream stream)
unwrapFilterInputStreamback to summary
public static InputStream unwrapFilterInputStream(InputStream filteredStream)

Unwrap the given stream to its first non-FilterInputStream. If the stream is not a FilterInputStream it is returned immediately. Note that this version is used when you are absolutely sure you want to unwrap; the unwrapBufferedStream version will perform checks for certain types of process-related streams that should not be unwrapped (Java 7+ Process, e.g.).

Parameters
filteredStream:InputStream

a stream to be unwrapped, if it is a FilterInputStream

Returns:InputStream

the deeped non-FilterInputStream stream, or filterInputStream if it is not a FilterInputStream to begin with.

unwrapFilterOutputStreamback to summary
public static OutputStream unwrapFilterOutputStream(OutputStream filteredStream)

Unwrap the given stream to its first non-FilterOutputStream. If the stream is not a FilterOutputStream it is returned immediately. Note that this version is used when you are absolutely sure you want to unwrap; the unwrapBufferedStream version will perform checks for certain types of process-related streams that should not be unwrapped (Java 7+ Process, e.g.).

Parameters
filteredStream:OutputStream

a stream to be unwrapped, if it is a FilterOutputStream

Returns:OutputStream

the deeped non-FilterOutputStream stream, or filterOutputStream if it is not a FilterOutputStream to begin with.

writableChannelback to summary
public static WritableByteChannel writableChannel(final OutputStream outputStream)
org.jruby.util.io back to summary

private Class ChannelHelper.SyncOutputStreamChannel

extends AbstractInterruptibleChannel
implements WritableByteChannel
Class Inheritance
All Implemented Interfaces
java.nio.channels.WritableByteChannel, java.nio.channels.Channel, java.io.Closeable, java.lang.AutoCloseable

Field Summary

Modifier and TypeField and Description
pack-priv final WritableByteChannel
private final OutputStream

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
public int
write(ByteBuffer
The buffer from which bytes are to be retrieved
src
)

Implements java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

Inherited from java.nio.channels.spi.AbstractInterruptibleChannel:
begincloseendisOpen

Field Detail

outback to summary
pack-priv final WritableByteChannel out
outputback to summary
private final OutputStream output

Constructor Detail

SyncOutputStreamChannelback to summary
pack-priv SyncOutputStreamChannel(OutputStream output)

Method Detail

implCloseChannelback to summary
protected void implCloseChannel() throws IOException

Implements abstract java.nio.channels.spi.AbstractInterruptibleChannel.implCloseChannel.

Doc from java.nio.channels.spi.AbstractInterruptibleChannel.implCloseChannel.

Closes this channel.

This method is invoked by the close method in order to perform the actual work of closing the channel. This method is only invoked if the channel has not yet been closed, and it is never invoked more than once.

An implementation of this method must arrange for any other thread that is blocked in an I/O operation upon this channel to return immediately, either by throwing an exception or by returning normally.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs while closing the channel
writeback to summary
public int write(ByteBuffer src) throws IOException

Implements java.nio.channels.WritableByteChannel.write.

Doc from java.nio.channels.WritableByteChannel.write.

Writes a sequence of bytes to this channel from the given buffer.

An attempt is made to write up to r bytes to the channel, where r is the number of bytes remaining in the buffer, that is, src.remaining(), at the moment this method is invoked.

Suppose that a byte sequence of length n is written, where 0 <= n <= r. This byte sequence will be transferred from the buffer starting at index p, where p is the buffer's position at the moment this method is invoked; the index of the last byte written will be p + n - 1. Upon return the buffer's position will be equal to p + n; its limit will not have changed.

Unless otherwise specified, a write operation will return only after writing all of the r requested bytes. Some types of channels, depending upon their state, may write only some of the bytes or possibly none at all. A socket channel in non-blocking mode, for example, cannot write any more bytes than are free in the socket's output buffer.

This method may be invoked at any time. If another thread has already initiated a write operation upon this channel, however, then an invocation of this method will block until the first operation is complete.

Parameters
src:ByteBuffer

The buffer from which bytes are to be retrieved

Returns:int

The number of bytes written, possibly zero

Annotations
@Override
Exceptions
IOException:
If some other I/O error occurs