public abstract class TextIOBase extends IOBase
Modifier and Type | Field and Description |
---|---|
protected BufferedIOBase |
bufferedIO
The underlying buffered i/o stream
|
protected java.lang.StringBuilder |
builder
Builds the final String returned from readline
|
static int |
CHUNK_SIZE
The size of chunks read for readline
|
protected static byte |
CR_BYTE
Byte representation of the Carriage Return character
|
protected char[] |
interimBuilder
An interim buffer for builder; readline loops move bytes into
this array to avoid StringBuilder.append method calls
|
protected java.nio.ByteBuffer |
readahead
The readahead buffer.
|
DEFAULT_BUFFER_SIZE, LF_BYTE
Constructor and Description |
---|
TextIOBase(BufferedIOBase bufferedIO)
Contruct a TextIOBase wrapping the given BufferedIOBase.
|
Modifier and Type | Method and 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.
|
protected boolean |
atEOF()
Return true if the file pointer is currently at EOF.
|
protected void |
clearReadahead()
Clear and reset the readahead buffer.
|
void |
close()
Flushes and closes the IO object.
|
boolean |
closed()
Return whether this file has been closed.
|
protected java.lang.String |
drainBuilder()
Return the String result of the builder, and reset it/perform
cleanup on it.
|
RawIOBase |
fileno()
Returns underlying file descriptor if one exists.
|
void |
flush()
Flushes write buffers, if applicable.
|
PyObject |
getNewlines()
Return the known Newline types, as a PyObject, encountered
while reading this file.
|
boolean |
isatty()
Returns whether this is an 'interactive' stream.
|
protected void |
packReadahead()
Restore the readahead to its original size (CHUNK_SIZE) if it
was previously resized.
|
java.lang.String |
read(int size)
Read and return up to size bytes, contained in a String.
|
boolean |
readable()
Return whether this file was opened for reading.
|
java.lang.String |
readall()
Read until EOF.
|
protected int |
readChunk()
Read a chunk of data of size CHUNK_SIZE into the readahead
buffer.
|
protected int |
readChunk(int size)
Read a chunk of data of the given size into the readahead
buffer.
|
int |
readinto(PyObject buf)
Read into the given PyObject that implements the Jython buffer API (with write access) or is
a PyArray.
|
java.lang.String |
readline(int size)
Read until size, newline or EOF.
|
long |
seek(long pos,
int whence)
Seek to byte offset
pos relative to position indicated by whence . |
long |
tell()
Return the current stream position.
|
long |
truncate(long pos)
Truncate file to size in bytes.
|
boolean |
writable()
Return whether this file was opened for writing.
|
int |
write(java.lang.String buf)
Write the given String to the IO stream.
|
checkClosed, checkReadable, checkWritable, seek, unsupported
public static final int CHUNK_SIZE
protected static final byte CR_BYTE
protected BufferedIOBase bufferedIO
protected java.nio.ByteBuffer readahead
protected java.lang.StringBuilder builder
protected char[] interimBuilder
public TextIOBase(BufferedIOBase bufferedIO)
bufferedIO
- a BufferedIOBase to wrappublic java.lang.String read(int size)
size
- the number of bytes to readpublic java.lang.String readall()
public java.lang.String readline(int size)
size
- the number of bytes to readpublic int readinto(PyObject buf)
buf
- a PyObject compatible with the buffer APIpublic int write(java.lang.String buf)
buf
- a String valuepublic long truncate(long pos)
IOBase
public void flush()
IOBase
public void close()
IOBase
public long seek(long pos, int whence)
IOBase
pos
relative to position indicated by whence
.
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. |
public long tell()
IOBase
public RawIOBase fileno()
IOBase
public boolean isatty()
IOBase
public boolean readable()
IOBase
public boolean writable()
IOBase
public boolean closed()
IOBase
public java.io.InputStream asInputStream()
IOBase
asInputStream
in class IOBase
public java.io.OutputStream asOutputStream()
IOBase
asOutputStream
in class IOBase
public PyObject getNewlines()
protected boolean atEOF()
protected int readChunk()
protected int readChunk(int size)
size
- the desired size of the chunkprotected void packReadahead()
protected void clearReadahead()
protected java.lang.String drainBuilder()