Top Description Fields Constructors Methods
org.python.modules._io

public Class PyIOBase

extends PyObject
implements FinalizableBuiltin, Traverseproc
Class Inheritance
All Implemented Interfaces
org.python.core.Traverseproc, org.python.core.finalization.FinalizableBuiltin
Known Direct Subclasses
org.python.modules._io.PyIOBaseDerived, org.python.modules._io.PyRawIOBase
Annotations
@ExposedType
name:_io._IOBase
doc:The abstract base class for all I/O classes, acting on streams of bytes. There is no public constructor. This class provides dummy implementations for many methods that derived classes can override selectively; the default implementations represent a file that cannot be read, written or seeked. Even though IOBase does not declare read, readinto, or write because their signatures will vary, implementations and clients should consider those methods part of the interface. Also, implementations may raise a IOError when operations they do not support are called. The basic type used for binary data read from or written to a file is bytes. bytearrays are accepted too, and in some cases (such as readinto) needed. Text I/O classes work with str data. Note that calling any method (even inquiries) on a closed stream is undefined. Implementations may raise IOError in this case. IOBase (and its subclasses) support the iterator protocol, meaning that an IOBase object can be iterated over yielding the lines in a stream. IOBase also supports the :keyword:`with` statement. In this example, fp is closed after the suite of the with statement is complete: with open(\'spam.txt\', \'r\') as fp: fp.write(\'Spam and eggs!\')
Imports
org.python.core.BufferProtocol, .Py, .PyArray, .PyBUF, .PyBuffer, .PyByteArray, .PyException, .PyList, .PyNewWrapper, .PyObject, .PyString, .PyStringMap, .PyType, .PyUnicode, .Traverseproc, .Visitproc, org.python.core.buffer.SimpleStringBuffer, org.python.core.finalization.FinalizableBuiltin, .FinalizeTrigger, org.python.core.io.FileIO, org.python.expose.ExposedGet, .ExposedMethod, .ExposedNew, .ExposedSet, .ExposedType

The Python module _io._IOBase, on which the io module depends directly.

Implementation Note

The code is based heavily on the Jython 2.6-ish _fileio.PyFileIO, the purely Java-accessible org.python.core.io.IOBase (both Philip Jenvey's work), and the Python implementation in Lib/_pyio. We do not simply delegate to the implementation in org.python.core.io because of the need to override parts of the implementation in Python subclasses. A call to close(), for example, is required to call flush(), but if delegated to the pure Java implementation would not call the version of flush() overridden in a Python sub-class of _io._IOBase. Equally, the use made by PyRawIOBase.read(int) of readinto(bytearray) would not pick up the version of readinto defined in Python.

Field Summary

Modifier and TypeField and Description
protected boolean
__closed

True if the object is closed to further client operations.

protected PyStringMap
__dict__

Provide a dictionary in the object, so that methods and attributes may be overridden at instance level.

public static final String
public static final String
private Closer<PyIOBase>
closer

The ioDelegate's closer object; ensures the stream is closed at shutdown

pack-priv static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final PyType
public static final String
public static final String
Inherited from org.python.core.PyObject:
attributesgcMonitorGlobalobjtype

Constructor Summary

AccessConstructor and Description
protected
protected
PyIOBase(PyType subtype)

Method Summary

Modifier and TypeMethod and Description
public void
__del_builtin__()

Implements org.python.core.finalization.FinalizableBuiltin.__del_builtin__.

__del_builtin__() is the built-in's own finalizer, while FinalizablePyObjectDerived#__del_derived__() refers to an instance's in-dict __del__.

public PyObject

Returns:

this object
__enter__
()

Called at the start of a context-managed suite (supporting the with clause).

public boolean

Returns:

false
__exit__
(PyObject type, PyObject value, PyObject traceback)

Called at the end of a context-managed suite (supporting the with clause), and will normally close the stream.

public PyObject
__iter__()

Overrides org.python.core.PyObject.__iter__.

Return an iterator on which next may be repeatedly called to produce (usually) lines from this stream or file.

public PyObject
__iternext__()

Overrides org.python.core.PyObject.__iternext__.

Return the next element of the sequence that this is an iterator for.

public void
_checkClosed(String
optional custom message
msg
)

Raise an error if the underlying IO stream is closed.

public final void
public void
_checkReadable(String
optional custom message
msg
)

Raise an error if the underlying IO stream is not readable.

public final void
_checkReadable()

Raise an error if the underlying IO stream is not readable.

public void
_checkSeekable(String
optional custom message
msg
)

Raise an error if the pointer of underlying IO stream is not capable of being positioned.

public final void
_checkSeekable()

Raise an error if the pointer of underlying IO stream is not capable of being positioned.

public void
_checkWritable(String
optional custom message
msg
)

Raise an error if the underlying IO stream is not writable.

public final void
_checkWritable()

Raise an error if the underlying IO stream is not writable.

pack-priv final PyObject
pack-priv final boolean
_IOBase___exit__(PyObject type, PyObject value, PyObject traceback)

pack-priv static PyObject
_IOBase___new__(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords)

pack-priv final void
pack-priv final void
pack-priv final void
pack-priv final void
pack-priv final void
pack-priv final void
pack-priv final PyObject
pack-priv final void
pack-priv final boolean
pack-priv final PyObject
pack-priv final boolean
pack-priv final PyObject
pack-priv final PyObject
pack-priv final long
_IOBase_seek(long pos, int whence)

pack-priv final boolean
pack-priv final long
pack-priv final long
pack-priv final boolean
pack-priv final void
private PyObject
_readline(int limit)

public void
close()

Close the stream.

public final boolean

Returns:

true if closed
closed
()

Is the stream closed against further client operations?

public final void
closed_readonly(boolean value)

public PyStringMap
fastGetDict()

Overrides org.python.core.PyObject.fastGetDict.

xxx implements where meaningful

public PyObject

Returns:

a file descriptor (as opaque object)
fileno
()

Return a file descriptor for the stream.

public void
flush()

Flush write buffers, or no-op for read-only and non-blocking streams.

public boolean

Returns:

true if a console: false if not or we can't tell
isatty
()

Is the stream known to be an interactive console?

public PyObject

Returns:

next line from the stream or file
next
()

May be called repeatedly to produce (usually) lines from this stream or file.

public boolean

Returns:

true if readable
readable
()

Is the stream readable?

protected static PyBuffer

Returns:

a 1D contiguous PyBuffer of bytes
readablePyBuffer
(PyObject
to be wrapped and presented as a buffer
obj
)

Construct a PyBuffer on a given object suitable for writing to the underlying stream.

public PyObject

Returns:

the line (or fragment)
readline
(int
maximum number of bytes (<0 means no limit)
limit
)

Return one line of text (bytes terminates by '\n'), or the specified number of bytes, or the whole stream, whichever is shortest.

public PyObject

Returns:

the line (or fragment)
readline
()

Return one line of text (bytes terminates by '\n'), or the whole stream, whichever is shorter.

public PyObject

Returns:

list containing the lines read
readlines
(PyObject
stop reading lines after this many bytes (if not EOF first)
hint
)

Read a stream as a sequence of lines.

public boolean
public long

Returns:

the new current position
seek
(long
relative to the specified point
pos
,
int
0=from start, 1=from here, 2=from end
whence
)

Position the read or write pointer at a given byte offset pos relative to a position indicated by whence.

public final long

Returns:

the new current position
seek
(long
relative to the start
pos
)

Position the read or write pointer at a given byte offset pos relative to the start.

public boolean

Returns:

True if may be positioned
seekable
()

Is the stream capable of positioning the read/write pointer?

private static PyException
tailoredIOError(String msg, String oper)

Convenience method providing the exception in the _checkWhatever() methods.

protected static PyException

Returns:

TypeError to throw
tailoredTypeError
(String
of thing expected (or could any text)
type
,
PyObject
argument provided from which actual type will be reported
arg
)

Convenience method providing the exception when an argument is not the expected type.

public long

Returns:

stream position
tell
()

Get the current stream position.

public int
traverse(Visitproc visit, Object arg)

Implements org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects.

public long

Returns:

the new size
truncate
(long
requested for stream
size
)

Truncate file to size bytes.

public long

Returns:

the new size
truncate
()

Truncate file to size bytes to the current position (as reported by tell()).

protected PyException

Returns:

the exception for throwing
unsupported
(String
name of operation
op
)

Convenience method returning a PyException(_io.UnsupportedOperation), ripe for throwing, and naming the unsupported operation.

public boolean

Returns:

true if writable
writable
()

Is the stream writable?

protected static PyBuffer

Returns:

a 1D contiguous PyBuffer of bytes
writablePyBuffer
(PyObject
to be wrapped and presented as a buffer
obj
)

Construct a PyBuffer on a given object suitable for reading into from the underlying stream.

public void
writelines(PyObject lines)

Write an iterable sequence of strings to the stream.

Inherited from org.python.core.PyObject:
__abs____add____and____call____call____call____call____call____call____call____call____call____call____call____call____call____call____call____call____cmp____coerce____coerce_ex____complex____contains____delattr____delattr____delete____delitem____delitem____delslice____delslice____dir____div____divmod____ensure_finalizer____eq____findattr____findattr____findattr_ex____finditem____finditem____finditem____float____floordiv____format____ge____get____getattr____getattr____getitem____getitem____getnewargs____getslice____getslice____gt____hash____hex____iadd____iand____idiv____idivmod____ifloordiv____ilshift____imod____imul____index____int____invert____ior____ipow____irshift____isub____itruediv____ixor____le____len____long____lshift____lt____mod____mul____ne____neg____nonzero____not____oct____or____pos____pow____pow____radd____rand____rawdir____rdiv____rdivmod____reduce____reduce_ex____reduce_ex____repr____rfloordiv____rlshift____rmod____rmul____ror____rpow____rrshift____rshift____rsub____rtruediv____rxor____set____setattr____setattr____setitem____setitem____setitem____setslice____setslice____str____sub____tojava____truediv____trunc____unicode____xor___add_and_callextra_cmp_div_divmod_doget_doget_doset_eq_floordiv_ge_gt_iadd_iand_idiv_idivmod_ifloordiv_ilshift_imod_imul_in_ior_ipow_irshift_is_isnot_isub_itruediv_ixor_jcall_jcallexc_jthrow_le_lshift_lt_mod_mul_ne_notin_or_pow_rshift_sub_truediv_unsupportedop_xoradaptToCoerceTupleasDoubleasIndexasIndexasIntasIntasIterableasLongasLongasNameasNameasStringasStringasStringOrNullasStringOrNullbit_lengthconjugatedelDictdelTypedispatch__init__equalsfastGetClassfinalizegetDictgetJavaProxygetTypehashCodeimpAttrimplementsDescrDeleteimplementsDescrGetimplementsDescrSetinvokeinvokeinvokeinvokeinvokeinvokeisCallableisDataDescrisIndexisIntegerisMappingTypeisNumberTypeisSequenceTypemergeClassDictmergeDictAttrmergeListAttrnoAttributeErrorobject___subclasshook__readonlyAttributeErrorrunsupportedopMessagesetDictsetTypetoStringunsupportedopMessage

Field Detail

__closedback to summary
protected boolean __closed

True if the object is closed to further client operations. It is the state accessed by closed and checked by _checkClosed(). It may be set without making it an error (for this object and its subclasses) to access some downstream object, notably in the implementation of close().

Annotations
@ExposedGet
name:closed
doc:True if the stream is closed.

__dict__back to summary
protected PyStringMap __dict__

Provide a dictionary in the object, so that methods and attributes may be overridden at instance level.

Annotations
@ExposedGet

close_docback to summary
public static final String close_doc
closed_docback to summary
public static final String closed_doc
closerback to summary
private Closer<PyIOBase> closer

The ioDelegate's closer object; ensures the stream is closed at shutdown

docback to summary
pack-priv static final String doc
fileno_docback to summary
public static final String fileno_doc
flush_docback to summary
public static final String flush_doc
isatty_docback to summary
public static final String isatty_doc
readable_docback to summary
public static final String readable_doc
readline_docback to summary
public static final String readline_doc
readlines_docback to summary
public static final String readlines_doc
seek_docback to summary
public static final String seek_doc
seekable_docback to summary
public static final String seekable_doc
tell_docback to summary
public static final String tell_doc
truncate_docback to summary
public static final String truncate_doc
TYPEback to summary
public static final PyType TYPE

Hides org.python.core.PyObject.TYPE.

writable_docback to summary
public static final String writable_doc
writelines_docback to summary
public static final String writelines_doc

Constructor Detail

PyIOBaseback to summary
protected PyIOBase()
PyIOBaseback to summary
protected PyIOBase(PyType subtype)

Method Detail

__del_builtin__back to summary
public void __del_builtin__()

Implements org.python.core.finalization.FinalizableBuiltin.__del_builtin__.

Doc from org.python.core.finalization.FinalizableBuiltin.__del_builtin__.

__del_builtin__() is the built-in's own finalizer, while FinalizablePyObjectDerived#__del_derived__() refers to an instance's in-dict __del__. A FinalizeTrigger calls FinalizablePyObjectDerived#__del_derived__() first and - if existent - __del_builtin__() after that. A plain FinalizablePyObject#__del__() would behave as overridden by FinalizablePyObjectDerived#__del_derived__(), i.e. won't be called if the type implements FinalizablePyObjectDerived, while __del_builtin__() is called in any case.

Annotations
@Override
__enter__back to summary
public PyObject __enter__()

Called at the start of a context-managed suite (supporting the with clause).

Returns:PyObject

this object

__exit__back to summary
public boolean __exit__(PyObject type, PyObject value, PyObject traceback)

Called at the end of a context-managed suite (supporting the with clause), and will normally close the stream.

Returns:boolean

false

__iter__back to summary
public PyObject __iter__()

Overrides org.python.core.PyObject.__iter__.

Return an iterator on which next may be repeatedly called to produce (usually) lines from this stream or file.

Annotations
@Override
__iternext__back to summary
public PyObject __iternext__()

Overrides org.python.core.PyObject.__iternext__.

Doc from org.python.core.PyObject.__iternext__.

Return the next element of the sequence that this is an iterator for. Returns null when the end of the sequence is reached.

Annotations
@Override
_checkClosedback to summary
public void _checkClosed(String msg) throws PyException

Raise an error if the underlying IO stream is closed. (Note opposite sense from _checkSeekable, etc..

Parameters
msg:String

optional custom message

Exceptions
PyException:
ValueError if the object is closed to client operations
_checkClosedback to summary
public final void _checkClosed() throws PyException
_checkReadableback to summary
public void _checkReadable(String msg)

Raise an error if the underlying IO stream is not readable.

Parameters
msg:String

optional custom message

Exceptions
PyException:
  • ValueError if the object is closed to client operations
  • IOError if the stream is not readable.
_checkReadableback to summary
public final void _checkReadable()

Raise an error if the underlying IO stream is not readable.

Exceptions
PyException:
  • ValueError if the object is closed to client operations
  • IOError if the stream is not readable.
_checkSeekableback to summary
public void _checkSeekable(String msg)

Raise an error if the pointer of underlying IO stream is not capable of being positioned.

Parameters
msg:String

optional custom message

Exceptions
PyException:
  • ValueError if the object is closed to client operations
  • IOError if the stream is not capable of being positioned.
_checkSeekableback to summary
public final void _checkSeekable()

Raise an error if the pointer of underlying IO stream is not capable of being positioned.

Exceptions
PyException:
  • ValueError if the object is closed to client operations
  • IOError if the stream is not capable of being positioned.
_checkWritableback to summary
public void _checkWritable(String msg) throws PyException

Raise an error if the underlying IO stream is not writable.

Parameters
msg:String

optional custom message

Exceptions
PyException:
  • ValueError if the object is closed to client operations
  • IOError if the stream is not writable.
_checkWritableback to summary
public final void _checkWritable() throws PyException

Raise an error if the underlying IO stream is not writable.

Exceptions
PyException:
  • ValueError if the object is closed to client operations
  • IOError if the stream is not writable.
_IOBase___enter__back to summary
pack-priv final PyObject _IOBase___enter__()
Annotations
@ExposedMethod
names:__enter__, __iter__
_IOBase___exit__back to summary
pack-priv final boolean _IOBase___exit__(PyObject type, PyObject value, PyObject traceback)
Annotations
@ExposedMethod
_IOBase___new__back to summary
pack-priv static PyObject _IOBase___new__(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords)
Annotations
@ExposedNew
_IOBase__checkClosedback to summary
pack-priv final void _IOBase__checkClosed(String msg) throws PyException
Annotations
@ExposedMethod
defaults:null
_IOBase__checkReadableback to summary
pack-priv final void _IOBase__checkReadable(String msg)
Annotations
@ExposedMethod
defaults:null
_IOBase__checkSeekableback to summary
pack-priv final void _IOBase__checkSeekable(String msg)
Annotations
@ExposedMethod
defaults:null
_IOBase__checkWritableback to summary
pack-priv final void _IOBase__checkWritable(String msg) throws PyException
Annotations
@ExposedMethod
defaults:null
_IOBase__unsupportedback to summary
pack-priv final void _IOBase__unsupported(String name)
Annotations
@ExposedMethod
doc:Internal: raise an exception for unsupported operations.
_IOBase_closeback to summary
pack-priv final void _IOBase_close()
Annotations
@ExposedMethod
doc:Flush and close the IO object. This method has no effect if the file is already closed.
_IOBase_filenoback to summary
pack-priv final PyObject _IOBase_fileno()
Annotations
@ExposedMethod
doc:Returns underlying file descriptor if one exists. An IOError is raised if the IO object does not use a file descriptor.
_IOBase_flushback to summary
pack-priv final void _IOBase_flush()
Annotations
@ExposedMethod
doc:Flush write buffers, if applicable. This is not implemented for read-only and non-blocking streams.
_IOBase_isattyback to summary
pack-priv final boolean _IOBase_isatty()
Annotations
@ExposedMethod
doc:Return whether this is an \'interactive\' stream. Return False if it can\'t be determined.
_IOBase_nextback to summary
pack-priv final PyObject _IOBase_next() throws PyException
Annotations
@ExposedMethod
doc:x.__next__() <==> next(x)
_IOBase_readableback to summary
pack-priv final boolean _IOBase_readable() throws PyException
Annotations
@ExposedMethod
doc:Return whether object was opened for reading. If False, read() will raise IOError.
_IOBase_readlineback to summary
pack-priv final PyObject _IOBase_readline(PyObject limit)
Annotations
@ExposedMethod
defaults:null
doc:Read and return a line from the stream. If limit is specified, at most limit bytes will be read. The line terminator is always b\' \' for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.
_IOBase_readlinesback to summary
pack-priv final PyObject _IOBase_readlines(PyObject hint)
Annotations
@ExposedMethod
defaults:null
doc:Return a list of lines from the stream. hint can be specified to control the number of lines read: no more lines will be read if the total size (in bytes/characters) of all lines so far exceeds hint.
_IOBase_seekback to summary
pack-priv final long _IOBase_seek(long pos, int whence)
Annotations
@ExposedMethod
defaults:0
doc:Change stream position. Change the stream position to byte offset offset. offset is interpreted relative to the position indicated by whence. Values for whence are: * 0 -- start of stream (the default); offset should be zero or positive * 1 -- current stream position; offset may be negative * 2 -- end of stream; offset is usually negative Return the new absolute position.
_IOBase_seekableback to summary
pack-priv final boolean _IOBase_seekable() throws PyException
Annotations
@ExposedMethod
doc:Return whether object supports random access. If False, seek(), tell() and truncate() will raise IOError. This method may need to do a test seek().
_IOBase_tellback to summary
pack-priv final long _IOBase_tell()
Annotations
@ExposedMethod
doc:Return current stream position.
_IOBase_truncateback to summary
pack-priv final long _IOBase_truncate(PyObject size)
Annotations
@ExposedMethod
defaults:null
doc:Truncate file to size bytes. File pointer is left unchanged. Size defaults to the current IO position as reported by tell(). Returns the new size.
_IOBase_writableback to summary
pack-priv final boolean _IOBase_writable() throws PyException
Annotations
@ExposedMethod
doc:Return whether object was opened for writing. If False, read() will raise IOError.
_IOBase_writelinesback to summary
pack-priv final void _IOBase_writelines(PyObject lines)
Annotations
@ExposedMethod
doc:Write a list of lines to the stream. Line separators are not added, so it is usual for each of the lines provided to have a line separator at the end.
_readlineback to summary
private PyObject _readline(int limit)
closeback to summary
public void close()

Close the stream. If closed already, this is a no-op.

closedback to summary
public final boolean closed()

Is the stream closed against further client operations?

Returns:boolean

true if closed

closed_readonlyback to summary
public final void closed_readonly(boolean value)
Annotations
@ExposedSet
name:closed
fastGetDictback to summary
public PyStringMap fastGetDict()

Overrides org.python.core.PyObject.fastGetDict.

Doc from org.python.core.PyObject.fastGetDict.

xxx implements where meaningful

Returns:PyStringMap

internal object per instance dict or null

Annotations
@Override

filenoback to summary
public PyObject fileno()

Return a file descriptor for the stream. A CPython file descriptor is an int, but this is not the natural choice in Jython, since Java has no such convention of using integers. File descriptors should be passed around opaquely, so their actual type is irrelevant, as long as (say) _jyio#open(PyObject[], String[]) accepts the type that FileIO#fileno() returns.

Returns:PyObject

a file descriptor (as opaque object)

flushback to summary
public void flush()

Flush write buffers, or no-op for read-only and non-blocking streams. Irrespective of the concrete type of the i/o object, locally-buffered write data is written downstream. Whether the downstream in object is also flushed depends upon the specific type of this object.

isattyback to summary
public boolean isatty()

Is the stream known to be an interactive console? This relies on the ability of the underlying stream to know, which is not always possible.

Returns:boolean

true if a console: false if not or we can't tell

nextback to summary
public PyObject next() throws PyException

May be called repeatedly to produce (usually) lines from this stream or file.

Returns:PyObject

next line from the stream or file

Exceptions
PyException:
  • StopIteration when iteration has reached a natural conclusion
  • ValueError if the file or stream is closed
  • IOError reflecting an I/O error in during the read

readableback to summary
public boolean readable() throws PyException

Is the stream readable?

Returns:boolean

true if readable

Exceptions
PyException:
ValueError if the object is closed to client operations

readablePyBufferback to summary
protected static PyBuffer readablePyBuffer(PyObject obj) throws PyException

Construct a PyBuffer on a given object suitable for writing to the underlying stream. The buffer returned will be navigable as a 1D contiguous sequence of bytes.

Parameters
obj:PyObject

to be wrapped and presented as a buffer

Returns:PyBuffer

a 1D contiguous PyBuffer of bytes

Exceptions
PyException:
  • BufferError if object has buffer API, but is not 1D contiguous bytes
  • TypeError if object not convertible to a byte array

readlineback to summary
public PyObject readline(int limit)

Return one line of text (bytes terminates by '\n'), or the specified number of bytes, or the whole stream, whichever is shortest.

Parameters
limit:int

maximum number of bytes (<0 means no limit)

Returns:PyObject

the line (or fragment)

readlineback to summary
public PyObject readline()

Return one line of text (bytes terminates by '\n'), or the whole stream, whichever is shorter.

Returns:PyObject

the line (or fragment)

readlinesback to summary
public PyObject readlines(PyObject hint)

Read a stream as a sequence of lines.

Parameters
hint:PyObject

stop reading lines after this many bytes (if not EOF first)

Returns:PyObject

list containing the lines read

refersDirectlyToback to summary
public boolean refersDirectlyTo(PyObject ob)

Implements org.python.core.Traverseproc.refersDirectlyTo.

Doc from org.python.core.Traverseproc.refersDirectlyTo.

Optional operation. Should only be implemented if it is more efficient than calling traverse(Visitproc, Object) with a visitproc that just watches out for ob. Must return false if ob is null.

Annotations
@Override
seekback to summary
public long seek(long pos, int whence)

Position the read or write pointer at a given byte offset pos relative to a position indicated by whence.

  • If whence=0, the position will be set to pos bytes.
  • If whence=1 the position will be set to the current position plus pos.
  • If whence=2 the position will be set to the stream size plus pos (and usually pos<=0).
Parameters
pos:long

relative to the specified point

whence:int

0=from start, 1=from here, 2=from end

Returns:long

the new current position

seekback to summary
public final long seek(long pos)

Position the read or write pointer at a given byte offset pos relative to the start.

Parameters
pos:long

relative to the start

Returns:long

the new current position

seekableback to summary
public boolean seekable() throws PyException

Is the stream capable of positioning the read/write pointer?

Returns:boolean

True if may be positioned

Exceptions
PyException:
ValueError if the object is closed to client operations

tailoredIOErrorback to summary
private static PyException tailoredIOError(String msg, String oper)

Convenience method providing the exception in the _checkWhatever() methods.

tailoredTypeErrorback to summary
protected static PyException tailoredTypeError(String type, PyObject arg)

Convenience method providing the exception when an argument is not the expected type. The format is "type argument expected, got type(arg)."

Parameters
type:String

of thing expected (or could any text)

arg:PyObject

argument provided from which actual type will be reported

Returns:PyException

TypeError to throw

tellback to summary
public long tell()

Get the current stream position.

Returns:long

stream position

traverseback to summary
public int traverse(Visitproc visit, Object arg)

Implements org.python.core.Traverseproc.traverse.

Doc from org.python.core.Traverseproc.traverse.

Traverses all directly contained PyObjects. Like in CPython, arg must be passed unmodified to visit as its second parameter. If Visitproc#visit(PyObject, Object) returns nonzero, this return value must be returned immediately by traverse. Visitproc#visit(PyObject, Object) must not be called with a null PyObject-argument.

Annotations
@Override
truncateback to summary
public long truncate(long size)

Truncate file to size bytes.

Parameters
size:long

requested for stream

Returns:long

the new size

truncateback to summary
public long truncate()

Truncate file to size bytes to the current position (as reported by tell()).

Returns:long

the new size

unsupportedback to summary
protected PyException unsupported(String op)

Convenience method returning a PyException(_io.UnsupportedOperation), ripe for throwing, and naming the unsupported operation. Like many similar methods, this does not actually throw (raise) the exception: it should be thrown from the place where the problem is.

Parameters
op:String

name of operation

Returns:PyException

the exception for throwing

writableback to summary
public boolean writable() throws PyException

Is the stream writable?

Returns:boolean

true if writable

Exceptions
PyException:
ValueError if the object is closed to client operations

writablePyBufferback to summary
protected static PyBuffer writablePyBuffer(PyObject obj) throws PyException

Construct a PyBuffer on a given object suitable for reading into from the underlying stream. The buffer returned will be navigable as a 1D contiguous writable sequence of bytes.

Parameters
obj:PyObject

to be wrapped and presented as a buffer

Returns:PyBuffer

a 1D contiguous PyBuffer of bytes

Exceptions
PyException:
  • BufferError if object has buffer API, but is not 1D contiguous bytes
  • TypeError if object not convertible to a byte array

writelinesback to summary
public void writelines(PyObject lines)

Write an iterable sequence of strings to the stream.