Package org.python.core.io
Class RawIOBase
java.lang.Object
org.python.core.io.IOBase
org.python.core.io.RawIOBase
- Direct Known Subclasses:
FileIO
,SocketIOBase
,StreamIO
Base class for raw binary I/O.
RawIOBases wrap raw Java I/O objects (typically nio Channels). They
provide a convenient means of handling raw Java I/O objects in the
context of Python files.
RawIOBases maintain state about their underlying I/O objects (such
as their mode) and translate Java exceptions into PyExceptions.
The read() method is implemented by calling readinto(); derived
classes that want to support read() only need to implement
readinto() as a primitive operation. In general, readinto() can be
more efficient than read().
- Author:
- Philip Jenvey
-
Field Summary
Fields inherited from class org.python.core.io.IOBase
DEFAULT_BUFFER_SIZE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfileno()
Returns underlying file descriptor if one exists.abstract Channel
Return the underlying Java nio Channel.read
(int size) Read and return up to size bytes, contained in a ByteBuffer.readall()
Read until EOF, using multiple read() calls.int
readinto
(ByteBuffer buf) Read up to buf.remaining() bytes into buf.long
readinto
(ByteBuffer[] bufs) Read bytes into each of the specified ByteBuffers.int
write
(ByteBuffer buf) Write the given ByteBuffer to the IO stream.long
write
(ByteBuffer[] bufs) Write the given ByteBuffers to the IO stream.Methods inherited from class org.python.core.io.IOBase
asInputStream, asOutputStream, checkClosed, checkReadable, checkWritable, close, closed, flush, isatty, readable, seek, seek, tell, truncate, writable
-
Constructor Details
-
RawIOBase
public RawIOBase()
-
-
Method Details
-
read
Read and return up to size bytes, contained in a ByteBuffer. ByteBuffers returned from read are already flip()'d. Returns an empty ByteBuffer on EOF- Parameters:
size
- the number of bytes to read- Returns:
- a ByteBuffer containing the bytes read
-
readall
Read until EOF, using multiple read() calls.- Returns:
- a ByteBuffer containing the bytes read
-
readinto
Read up to buf.remaining() bytes into buf. Returns number of bytes read (0 for EOF).- Parameters:
buf
- a ByteBuffer to read bytes into- Returns:
- the amount of data read as an int
-
readinto
Read bytes into each of the specified ByteBuffers. Returns number of bytes read (0 for EOF).- Parameters:
bufs
- an array of ByteBuffers to read bytes into- Returns:
- the amount of data read as a long
-
write
Write the given ByteBuffer to the IO stream. Returns the number of bytes written, which may be less than buf.remaining().- Parameters:
buf
- a ByteBuffer value- Returns:
- the number of bytes written as an int
-
write
Write the given ByteBuffers to the IO stream. Returns the number of bytes written, which may be less than the combined value of all the buf.remaining()'s.- Parameters:
bufs
- an array of ByteBuffers- Returns:
- the number of bytes written as a long
-
fileno
Description copied from class:IOBase
Returns underlying file descriptor if one exists. Raises IOError if the IO object does not use a file descriptor. -
getChannel
Return the underlying Java nio Channel.- Returns:
- the underlying Java nio Channel
-