Package org.python.core.io
Class StreamIO
- java.lang.Object
-
- org.python.core.io.IOBase
-
- org.python.core.io.RawIOBase
-
- org.python.core.io.StreamIO
-
public class StreamIO extends RawIOBase
Raw I/O implementation for simple streams. Supports Input/Outputstreams and Readable/WritableByteChannels.- Author:
- Philip Jenvey
-
-
Field Summary
-
Fields inherited from class org.python.core.io.IOBase
DEFAULT_BUFFER_SIZE
-
-
Constructor Summary
Constructors Constructor Description StreamIO(java.io.InputStream inputStream, boolean closefd)
Construct a StreamIO for the given read/write streams.StreamIO(java.io.OutputStream outputStream, boolean closefd)
Construct a StreamIO for the given read/write streams.StreamIO(java.nio.channels.ReadableByteChannel readChannel)
Construct a StreamIO for the given read channel.StreamIO(java.nio.channels.ReadableByteChannel readChannel, boolean closefd)
Construct a StreamIO for the given read channel.StreamIO(java.nio.channels.WritableByteChannel writeChannel)
Construct a StreamIO for the given write channel.StreamIO(java.nio.channels.WritableByteChannel writeChannel, boolean closefd)
Construct a StreamIO for the given write channel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.InputStream
asInputStream()
Coerce this into an InputStream if possible, or return null.java.io.OutputStream
asOutputStream()
Coerce this into an OutputStream if possible, or return null.void
close()
Flushes and closes the IO object.void
flush()
Flushes write buffers, if applicable.java.nio.channels.Channel
getChannel()
Return the underlying Java nio Channel.boolean
isatty()
Returns whether this is an 'interactive' stream.boolean
readable()
Return whether this file was opened for reading.int
readinto(java.nio.ByteBuffer buf)
Read up to buf.remaining() bytes into buf.boolean
writable()
Return whether this file was opened for writing.int
write(java.nio.ByteBuffer buf)
Write the given ByteBuffer to the IO stream.-
Methods inherited from class org.python.core.io.IOBase
checkClosed, checkReadable, checkWritable, closed, seek, seek, tell, truncate
-
-
-
-
Constructor Detail
-
StreamIO
public StreamIO(java.nio.channels.ReadableByteChannel readChannel, boolean closefd)
Construct a StreamIO for the given read channel.- Parameters:
readChannel
- a ReadableByteChannelclosefd
- boolean whether the underlying file is closed on close() (defaults to True)
-
StreamIO
public StreamIO(java.nio.channels.ReadableByteChannel readChannel)
Construct a StreamIO for the given read channel.- Parameters:
readChannel
- a ReadableByteChannel
-
StreamIO
public StreamIO(java.nio.channels.WritableByteChannel writeChannel, boolean closefd)
Construct a StreamIO for the given write channel.- Parameters:
writeChannel
- a WritableByteChannelclosefd
- boolean whether the underlying file is closed on close() (defaults to True)
-
StreamIO
public StreamIO(java.nio.channels.WritableByteChannel writeChannel)
Construct a StreamIO for the given write channel.- Parameters:
writeChannel
- a WritableByteChannel
-
StreamIO
public StreamIO(java.io.InputStream inputStream, boolean closefd)
Construct a StreamIO for the given read/write streams.- Parameters:
inputStream
- an InputStreamclosefd
- boolean whether the underlying file is closed on close() (defaults to True)
-
StreamIO
public StreamIO(java.io.OutputStream outputStream, boolean closefd)
Construct a StreamIO for the given read/write streams.- Parameters:
outputStream
- an OutputStreamclosefd
- boolean whether the underlying file is closed on close() (defaults to True)
-
-
Method Detail
-
readinto
public int readinto(java.nio.ByteBuffer buf)
Description copied from class:RawIOBase
Read up to buf.remaining() bytes into buf. Returns number of bytes read (0 for EOF).
-
write
public int write(java.nio.ByteBuffer buf)
Description copied from class:RawIOBase
Write the given ByteBuffer to the IO stream. Returns the number of bytes written, which may be less than buf.remaining().
-
flush
public void flush()
Description copied from class:IOBase
Flushes write buffers, if applicable. This is a no-op for read-only and non-blocking streams.
-
close
public void close()
Description copied from class:IOBase
Flushes and closes the IO object. This must be idempotent. It should also set a flag for the 'closed' property (see below) to test.
-
isatty
public boolean isatty()
Description copied from class:IOBase
Returns whether this is an 'interactive' stream. Returns False if we don't know.
-
readable
public boolean readable()
Description copied from class:IOBase
Return whether this file was opened for reading.
-
writable
public boolean writable()
Description copied from class:IOBase
Return whether this file was opened for writing.
-
asOutputStream
public java.io.OutputStream asOutputStream()
Description copied from class:IOBase
Coerce this into an OutputStream if possible, or return null.- Overrides:
asOutputStream
in classIOBase
-
asInputStream
public java.io.InputStream asInputStream()
Description copied from class:IOBase
Coerce this into an InputStream if possible, or return null.- Overrides:
asInputStream
in classIOBase
-
getChannel
public java.nio.channels.Channel getChannel()
Description copied from class:RawIOBase
Return the underlying Java nio Channel.- Specified by:
getChannel
in classRawIOBase
- Returns:
- the underlying Java nio Channel
-
-