Package org.python.core.io
Class FileIO
java.lang.Object
org.python.core.io.IOBase
org.python.core.io.RawIOBase
org.python.core.io.FileIO
Raw I/O implementation for OS files.
- Author:
- Philip Jenvey
-
Field Summary
Fields inherited from class org.python.core.io.IOBase
DEFAULT_BUFFER_SIZE
-
Constructor Summary
ConstructorDescriptionFileIO
(FileChannel fileChannel, String mode) Construct a FileIO instance with the given FileChannel.Construct a FileIO instance for the specified file name, which will be decoded using the nominal Jython file system encoding if it is astr/bytes
rather than aunicode
. -
Method Summary
Modifier and TypeMethodDescription__int__()
Coerce this into an InputStream if possible, or return null.Coerce this into an OutputStream if possible, or return null.void
close()
Flushes and closes the IO object.Return the underlying Java nio Channel.getFD()
boolean
isatty()
Returns whether this is an 'interactive' stream.boolean
readable()
Return whether this file was opened for reading.readall()
Read until EOF with one readinto() call.int
readinto
(ByteBuffer buf) Read up to buf.remaining() bytes into buf.long
readinto
(ByteBuffer[] bufs) Read bytes into each of the specified ByteBuffers via scatter i/o.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.int
write
(ByteBuffer buf) Write the given ByteBuffer to the IO stream.long
write
(ByteBuffer[] bufs) Write bytes from each of the specified ByteBuffers via gather i/o.Methods inherited from class org.python.core.io.IOBase
checkClosed, checkReadable, checkWritable, closed, flush, seek
-
Constructor Details
-
FileIO
- See Also:
-
FileIO
Construct a FileIO instance for the specified file name, which will be decoded using the nominal Jython file system encoding if it is astr/bytes
rather than aunicode
. The mode can be 'r', 'w' or 'a' for reading (default), writing or appending. Add a '+' to the mode to allow simultaneous reading and writing.- Parameters:
name
- the name of the filemode
- a raw io file mode String
-
FileIO
Construct a FileIO instance with the given FileChannel. The mode can be 'r', 'w' or 'a' for reading (default), writing or appending. Add a '+' to the mode to allow simultaneous reading and writing.- Parameters:
fileChannel
- a FileChannel objectmode
- a raw io file mode String
-
-
Method Details
-
isatty
public boolean isatty()Description copied from class:IOBase
Returns whether this is an 'interactive' stream. Returns False if we don't know. -
readinto
Description copied from class:RawIOBase
Read up to buf.remaining() bytes into buf. Returns number of bytes read (0 for EOF). -
readinto
Read bytes into each of the specified ByteBuffers via scatter i/o. Returns number of bytes read (0 for EOF). -
readall
Read until EOF with one readinto() call. Takes advantage of the fact that the underlying file's size is available. However, we have to special case if file size is 0, as seen in the /proc virtual file system - in this case we cannot assume the file is truly empty. -
write
Description copied from class:RawIOBase
Write the given ByteBuffer to the IO stream. Returns the number of bytes written, which may be less than buf.remaining(). -
write
Write bytes from each of the specified ByteBuffers via gather i/o. -
seek
public long seek(long pos, int whence) Description copied from class:IOBase
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. -
tell
public long tell()Description copied from class:IOBase
Return the current stream position. -
truncate
public long truncate(long size) Description copied from class:IOBase
Truncate file to size in bytes. Returns the new size. -
close
public void close()Description copied from class:IOBase
Flushes and closes the IO object. This must be idempotent. It should also set a flag for the 'closed' property (see below) to test. -
asOutputStream
Description copied from class:IOBase
Coerce this into an OutputStream if possible, or return null.- Overrides:
asOutputStream
in classIOBase
-
asInputStream
Description copied from class:IOBase
Coerce this into an InputStream if possible, or return null.- Overrides:
asInputStream
in classIOBase
-
readable
public boolean readable()Description copied from class:IOBase
Return whether this file was opened for reading. -
writable
public boolean writable()Description copied from class:IOBase
Return whether this file was opened for writing. -
getChannel
Description copied from class:RawIOBase
Return the underlying Java nio Channel.- Specified by:
getChannel
in classRawIOBase
- Returns:
- the underlying Java nio Channel
-
getFD
-
__int__
-
__add__
-