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
Modifier and TypeFieldDescriptionstatic final int
The default size of generic buffers -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCoerce this into an InputStream if possible, or return null.Coerce this into an OutputStream if possible, or return null.void
Raise a ValueError if the file is closed.void
Raise an IOError if the file is not readable.void
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.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 offsetpos
relative to position indicated bywhence
.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.
-
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 offsetpos
relative to position indicated bywhence
.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. - 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.
-