Package org.python.core.io
Class BufferedIOBase
- java.lang.Object
-
- org.python.core.io.IOBase
-
- org.python.core.io.BufferedIOBase
-
- Direct Known Subclasses:
BufferedIOMixin
public abstract class BufferedIOBase extends IOBase
Base class for buffered I/O objects.- Author:
- Philip Jenvey
-
-
Field Summary
-
Fields inherited from class org.python.core.io.IOBase
DEFAULT_BUFFER_SIZE
-
-
Constructor Summary
Constructors Constructor Description BufferedIOBase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
buffered()
Return true if this objects buffer contains any data.void
clear()
Clear the read buffer if one exists.java.nio.ByteBuffer
peek(int size)
Returns buffered bytes without advancing the position.java.nio.ByteBuffer
read(int size)
Read and return up to size bytes, contained in a ByteBuffer.int
read1(java.nio.ByteBuffer bytes)
Reads up to bytes.remaining() bytes.java.nio.ByteBuffer
readall()
Read until EOF.int
readinto(java.nio.ByteBuffer bytes)
Read up to bytes.remaining() bytes into the given ByteBuffer.int
write(java.nio.ByteBuffer bytes)
Write the given ByteBuffer to the IO stream.-
Methods inherited from class org.python.core.io.IOBase
asInputStream, asOutputStream, checkClosed, checkReadable, checkWritable, close, closed, fileno, flush, isatty, readable, seek, seek, tell, truncate, writable
-
-
-
-
Method Detail
-
read
public java.nio.ByteBuffer read(int size)
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
public java.nio.ByteBuffer readall()
Read until EOF.- Returns:
- a ByteBuffer containing the bytes read
-
readinto
public int readinto(java.nio.ByteBuffer bytes)
Read up to bytes.remaining() bytes into the given ByteBuffer. Returns number of bytes read (0 for EOF).- Parameters:
bytes
- a ByteBuffer to read bytes into- Returns:
- the amount of data read as an int
-
write
public int write(java.nio.ByteBuffer bytes)
Write the given ByteBuffer to the IO stream. Returns the number of bytes written, which may be less than bytes.remaining().- Parameters:
bytes
- a ByteBuffer value- Returns:
- the number of bytes written as an int
-
peek
public java.nio.ByteBuffer peek(int size)
Returns buffered bytes without advancing the position. The argument indicates a desired minimal number of bytes; we do at most one raw read to satisfy it. We never return more than the size of the underlying buffer;- Parameters:
size
- the minimal number of bytes as an int- Returns:
- a ByteBuffer containing the bytes read
-
read1
public int read1(java.nio.ByteBuffer bytes)
Reads up to bytes.remaining() bytes. Returns up to bytes.remaining() bytes. If at least one byte is buffered, we only return buffered bytes. Otherwise, we do one raw read.- Parameters:
bytes
- a ByteBuffer to read bytes into- Returns:
- the amount of data read as an int
-
buffered
public boolean buffered()
Return true if this objects buffer contains any data.- Returns:
- boolean whether or not any data is currently buffered
-
clear
public void clear()
Clear the read buffer if one exists.
-
-