Package org.python.core.io
Class IOBase
java.lang.Object
org.python.core.io.IOBase
- Direct Known Subclasses:
BufferedIOBase,RawIOBase,TextIOBase
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
FieldsModifier and TypeFieldDescriptionstatic final intThe default size of generic buffers -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCoerce this into an InputStream if possible, or return null.Coerce this into an OutputStream if possible, or return null.voidRaise a ValueError if the file is closed.voidRaise an IOError if the file is not readable.voidRaise an IOError if the file is not writable.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.booleanisatty()Returns whether this is an 'interactive' stream.booleanreadable()Return whether this file was opened for reading.longseek(long pos) Seek to byte offset pos relative to the start of the stream.longseek(long pos, int whence) Seek to byte offsetposrelative to position indicated bywhence.longtell()Return the current stream position.longtruncate(long size) Truncate file to size in bytes.booleanwritable()Return whether this file was opened for writing.
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEThe default size of generic buffers- See Also:
-
-
Constructor Details
-
IOBase
public IOBase()
-
-
Method Details
-
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 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. - Parameters:
pos- a long position valuewhence- 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
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
Coerce this into an OutputStream if possible, or return null. -
asInputStream
Coerce this into an InputStream if possible, or return null.
-