Package org.python.core.io
Class TextIOBase
java.lang.Object
org.python.core.io.IOBase
org.python.core.io.TextIOBase
- Direct Known Subclasses:
BinaryIOWrapper,UniversalIOWrapper
Base class for text I/O.
This class provides a character and line based interface to stream
I/O.
- Author:
- Philip Jenvey
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe size of chunks read for readlineFields inherited from class org.python.core.io.IOBase
DEFAULT_BUFFER_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionTextIOBase(BufferedIOBase bufferedIO) Contruct a TextIOBase wrapping the given BufferedIOBase. -
Method Summary
Modifier and TypeMethodDescriptionCoerce this into an InputStream if possible, or return null.Coerce this into an OutputStream if possible, or return null.voidclose()Flushes and closes the IO object.booleanclosed()Return whether this file has been closed.fileno()Returns underlying file descriptor if one exists.voidflush()Flushes write buffers, if applicable.Return the known Newline types, as a PyObject, encountered while reading this file.booleanisatty()Returns whether this is an 'interactive' stream.read(int size) Read and return up to size bytes, contained in a String.booleanreadable()Return whether this file was opened for reading.readall()Read until EOF.intRead into the given PyObject that implements the Jython buffer API (with write access) or is a PyArray.readline(int size) Read until size, newline or EOF.longseek(long pos, int whence) Seek to byte offsetposrelative to position indicated bywhence.longtell()Return the current stream position.longtruncate(long pos) Truncate file to size in bytes.booleanwritable()Return whether this file was opened for writing.intWrite the given String to the IO stream.Methods inherited from class org.python.core.io.IOBase
checkClosed, checkReadable, checkWritable, seek
-
Field Details
-
CHUNK_SIZE
public static final int CHUNK_SIZEThe size of chunks read for readline- See Also:
-
-
Constructor Details
-
TextIOBase
Contruct a TextIOBase wrapping the given BufferedIOBase.- Parameters:
bufferedIO- a BufferedIOBase to wrap
-
-
Method Details
-
read
Read and return up to size bytes, contained in a String. Returns an empty String on EOF- Parameters:
size- the number of bytes to read- Returns:
- a String containing the bytes read
-
readall
Read until EOF.- Returns:
- a String containing the bytes read
-
readline
Read until size, newline or EOF. Returns an empty string if EOF is hit immediately.- Parameters:
size- the number of bytes to read- Returns:
- a String containing the bytes read
-
readinto
Read into the given PyObject that implements the Jython buffer API (with write access) or is a PyArray.- Parameters:
buf- a PyObject compatible with the buffer API- Returns:
- the amount of data read as an int
-
write
Write the given String to the IO stream. Returns the number of characters written.- Parameters:
buf- a String value- Returns:
- the number of characters written as an int
-
truncate
public long truncate(long pos) Description copied from class:IOBaseTruncate file to size in bytes. Returns the new size. -
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. -
close
public void close()Description copied from class:IOBaseFlushes and closes the IO object. This must be idempotent. It should also set a flag for the 'closed' property (see below) to test. -
seek
public long seek(long pos, int whence) Description copied from class:IOBaseSeek to byte offsetposrelative to position indicated bywhence.
Returns the new absolute position.Semantics whenceSeek to pos0 Start of stream (the default). Should be ≥0. 1 Current position + posEither sign. 2 End of stream + posUsually ≤0. -
tell
public long tell()Description copied from class:IOBaseReturn the current stream position. -
fileno
Description copied from class:IOBaseReturns underlying file descriptor if one exists. Raises IOError if the IO object does not use a file descriptor. -
isatty
public boolean isatty()Description copied from class:IOBaseReturns whether this is an 'interactive' stream. Returns False if we don't know. -
readable
public boolean readable()Description copied from class:IOBaseReturn whether this file was opened for reading. -
writable
public boolean writable()Description copied from class:IOBaseReturn whether this file was opened for writing. -
closed
public boolean closed()Description copied from class:IOBaseReturn whether this file has been closed. -
asInputStream
Description copied from class:IOBaseCoerce this into an InputStream if possible, or return null.- Overrides:
asInputStreamin classIOBase
-
asOutputStream
Description copied from class:IOBaseCoerce this into an OutputStream if possible, or return null.- Overrides:
asOutputStreamin classIOBase
-
getNewlines
Return the known Newline types, as a PyObject, encountered while reading this file. Returns None for all modes except universal newline mode.- Returns:
- a PyObject containing all encountered Newlines, or None
-