Top Description Fields Constructors Methods
org.python.core.io

public abstract Class IOBase

extends Object
Class Inheritance
Known Direct Subclasses
org.python.core.io.RawIOBase, org.python.core.io.TextIOBase, org.python.core.io.BufferedIOBase
Imports
jnr.constants.platform.Errno, java.io.InputStream, .OutputStream, org.python.core.Py, .PyException

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

Modifier and TypeField and Description
private boolean
closed

true if the file has been closed

public static final int
DEFAULT_BUFFER_SIZE

The default size of generic buffers

protected static final byte
LF_BYTE

Byte representation of the Line Feed character

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public InputStream
asInputStream()

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

public OutputStream
asOutputStream()

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

public void
checkClosed()

Raise a ValueError if the file is closed.

public void
checkReadable()

Raise an IOError if the file is not readable.

public void
checkWritable()

Raise an IOError if the file is not writable.

public void
close()

Flushes and closes the IO object.

public boolean

Returns:

true if the file has been closed
closed
()

Return whether this file has been closed.

public RawIOBase

Returns:

a file descriptor
fileno
()

Returns underlying file descriptor if one exists.

public void
flush()

Flushes write buffers, if applicable.

public boolean

Returns:

a boolean, true if an 'interactive' stream
isatty
()

Returns whether this is an 'interactive' stream.

public boolean

Returns:

true if the file was opened for reading
readable
()

Return whether this file was opened for reading.

public long

Returns:

a long position value seeked to
seek
(long
a long position value
pos
)

Seek to byte offset pos relative to the start of the stream.

public long

Returns:

a long position value seeked to
seek
(long
a long position value
pos
,
int
an int whence value
whence
)

Seek to byte offset pos relative to position indicated by whence.

public long

Returns:

a long position value
tell
()

Return the current stream position.

public long

Returns:

a long size value the file was truncated to
truncate
(long
a long size to truncate to
size
)

Truncate file to size in bytes.

protected void
unsupported(String
the String name of the operation
methodName
)

Raise a TypeError indicating the specified operation is not supported.

public boolean

Returns:

true if the file was opened for writing
writable
()

Return whether this file was opened for writing.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closedback to summary
private boolean closed

true if the file has been closed

DEFAULT_BUFFER_SIZEback to summary
public static final int DEFAULT_BUFFER_SIZE

The default size of generic buffers

LF_BYTEback to summary
protected static final byte LF_BYTE

Byte representation of the Line Feed character

Constructor Detail

IOBaseback to summary
public IOBase()

Method Detail

asInputStreamback to summary
public InputStream asInputStream()

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

asOutputStreamback to summary
public OutputStream asOutputStream()

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

checkClosedback to summary
public void checkClosed()

Raise a ValueError if the file is closed.

checkReadableback to summary
public void checkReadable()

Raise an IOError if the file is not readable.

checkWritableback to summary
public void checkWritable()

Raise an IOError if the file is not writable.

closeback to summary
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.

closedback to summary
public boolean closed()

Return whether this file has been closed.

Returns:boolean

true if the file has been closed

filenoback to summary
public RawIOBase fileno()

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

Returns:RawIOBase

a file descriptor

flushback to summary
public void flush()

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

isattyback to summary
public boolean isatty()

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

Returns:boolean

a boolean, true if an 'interactive' stream

readableback to summary
public boolean readable()

Return whether this file was opened for reading.

Returns:boolean

true if the file was opened for reading

seekback to summary
public long seek(long pos)

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

Parameters
pos:long

a long position value

Returns:long

a long position value seeked to

seekback to summary
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:long

a long position value

whence:int

an int whence value

Returns:long

a long position value seeked to

tellback to summary
public long tell()

Return the current stream position.

Returns:long

a long position value

truncateback to summary
public long truncate(long size)

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

Parameters
size:long

a long size to truncate to

Returns:long

a long size value the file was truncated to

unsupportedback to summary
protected void unsupported(String methodName)

Raise a TypeError indicating the specified operation is not supported.

Parameters
methodName:String

the String name of the operation

writableback to summary
public boolean writable()

Return whether this file was opened for writing.

Returns:boolean

true if the file was opened for writing