Class TextIOBase

java.lang.Object
org.python.core.io.IOBase
org.python.core.io.TextIOBase
Direct Known Subclasses:
BinaryIOWrapper, UniversalIOWrapper

public abstract class TextIOBase extends IOBase
Base class for text I/O. This class provides a character and line based interface to stream I/O.
Author:
Philip Jenvey
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The size of chunks read for readline

    Fields inherited from class org.python.core.io.IOBase

    DEFAULT_BUFFER_SIZE
  • Constructor Summary

    Constructors
    Constructor
    Description
    Contruct a TextIOBase wrapping the given BufferedIOBase.
  • Method Summary

    Modifier and Type
    Method
    Description
    Coerce this into an InputStream if possible, or return null.
    Coerce this into an OutputStream if possible, or return null.
    void
    Flushes and closes the IO object.
    boolean
    Return whether this file has been closed.
    Returns underlying file descriptor if one exists.
    void
    Flushes write buffers, if applicable.
    Return the known Newline types, as a PyObject, encountered while reading this file.
    boolean
    Returns whether this is an 'interactive' stream.
    read(int size)
    Read and return up to size bytes, contained in a String.
    boolean
    Return whether this file was opened for reading.
    Read until EOF.
    int
    Read 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.
    long
    seek(long pos, int whence)
    Seek to byte offset pos relative to position indicated by whence.
    long
    Return the current stream position.
    long
    truncate(long pos)
    Truncate file to size in bytes.
    boolean
    Return whether this file was opened for writing.
    int
    Write the given String to the IO stream.

    Methods inherited from class org.python.core.io.IOBase

    checkClosed, checkReadable, checkWritable, seek

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CHUNK_SIZE

      public static final int CHUNK_SIZE
      The size of chunks read for readline
      See Also:
  • Constructor Details

    • TextIOBase

      public TextIOBase(BufferedIOBase bufferedIO)
      Contruct a TextIOBase wrapping the given BufferedIOBase.
      Parameters:
      bufferedIO - a BufferedIOBase to wrap
  • Method Details

    • read

      public String read(int size)
      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

      public String readall()
      Read until EOF.
      Returns:
      a String containing the bytes read
    • readline

      public String readline(int size)
      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

      public int readinto(PyObject buf)
      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

      public int write(String buf)
      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: IOBase
      Truncate file to size in bytes. Returns the new size.
      Overrides:
      truncate in class IOBase
      Parameters:
      pos - a long size to truncate to
      Returns:
      a long size value the file was truncated to
    • 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 class IOBase
    • close

      public void close()
      Description copied from class: IOBase
      Flushes and closes the IO object. This must be idempotent. It should also set a flag for the 'closed' property (see below) to test.
      Overrides:
      close in class IOBase
    • seek

      public long seek(long pos, int whence)
      Description copied from class: IOBase
      Seek to byte offset pos relative to position indicated by whence.
      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.
      Returns the new absolute position.
      Overrides:
      seek in class IOBase
      Parameters:
      pos - a long position value
      whence - 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 class IOBase
      Returns:
      a long position value
    • fileno

      public RawIOBase fileno()
      Description copied from class: IOBase
      Returns underlying file descriptor if one exists. Raises IOError if the IO object does not use a file descriptor.
      Overrides:
      fileno in class IOBase
      Returns:
      a file descriptor
    • isatty

      public boolean isatty()
      Description copied from class: IOBase
      Returns whether this is an 'interactive' stream. Returns False if we don't know.
      Overrides:
      isatty in class IOBase
      Returns:
      a boolean, true if an 'interactive' stream
    • readable

      public boolean readable()
      Description copied from class: IOBase
      Return whether this file was opened for reading.
      Overrides:
      readable in class IOBase
      Returns:
      true if the file was opened for reading
    • writable

      public boolean writable()
      Description copied from class: IOBase
      Return whether this file was opened for writing.
      Overrides:
      writable in class IOBase
      Returns:
      true if the file was opened for writing
    • closed

      public boolean closed()
      Description copied from class: IOBase
      Return whether this file has been closed.
      Overrides:
      closed in class IOBase
      Returns:
      true if the file has been closed
    • asInputStream

      public InputStream asInputStream()
      Description copied from class: IOBase
      Coerce this into an InputStream if possible, or return null.
      Overrides:
      asInputStream in class IOBase
    • asOutputStream

      public OutputStream asOutputStream()
      Description copied from class: IOBase
      Coerce this into an OutputStream if possible, or return null.
      Overrides:
      asOutputStream in class IOBase
    • getNewlines

      public PyObject 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