Top Description Fields Constructors Methods
org.python.core.io

public Class StreamIO

extends RawIOBase
Class Inheritance
Known Direct Subclasses
org.python.modules.bz2.PyBZ2File.SkippableStreamIO
Imports
java.io.FileDescriptor, .FileInputStream, .FileOutputStream, .FilterInputStream, .FilterOutputStream, .IOException, .InputStream, .OutputStream, java.lang.reflect.Field, java.nio.ByteBuffer, java.nio.channels.Channel, .Channels, .ReadableByteChannel, .WritableByteChannel, java.nio.channels.spi.AbstractInterruptibleChannel, org.python.core.Py, org.python.modules.posix.PosixModule

Raw I/O implementation for simple streams. Supports Input/Outputstreams and Readable/WritableByteChannels.
Author
Philip Jenvey

Field Summary

Modifier and TypeField and Description
private boolean
closefd

true if the underlying file is actually closed on close()

private InputStream
inputStream

The original InputStream if one was passed in, used for __tojava__

private OutputStream
outputStream

The original OutputStream if one was passed in, used for __tojava__

private ReadableByteChannel
readChannel

The underlying read channel

private WritableByteChannel
writeChannel

The underlying write channel

Constructor Summary

AccessConstructor and Description
public
StreamIO(ReadableByteChannel
a ReadableByteChannel
readChannel
,
boolean
boolean whether the underlying file is closed on close() (defaults to True)
closefd
)

Construct a StreamIO for the given read channel.

public
StreamIO(ReadableByteChannel
a ReadableByteChannel
readChannel
)

Construct a StreamIO for the given read channel.

public
StreamIO(WritableByteChannel
a WritableByteChannel
writeChannel
,
boolean
boolean whether the underlying file is closed on close() (defaults to True)
closefd
)

Construct a StreamIO for the given write channel.

public
StreamIO(WritableByteChannel
a WritableByteChannel
writeChannel
)

Construct a StreamIO for the given write channel.

public
StreamIO(InputStream
an InputStream
inputStream
,
boolean
boolean whether the underlying file is closed on close() (defaults to True)
closefd
)

Construct a StreamIO for the given read/write streams.

public
StreamIO(OutputStream
an OutputStream
outputStream
,
boolean
boolean whether the underlying file is closed on close() (defaults to True)
closefd
)

Construct a StreamIO for the given read/write streams.

Method Summary

Modifier and TypeMethod and Description
public InputStream
asInputStream()

Overrides org.python.core.io.IOBase.asInputStream.

Coerce this into an InputStream if possible, or return null.

public OutputStream
asOutputStream()

Overrides org.python.core.io.IOBase.asOutputStream.

Coerce this into an OutputStream if possible, or return null.

public void
close()

Overrides org.python.core.io.IOBase.close.

Flushes and closes the IO object.

public void
flush()

Overrides org.python.core.io.IOBase.flush.

Flushes write buffers, if applicable.

public Channel
getChannel()

Implements abstract org.python.core.io.RawIOBase.getChannel.

Return the underlying Java nio Channel.

private static FileDescriptor
getInputFileDescriptor(InputStream stream)

Unwrap one or more nested FilterInputStreams.

private static FileDescriptor
getOutputFileDescriptor(OutputStream stream)

Unwrap one or more nested FilterOutputStreams.

public boolean
isatty()

Overrides org.python.core.io.IOBase.isatty.

Returns whether this is an 'interactive' stream.

private static ReadableByteChannel
public boolean
readable()

Overrides org.python.core.io.IOBase.readable.

Return whether this file was opened for reading.

public int
readinto(ByteBuffer
a ByteBuffer to read bytes into
buf
)

Overrides org.python.core.io.RawIOBase.readinto.

Read up to buf.remaining() bytes into buf.

public boolean
writable()

Overrides org.python.core.io.IOBase.writable.

Return whether this file was opened for writing.

public int
write(ByteBuffer
a ByteBuffer value
buf
)

Overrides org.python.core.io.RawIOBase.write.

Write the given ByteBuffer to the IO stream.

Inherited from org.python.core.io.RawIOBase:
filenoreadreadallreadintowrite

Field Detail

closefdback to summary
private boolean closefd

true if the underlying file is actually closed on close()

inputStreamback to summary
private InputStream inputStream

The original InputStream if one was passed in, used for __tojava__

outputStreamback to summary
private OutputStream outputStream

The original OutputStream if one was passed in, used for __tojava__

readChannelback to summary
private ReadableByteChannel readChannel

The underlying read channel

writeChannelback to summary
private WritableByteChannel writeChannel

The underlying write channel

Constructor Detail

StreamIOback to summary
public StreamIO(ReadableByteChannel readChannel, boolean closefd)

Construct a StreamIO for the given read channel.

Parameters
readChannel:ReadableByteChannel

a ReadableByteChannel

closefd:boolean

boolean whether the underlying file is closed on close() (defaults to True)

StreamIOback to summary
public StreamIO(ReadableByteChannel readChannel)

Construct a StreamIO for the given read channel.

Parameters
readChannel:ReadableByteChannel

a ReadableByteChannel

StreamIOback to summary
public StreamIO(WritableByteChannel writeChannel, boolean closefd)

Construct a StreamIO for the given write channel.

Parameters
writeChannel:WritableByteChannel

a WritableByteChannel

closefd:boolean

boolean whether the underlying file is closed on close() (defaults to True)

StreamIOback to summary
public StreamIO(WritableByteChannel writeChannel)

Construct a StreamIO for the given write channel.

Parameters
writeChannel:WritableByteChannel

a WritableByteChannel

StreamIOback to summary
public StreamIO(InputStream inputStream, boolean closefd)

Construct a StreamIO for the given read/write streams.

Parameters
inputStream:InputStream

an InputStream

closefd:boolean

boolean whether the underlying file is closed on close() (defaults to True)

StreamIOback to summary
public StreamIO(OutputStream outputStream, boolean closefd)

Construct a StreamIO for the given read/write streams.

Parameters
outputStream:OutputStream

an OutputStream

closefd:boolean

boolean whether the underlying file is closed on close() (defaults to True)

Method Detail

asInputStreamback to summary
public InputStream asInputStream()

Overrides org.python.core.io.IOBase.asInputStream.

Doc from org.python.core.io.IOBase.asInputStream.

Coerce this into an InputStream if possible, or return null.

Annotations
@Override
asOutputStreamback to summary
public OutputStream asOutputStream()

Overrides org.python.core.io.IOBase.asOutputStream.

Doc from org.python.core.io.IOBase.asOutputStream.

Coerce this into an OutputStream if possible, or return null.

Annotations
@Override
closeback to summary
public void close()

Overrides org.python.core.io.IOBase.close.

Doc from org.python.core.io.IOBase.close.

Flushes and closes the IO object. This must be idempotent. It should also set a flag for the 'closed' property (see below) to test.

Annotations
@Override
flushback to summary
public void flush()

Overrides org.python.core.io.IOBase.flush.

Doc from org.python.core.io.IOBase.flush.

Flushes write buffers, if applicable. This is a no-op for read-only and non-blocking streams.

Annotations
@Override
getChannelback to summary
public Channel getChannel()

Implements abstract org.python.core.io.RawIOBase.getChannel.

Doc from org.python.core.io.RawIOBase.getChannel.

Return the underlying Java nio Channel.

Returns:Channel

the underlying Java nio Channel

Annotations
@Override

getInputFileDescriptorback to summary
private static FileDescriptor getInputFileDescriptor(InputStream stream) throws IOException

Unwrap one or more nested FilterInputStreams.

getOutputFileDescriptorback to summary
private static FileDescriptor getOutputFileDescriptor(OutputStream stream) throws IOException

Unwrap one or more nested FilterOutputStreams.

isattyback to summary
public boolean isatty()

Overrides org.python.core.io.IOBase.isatty.

Doc from org.python.core.io.IOBase.isatty.

Returns whether this is an 'interactive' stream. Returns False if we don't know.

Returns:boolean

a boolean, true if an 'interactive' stream

Annotations
@Override

newChannelback to summary
private static ReadableByteChannel newChannel(InputStream in)
readableback to summary
public boolean readable()

Overrides org.python.core.io.IOBase.readable.

Doc from org.python.core.io.IOBase.readable.

Return whether this file was opened for reading.

Returns:boolean

true if the file was opened for reading

Annotations
@Override

readintoback to summary
public int readinto(ByteBuffer buf)

Overrides org.python.core.io.RawIOBase.readinto.

Doc from org.python.core.io.RawIOBase.readinto.

Read up to buf.remaining() bytes into buf. Returns number of bytes read (0 for EOF).

Parameters
buf:ByteBuffer

a ByteBuffer to read bytes into

Returns:int

the amount of data read as an int

Annotations
@Override

writableback to summary
public boolean writable()

Overrides org.python.core.io.IOBase.writable.

Doc from org.python.core.io.IOBase.writable.

Return whether this file was opened for writing.

Returns:boolean

true if the file was opened for writing

Annotations
@Override

writeback to summary
public int write(ByteBuffer buf)

Overrides org.python.core.io.RawIOBase.write.

Doc from org.python.core.io.RawIOBase.write.

Write the given ByteBuffer to the IO stream. Returns the number of bytes written, which may be less than buf.remaining().

Parameters
buf:ByteBuffer

a ByteBuffer value

Returns:int

the number of bytes written as an int

Annotations
@Override