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
-
public class FileIO extends RawIOBase
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
Constructors Constructor Description FileIO(java.lang.String name, java.lang.String mode)FileIO(java.nio.channels.FileChannel fileChannel, java.lang.String mode)Construct a FileIO instance with the given FileChannel.FileIO(PyString name, java.lang.String mode)Construct a FileIO instance for the specified file name, which will be decoded using the nominal Jython file system encoding if it is astr/bytesrather than aunicode.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PyObject__add__(PyObject otherObj)PyObject__int__()java.io.InputStreamasInputStream()Coerce this into an InputStream if possible, or return null.java.io.OutputStreamasOutputStream()Coerce this into an OutputStream if possible, or return null.voidclose()Flushes and closes the IO object.java.nio.channels.FileChannelgetChannel()Return the underlying Java nio Channel.java.io.FileDescriptorgetFD()booleanisatty()Returns whether this is an 'interactive' stream.booleanreadable()Return whether this file was opened for reading.java.nio.ByteBufferreadall()Read until EOF with one readinto() call.intreadinto(java.nio.ByteBuffer buf)Read up to buf.remaining() bytes into buf.longreadinto(java.nio.ByteBuffer[] bufs)Read bytes into each of the specified ByteBuffers via scatter i/o.longseek(long pos, int whence)Seek to byte offset pos relative to position indicated by whence: 0 Start of stream (the default). pos should be >= 0; 1 Current position - whence may be negative; 2 End of stream - whence usually negative.longtell()Return the current stream position.longtruncate(long size)Truncate file to size in bytes.booleanwritable()Return whether this file was opened for writing.intwrite(java.nio.ByteBuffer buf)Write the given ByteBuffer to the IO stream.longwrite(java.nio.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 Detail
-
FileIO
public FileIO(java.lang.String name, java.lang.String mode)- See Also:
FileIO(PyString name, String mode)
-
FileIO
public FileIO(PyString name, java.lang.String mode)
Construct a FileIO instance for the specified file name, which will be decoded using the nominal Jython file system encoding if it is astr/bytesrather 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
public FileIO(java.nio.channels.FileChannel fileChannel, java.lang.String mode)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 Detail
-
isatty
public boolean isatty()
Description copied from class:IOBaseReturns whether this is an 'interactive' stream. Returns False if we don't know.
-
readinto
public int readinto(java.nio.ByteBuffer buf)
Description copied from class:RawIOBaseRead up to buf.remaining() bytes into buf. Returns number of bytes read (0 for EOF).
-
readinto
public long readinto(java.nio.ByteBuffer[] bufs)
Read bytes into each of the specified ByteBuffers via scatter i/o. Returns number of bytes read (0 for EOF).
-
readall
public java.nio.ByteBuffer 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
public int write(java.nio.ByteBuffer buf)
Description copied from class:RawIOBaseWrite the given ByteBuffer to the IO stream. Returns the number of bytes written, which may be less than buf.remaining().
-
write
public long write(java.nio.ByteBuffer[] bufs)
Write bytes from each of the specified ByteBuffers via gather i/o.
-
seek
public long seek(long pos, int whence)Description copied from class:IOBaseSeek to byte offset pos relative to position indicated by whence: 0 Start of stream (the default). pos should be >= 0; 1 Current position - whence may be negative; 2 End of stream - whence usually negative. Returns the new absolute position.
-
tell
public long tell()
Description copied from class:IOBaseReturn the current stream position.
-
truncate
public long truncate(long size)
Description copied from class:IOBaseTruncate file to size in bytes. Returns the new size.
-
close
public void close()
Description copied from class:IOBaseFlushes and closes the IO object. This must be idempotent. It should also set a flag for the 'closed' property (see below) to test.
-
asOutputStream
public java.io.OutputStream asOutputStream()
Description copied from class:IOBaseCoerce this into an OutputStream if possible, or return null.- Overrides:
asOutputStreamin classIOBase
-
asInputStream
public java.io.InputStream asInputStream()
Description copied from class:IOBaseCoerce this into an InputStream if possible, or return null.- Overrides:
asInputStreamin classIOBase
-
readable
public boolean readable()
Description copied from class:IOBaseReturn whether this file was opened for reading.
-
writable
public boolean writable()
Description copied from class:IOBaseReturn whether this file was opened for writing.
-
getChannel
public java.nio.channels.FileChannel getChannel()
Description copied from class:RawIOBaseReturn the underlying Java nio Channel.- Specified by:
getChannelin classRawIOBase- Returns:
- the underlying Java nio Channel
-
getFD
public java.io.FileDescriptor getFD()
-
__int__
public PyObject __int__()
-
-