IOBase (Jython API documentation)
Date: 2012-08-13

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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 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
`static int` | `DEFAULT_BUFFER_SIZE` The default size of generic buffers

Constructor Summary
`IOBase()`

Method Summary
`InputStream` | `asInputStream()` Coerce this into an InputStream if possible, or return null.
`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: 0 Start of stream (the default). pos should be >= 0; 1 Current position - whence may be negative; 2 End of stream - whence usually negative.
`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: 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.

  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 OutputStream asOutputStream()

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

### asInputStream

    public InputStream asInputStream()

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

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Jython homepage