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
public class BufferedRandom extends BufferedIOMixin
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
Constructors Constructor Description BufferedRandom(RawIOBase rawIO, int bufferSize)Construct a BufferedRandom of bufferSize, wrapping the given RawIOBase.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidflush()Flushes write buffers, if applicable.java.nio.ByteBufferpeek(int size)Returns buffered bytes without advancing the position.java.nio.ByteBufferread(int size)Read and return up to size bytes, contained in a ByteBuffer.intread1(java.nio.ByteBuffer bytes)Reads up to bytes.remaining() bytes.java.nio.ByteBufferreadall()Read until EOF.intreadinto(java.nio.ByteBuffer bytes)Read up to bytes.remaining() bytes into the given ByteBuffer.longseek(long pos, int whence)Seek to byte offset pos relative to position indicated by whence: 0 Start of stream (the default). pos should be >= 0; 1 Current position - whence may be negative; 2 End of stream - whence usually negative.longtell()Return the current stream position.intwrite(java.nio.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 Detail
-
BufferedRandom
public BufferedRandom(RawIOBase rawIO, int bufferSize)
Construct a BufferedRandom of bufferSize, wrapping the given RawIOBase.- Parameters:
rawIO-bufferSize-
-
-
Method Detail
-
seek
public long seek(long pos, int whence)Description copied from class:IOBaseSeek to byte offset pos relative to position indicated by whence: 0 Start of stream (the default). pos should be >= 0; 1 Current position - whence may be negative; 2 End of stream - whence usually negative. Returns the new absolute position.- Overrides:
seekin 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:IOBaseReturn the current stream position.- Overrides:
tellin classBufferedIOMixin- Returns:
- a long position value
-
read
public java.nio.ByteBuffer read(int size)
Description copied from class:BufferedIOBaseRead 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:
readin classBufferedIOBase- Parameters:
size- the number of bytes to read- Returns:
- a ByteBuffer containing the bytes read
-
readall
public java.nio.ByteBuffer readall()
Description copied from class:BufferedIOBaseRead until EOF.- Overrides:
readallin classBufferedIOBase- Returns:
- a ByteBuffer containing the bytes read
-
readinto
public int readinto(java.nio.ByteBuffer bytes)
Description copied from class:BufferedIOBaseRead up to bytes.remaining() bytes into the given ByteBuffer. Returns number of bytes read (0 for EOF).- Overrides:
readintoin classBufferedIOBase- 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)
Description copied from class:BufferedIOBaseWrite the given ByteBuffer to the IO stream. Returns the number of bytes written, which may be less than bytes.remaining().- Overrides:
writein classBufferedIOBase- Parameters:
bytes- a ByteBuffer value- Returns:
- the number of bytes written as an int
-
peek
public java.nio.ByteBuffer peek(int size)
Description copied from class:BufferedIOBaseReturns 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:
peekin classBufferedIOBase- 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)
Description copied from class:BufferedIOBaseReads 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:
read1in 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:IOBaseFlushes write buffers, if applicable. This is a no-op for read-only and non-blocking streams.- Overrides:
flushin classBufferedIOMixin
-
-