Package org.python.core.io
Class BufferedRandom
java.lang.Object
org.python.core.io.IOBase
org.python.core.io.BufferedIOBase
org.python.core.io.BufferedIOMixin
org.python.core.io.BufferedRandom
- Direct Known Subclasses:
LineBufferedRandom
A buffered reader and writer together for a random access file.
- Author:
- Philip Jenvey
-
Field Summary
Fields inherited from class org.python.core.io.IOBase
DEFAULT_BUFFER_SIZE
-
Constructor Summary
ConstructorDescriptionBufferedRandom
(RawIOBase rawIO, int bufferSize) Construct a BufferedRandom of bufferSize, wrapping the given RawIOBase. -
Method Summary
Modifier and TypeMethodDescriptionvoid
flush()
Flushes write buffers, if applicable.peek
(int size) Returns buffered bytes without advancing the position.read
(int size) Read and return up to size bytes, contained in a ByteBuffer.int
read1
(ByteBuffer bytes) Reads up to bytes.remaining() bytes.readall()
Read until EOF.int
readinto
(ByteBuffer bytes) Read up to bytes.remaining() bytes into the given ByteBuffer.long
seek
(long pos, int whence) Seek to byte offsetpos
relative to position indicated bywhence
.long
tell()
Return the current stream position.int
write
(ByteBuffer bytes) Write the given ByteBuffer to the IO stream.Methods inherited from class org.python.core.io.BufferedIOMixin
asInputStream, asOutputStream, close, closed, fileno, isatty, readable, truncate, writable
Methods inherited from class org.python.core.io.BufferedIOBase
buffered, clear
Methods inherited from class org.python.core.io.IOBase
checkClosed, checkReadable, checkWritable, seek
-
Constructor Details
-
BufferedRandom
Construct a BufferedRandom of bufferSize, wrapping the given RawIOBase.- Parameters:
rawIO
-bufferSize
-
-
-
Method Details
-
seek
public long seek(long pos, int whence) Description copied from class:IOBase
Seek to byte offsetpos
relative to position indicated bywhence
.Semantics whence
Seek to pos
0 Start of stream (the default). Should be ≥0. 1 Current position + pos
Either sign. 2 End of stream + pos
Usually ≤0. - Overrides:
seek
in classBufferedIOMixin
- Parameters:
pos
- a long position valuewhence
- an int whence value- Returns:
- a long position value seeked to
-
tell
public long tell()Description copied from class:IOBase
Return the current stream position.- Overrides:
tell
in classBufferedIOMixin
- Returns:
- a long position value
-
read
Description copied from class:BufferedIOBase
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- Overrides:
read
in classBufferedIOBase
- Parameters:
size
- the number of bytes to read- Returns:
- a ByteBuffer containing the bytes read
-
readall
Description copied from class:BufferedIOBase
Read until EOF.- Overrides:
readall
in classBufferedIOBase
- Returns:
- a ByteBuffer containing the bytes read
-
readinto
Description copied from class:BufferedIOBase
Read up to bytes.remaining() bytes into the given ByteBuffer. Returns number of bytes read (0 for EOF).- Overrides:
readinto
in classBufferedIOBase
- Parameters:
bytes
- a ByteBuffer to read bytes into- Returns:
- the amount of data read as an int
-
write
Description copied from class:BufferedIOBase
Write the given ByteBuffer to the IO stream. Returns the number of bytes written, which may be less than bytes.remaining().- Overrides:
write
in classBufferedIOBase
- Parameters:
bytes
- a ByteBuffer value- Returns:
- the number of bytes written as an int
-
peek
Description copied from class:BufferedIOBase
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;- Overrides:
peek
in classBufferedIOBase
- Parameters:
size
- the minimal number of bytes as an int- Returns:
- a ByteBuffer containing the bytes read
-
read1
Description copied from class:BufferedIOBase
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.- Overrides:
read1
in classBufferedIOBase
- Parameters:
bytes
- a ByteBuffer to read bytes into- Returns:
- the amount of data read as an int
-
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.- Overrides:
flush
in classBufferedIOMixin
-