org.python.core.io

## Class IOBase

- java.lang.Object
- - org.python.core.io.IOBase

Direct Known Subclasses:
  BufferedIOBase, RawIOBase, TextIOBase

    public abstract class IOBase
    extends java.lang.Object

Base class for all I/O classes. IOBase and its descendents in org.python.core.io are based off Python 3's new io module (PEP 3116). This does not define read(), readinto() and write(), nor readline() and friends, since their signatures vary per layer.

Author:
  Philip Jenvey

### Field Summary

Fields
`static int` `DEFAULT_BUFFER_SIZE` The default size of generic buffers

### Constructor Summary

Constructors
Constructor and Description
`IOBase()`

### Method Summary

All Methods Instance Methods Concrete Methods
`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.
`void` `checkClosed()` Raise a ValueError if the file is closed.
`void` `checkReadable()` Raise an IOError if the file is not readable.
`void` `checkWritable()` Raise an IOError if the file is not writable.
`void` `close()` Flushes and closes the IO object.
`boolean` `closed()` Return whether this file has been closed.
`RawIOBase` `fileno()` Returns underlying file descriptor if one exists.
`void` `flush()` Flushes write buffers, if applicable.
`boolean` `isatty()` Returns whether this is an 'interactive' stream.
`boolean` `readable()` Return whether this file was opened for reading.
`long` `seek(long pos)` Seek to byte offset pos relative to the start of the stream.
`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 size)` Truncate file to size in bytes.
`boolean` `writable()` Return whether this file was opened for writing.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### DEFAULT_BUFFER_SIZE

    public static final int DEFAULT_BUFFER_SIZE

The default size of generic buffers

See Also:
  Constant Field Values

### Constructor Detail

#### IOBase

    public IOBase()

### Method Detail

#### seek

    public long seek(long pos)

Seek to byte offset pos relative to the start of the stream. Returns the new absolute position.

Parameters:
  `pos` - a long position value
Returns:
  a long position value seeked to

#### seek

    public long seek(long pos,
                     int whence)

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.

Parameters:
  `pos` - a long position value
  `whence` - an int whence value
Returns:
  a long position value seeked to

#### tell

    public long tell()

Return the current stream position.

Returns:
  a long position value

#### truncate

    public long truncate(long size)

Truncate file to size in bytes. Returns the new size.

Parameters:
  `size` - a long size to truncate to
Returns:
  a long size value the file was truncated to

#### flush

    public void flush()

Flushes write buffers, if applicable. This is a no-op for read-only and non-blocking streams.

#### close

    public void close()

Flushes and closes the IO object. This must be idempotent. It should also set a flag for the 'closed' property (see below) to test.

#### fileno

    public RawIOBase fileno()

Returns underlying file descriptor if one exists. Raises IOError if the IO object does not use a file descriptor.

Returns:
  a file descriptor

#### isatty

    public boolean isatty()

Returns whether this is an 'interactive' stream. Returns False if we don't know.

Returns:
  a boolean, true if an 'interactive' stream

#### readable

    public boolean readable()

Return whether this file was opened for reading.

Returns:
  true if the file was opened for reading

#### checkReadable

    public void checkReadable()

Raise an IOError if the file is not readable.

#### writable

    public boolean writable()

Return whether this file was opened for writing.

Returns:
  true if the file was opened for writing

#### checkWritable

    public void checkWritable()

Raise an IOError if the file is not writable.

#### closed

    public boolean closed()

Return whether this file has been closed.

Returns:
  true if the file has been closed

#### checkClosed

    public void checkClosed()

Raise a ValueError if the file is closed.

#### asOutputStream

    public java.io.OutputStream asOutputStream()

Coerce this into an OutputStream if possible, or return null.

#### asInputStream

    public java.io.InputStream asInputStream()

Coerce this into an InputStream if possible, or return null.