Package org.jruby.util.io
Class OpenFile
java.lang.Object
org.jruby.util.io.OpenFile
- All Implemented Interfaces:
Finalizable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intprotected Set<RubyThread>static final intfinal OpenFile.Bufferstatic final intstatic final intprivate static final byte[]static final intstatic final intprivate ChannelFDprivate OpenFile.Finalizerstatic final intstatic final intstatic final intprivate intprivate final ReentrantLockprivate intstatic final intstatic final intprivate booleanprivate Stringprivate longstatic final intstatic final OpenFile.FinalizerDeprecated.final PosixShimstatic final intprivate Processfinal OpenFile.Buffer(package private) static final RubyThread.ReadWrite<OpenFile>static final intorg.jcodings.transcode.EConvstatic final intprivate final Rubystatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intfinal OpenFile.Bufferstatic final int(package private) static final RubyThread.ReadWrite<OpenFile>org.jcodings.transcode.EConvorg.jcodings.Encodingbooleanintstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBlockingThread(RubyThread thread) Add a thread to the list of blocking threads for this IO.intappendline(ThreadContext context, int delim, ByteList[] strp, int[] lp) voidascii8bitBinmode(Ruby runtime) longbinwrite(ThreadContext context, byte[] ptrBytes, int ptr, int len, boolean nosync) Deprecated.intbinwriteInt(ThreadContext context, byte[] ptrBytes, int ptr, int len, boolean nosync) (package private) static intbinwriteString(OpenFile fptr, byte[] bytes, int start, int length) channel()voidcheckByteReadable(ThreadContext context) voidcheckCharReadable(ThreadContext context) voidvoidcheckReadable(ThreadContext context) voidcheckReopenSeek(ThreadContext context, Ruby runtime, long pos) voidcheckTTY()voidcheckWritable(ThreadContext context) voidvoidvoidvoidvoidstatic intcloexecDup2(PosixShim posix, ChannelFD oldfd, ChannelFD newfd) doWriteconv(ThreadContext context, byte[] bytes, int start, int length, org.jcodings.Encoding encoding) doWriteconv(ThreadContext context, RubyString str) jnr.constants.platform.Errnoerrno()voiderrno(jnr.constants.platform.Errno newErrno) fd()static voidfdFixCloexec(PosixShim posix, int fd) intfillbuf(ThreadContext context) private ObjectfillCbuf(ThreadContext context, int ec_flags) voidfinalize()voidfinalize(ThreadContext context, boolean noraise) voidfinalizeFlush(ThreadContext context, boolean noraise) (package private) IRubyObjectfinishWriteconv(ThreadContext context, boolean noalloc) private voidflushBeforeSeek(ThreadContext context) intintprivate intprivate intintfread(ThreadContext context, byte[] buffer, int offset, int size) intfwrite(ThreadContext context, byte[] bytes, int start, int length, org.jcodings.Encoding encoding, boolean nosync) longfwrite(ThreadContext context, RubyString str, boolean nosync) getc(ThreadContext context, org.jcodings.Encoding enc) protected org.jcodings.EncodinggetCommonEncodingForWriteConv(ThreadContext context, org.jcodings.Encoding strEncoding) intstatic intgetFModeFromString(String modesString) Deprecated.getlineFast(ThreadContext context, org.jcodings.Encoding enc, RubyIO io, boolean chomp) intintgetMode()getModeAsString(Ruby runtime) static intgetModeFlagsAsIntFrom(int fmode) getPath()longgetPid()static StringgetStringFromMode(int mode) voidincrementLineno(Ruby runtime) Deprecated.voidincrementLineno(Ruby runtime, RubyIO io) org.jcodings.EncodinginputEncoding(Ruby runtime) voidinterruptBlockingThreads(ThreadContext context) Fire an IOError in all threads blocking on this IO objectintio_fflush(ThreadContext context) intprivate intioBufread(ThreadContext context, byte[] ptrBytes, int ptr, int len) (package private) static booleanioEncnameBomP(String name, long len) static intioFmodeOflags(int fmode) static intioModestrFmode(Ruby runtime, String modestr) static intioModestrOflags(Ruby runtime, String modestr) static StringioOflagsModestr(Ruby runtime, int oflags) booleanbooleanbooleanbooleanbooleanisBOM()booleanisDuplex()booleanisOpen()booleanbooleanbooleanisStdio()booleanisSync()booleanbooleanbooleanbooleanlock()booleanvoidmakeReadConversion(ThreadContext context) voidmakeReadConversion(ThreadContext context, int size) voidmakeWriteConversion(ThreadContext context) private static intmemchr(byte[] pBytes, int p, int delim, int length) private static StringMODE_BINARY(int oflags, String a, String b) intmoreChar(ThreadContext context) booleanvoidbooleanbooleanbooleanneedsWriteConversion(ThreadContext context) static intrbW32WriteConsole(byte[] bytes, int start, int length, org.jcodings.Encoding encoding) static longrbW32WriteConsole(RubyString buffer) booleanintintbyte[]intvoidREAD_CHECK(ThreadContext context) booleanbooleanintintbyte[]intreadAll(ThreadContext context, int siz, IRubyObject str) intreadBufferedData(byte[] ptrBytes, int ptr, int len) org.jcodings.EncodingreadEncoding(Ruby runtime) static intreadInternal(ThreadContext context, OpenFile fptr, ChannelFD fd, byte[] bufBytes, int buf, int count) intbooleanready(Ruby runtime, RubyThread thread, int ops, long timeout) Wait until the channel is available for the given operations or the timeout expires.booleanreadyNow(ThreadContext context) Likeready(org.jruby.Ruby, org.jruby.RubyThread, int, long)but returns a result immediately.intvoidremoveBlockingThread(RubyThread thread) Remove a thread from the list of blocking threads for this IO.longseek(ThreadContext context, long offset, int whence) voidprivate voidvoidsetAutoclose(boolean autoclose) voidvoidvoidsetBlocking(Ruby runtime, boolean blocking) voidsetBOM(boolean bom) voidsetChannel(Channel fd) voidvoidsetFinalizer(OpenFile.Finalizer finalizer) voidsetLineNumber(int lineNumber) voidsetMode(int modes) voidsetNonblock(Ruby runtime) voidvoidsetPid(long pid) voidsetProcess(Process process) voidsetSync(boolean sync) voidshiftCbuf(int len, RubyString str) shiftCbuf(ThreadContext context, int len, IRubyObject strp) booleanswallow(ThreadContext context, int term) longtell(ThreadContext context) intthreadFlock(ThreadContext context, int lockMode) voidungetbyte(ThreadContext context, IRubyObject str) voidunlock()voidunread(ThreadContext context) private voidprivate voidunreadWindows(ThreadContext context) voidwaitForBlockingThreads(ThreadContext context) Wait until all blocking threads have exited their blocking area.booleanwaitReadable(ThreadContext context) booleanwaitReadable(ThreadContext context, long timeout) (package private) booleanwaitReadable(ThreadContext context, ChannelFD fd) Logic to match (as well as possible) rb_io_wait_readable from MRI.booleanwaitWritable(ThreadContext context) booleanwaitWritable(ThreadContext context, long timeout) private intwritableLength(int l) static intwriteInternal(ThreadContext context, OpenFile fptr, byte[] bufBytes, int buf, int count) (package private) intwriteInternal2(ChannelFD fd, byte[] bufBytes, int buf, int count) private booleanwsplit()wsplit mode selects a smaller write size based on the internal buffer of things like pipes, in order to help guarantee it will not block when emptying our write buffer.
-
Field Details
-
READABLE
public static final int READABLE- See Also:
-
WRITABLE
public static final int WRITABLE- See Also:
-
READWRITE
public static final int READWRITE- See Also:
-
BINMODE
public static final int BINMODE- See Also:
-
SYNC
public static final int SYNC- See Also:
-
TTY
public static final int TTY- See Also:
-
DUPLEX
public static final int DUPLEX- See Also:
-
APPEND
public static final int APPEND- See Also:
-
CREATE
public static final int CREATE- See Also:
-
WSPLIT
public static final int WSPLIT- See Also:
-
EXCLUSIVE
public static final int EXCLUSIVE- See Also:
-
TRUNC
public static final int TRUNC- See Also:
-
TEXTMODE
public static final int TEXTMODE- See Also:
-
SETENC_BY_BOM
public static final int SETENC_BY_BOM- See Also:
-
TMPFILE
public static final int TMPFILE- See Also:
-
PREP
public static final int PREP- See Also:
-
SYNCWRITE
public static final int SYNCWRITE- See Also:
-
PIPE_BUF
public static final int PIPE_BUF- See Also:
-
BUFSIZ
public static final int BUFSIZ- See Also:
-
fd
-
mode
private int mode -
pid
private long pid -
process
-
lineno
private int lineno -
pathv
-
finalizer
-
stdio_file
-
currentLock
-
encs
-
readconv
public org.jcodings.transcode.EConv readconv -
writeconv
public org.jcodings.transcode.EConv writeconv -
writeconvAsciicompat
public org.jcodings.Encoding writeconvAsciicompat -
writeconvPreEcflags
public int writeconvPreEcflags -
writeconvPreEcopts
-
writeconvInitialized
public boolean writeconvInitialized -
write_lock
-
lock
-
wbuf
-
rbuf
-
cbuf
-
tiedIOForWriting
-
nonblock
private boolean nonblock -
posix
-
runtime
-
blockingThreads
-
PIPE_FINALIZE
Deprecated. -
MORE_CHAR_SUSPENDED
public static final int MORE_CHAR_SUSPENDED- See Also:
-
MORE_CHAR_FINISHED
public static final int MORE_CHAR_FINISHED- See Also:
-
EOF
public static final int EOF- See Also:
-
IO_RBUF_CAPA_MIN
public static final int IO_RBUF_CAPA_MIN- See Also:
-
IO_CBUF_CAPA_MIN
public static final int IO_CBUF_CAPA_MIN- See Also:
-
IO_WBUF_CAPA_MIN
public static final int IO_WBUF_CAPA_MIN- See Also:
-
EMPTY_BYTE_ARRAY
private static final byte[] EMPTY_BYTE_ARRAY -
READ_TASK
-
WRITE_TASK
-
-
Constructor Details
-
OpenFile
-
-
Method Details
-
ascii8bitBinmode
-
checkReopenSeek
-
clearStdio
public void clearStdio() -
PREP_STDIO_NAME
-
READ_DATA_PENDING
public boolean READ_DATA_PENDING() -
READ_DATA_PENDING_COUNT
public int READ_DATA_PENDING_COUNT() -
READ_DATA_PENDING_PTR
public byte[] READ_DATA_PENDING_PTR() -
READ_DATA_PENDING_OFF
public int READ_DATA_PENDING_OFF() -
READ_DATA_PENDING_START
public int READ_DATA_PENDING_START() -
READ_DATA_BUFFERED
public boolean READ_DATA_BUFFERED() -
READ_CHAR_PENDING
public boolean READ_CHAR_PENDING() -
READ_CHAR_PENDING_COUNT
public int READ_CHAR_PENDING_COUNT() -
READ_CHAR_PENDING_PTR
public byte[] READ_CHAR_PENDING_PTR() -
READ_CHAR_PENDING_OFF
public int READ_CHAR_PENDING_OFF() -
READ_CHAR_PENDING_START
public int READ_CHAR_PENDING_START() -
READ_CHECK
-
IS_PREP_STDIO
public boolean IS_PREP_STDIO() -
setFD
-
setChannel
-
getMode
public int getMode() -
getModeAsString
-
getModeFlagsAsIntFrom
public static int getModeFlagsAsIntFrom(int fmode) -
ioOflagsModestr
-
ioModestrOflags
-
ioFmodeOflags
public static int ioFmodeOflags(int fmode) -
ioModestrFmode
-
ioEncnameBomP
-
MODE_BINARY
-
getStringFromMode
-
checkCharReadable
-
checkByteReadable
-
checkReadable
-
io_fflush
-
waitWritable
-
waitWritable
-
waitReadable
-
waitReadable
-
ready
Wait until the channel is available for the given operations or the timeout expires.- Parameters:
runtime-ops-timeout-- Returns:
- See Also:
-
readyNow
Likeready(org.jruby.Ruby, org.jruby.RubyThread, int, long)but returns a result immediately.- Parameters:
context-- Returns:
-
flushBuffer
public int flushBuffer() -
flushBufferAsync2
public int flushBufferAsync2() -
flushBufferSync2
private int flushBufferSync2() -
flushBufferSync
private int flushBufferSync() -
writableLength
private int writableLength(int l) -
wsplit
private boolean wsplit()wsplit mode selects a smaller write size based on the internal buffer of things like pipes, in order to help guarantee it will not block when emptying our write buffer. This must be guaranteed to allow MRI to re-try flushing the rest of the buffer with the GVL released, which happens when flushBufferSync above produces EAGAIN. In JRuby, where we don't have to release a lock, we skip this logic and always just let writes do what writes do. MRI: wsplit_p- Returns:
-
seek
-
flushBeforeSeek
-
checkWritable
-
checkClosed
public void checkClosed() -
isBinmode
public boolean isBinmode() -
isTextMode
public boolean isTextMode() -
setTextMode
public void setTextMode() -
clearTextMode
public void clearTextMode() -
setBinmode
public void setBinmode() -
isOpen
public boolean isOpen() -
isReadable
public boolean isReadable() -
isWritable
public boolean isWritable() -
isDuplex
public boolean isDuplex() -
isReadBuffered
public boolean isReadBuffered() -
isWriteBuffered
public boolean isWriteBuffered() -
setSync
public void setSync(boolean sync) -
isSync
public boolean isSync() -
setMode
public void setMode(int modes) -
getProcess
-
setProcess
-
getPid
public long getPid() -
setPid
public void setPid(long pid) -
getLineNumber
public int getLineNumber() -
setLineNumber
public void setLineNumber(int lineNumber) -
getPath
-
setPath
-
isAutoclose
public boolean isAutoclose() -
setAutoclose
public void setAutoclose(boolean autoclose) -
getFinalizer
-
setFinalizer
-
cleanup
-
finalize
public void finalize()- Specified by:
finalizein interfaceFinalizable- Overrides:
finalizein classObject
-
finalize
-
finalizeFlush
-
needsReadConversion
public boolean needsReadConversion() -
needsWriteConversion
-
makeReadConversion
-
makeReadConversion
-
makeWriteConversion
-
clearReadConversion
public void clearReadConversion() -
clearCodeConversion
public void clearCodeConversion() -
IO_RBUF_CAPA_FOR
public int IO_RBUF_CAPA_FOR() -
appendline
-
memchr
private static int memchr(byte[] pBytes, int p, int delim, int length) -
NEED_NEWLINE_DECORATOR_ON_READ_CHECK
public void NEED_NEWLINE_DECORATOR_ON_READ_CHECK() -
NEED_NEWLINE_DECORATOR_ON_READ
public boolean NEED_NEWLINE_DECORATOR_ON_READ() -
NEED_NEWLINE_DECORATOR_ON_WRITE
public boolean NEED_NEWLINE_DECORATOR_ON_WRITE() -
moreChar
-
fillCbuf
-
readBufferedData
public int readBufferedData(byte[] ptrBytes, int ptr, int len) -
fillbuf
-
readInternal
public static int readInternal(ThreadContext context, OpenFile fptr, ChannelFD fd, byte[] bufBytes, int buf, int count) -
waitReadable
Logic to match (as well as possible) rb_io_wait_readable from MRI. We do not have the luxury of treating all file descriptors the same, so there's a bit of special-casing here when the channel is not selectable. Note also the EBADF on closed channels; I believe this is what *would* happen in MRI if we always called the selection logic and were given a closed channel. MRI: rb_io_wait_readable -
readEncoding
-
inputEncoding
-
swallow
-
shiftCbuf
-
shiftCbuf
-
getlineFast
public IRubyObject getlineFast(ThreadContext context, org.jcodings.Encoding enc, RubyIO io, boolean chomp) -
incrementLineno
-
incrementLineno
Deprecated. -
readAll
-
ioBufread
-
fread
-
ungetbyte
-
getc
-
tell
-
unread
-
unreadPosix
private void unreadPosix() -
unreadWindows
-
fwrite
-
fwrite
public int fwrite(ThreadContext context, byte[] bytes, int start, int length, org.jcodings.Encoding encoding, boolean nosync) -
rbW32WriteConsole
-
rbW32WriteConsole
public static int rbW32WriteConsole(byte[] bytes, int start, int length, org.jcodings.Encoding encoding) -
doWriteconv
-
getCommonEncodingForWriteConv
protected org.jcodings.Encoding getCommonEncodingForWriteConv(ThreadContext context, org.jcodings.Encoding strEncoding) -
doWriteconv
public ByteList doWriteconv(ThreadContext context, byte[] bytes, int start, int length, org.jcodings.Encoding encoding) -
binwriteInt
-
binwriteString
-
writeInternal
public static int writeInternal(ThreadContext context, OpenFile fptr, byte[] bufBytes, int buf, int count) -
writeInternal2
-
fd
-
channel
-
readChannel
-
writeChannel
-
seekChannel
-
selectChannel
-
fileChannel
-
socketChannel
-
finishWriteconv
-
setNonblock
-
setBlock
-
setBlocking
-
isBlocking
public boolean isBlocking() -
checkTTY
public void checkTTY() -
isBOM
public boolean isBOM() -
setBOM
public void setBOM(boolean bom) -
isStdio
public boolean isStdio() -
readPending
public int readPending() -
getFModeFromString
Deprecated.- Throws:
InvalidValueException
-
getFileno
public int getFileno() -
threadFlock
-
errno
public jnr.constants.platform.Errno errno() -
errno
public void errno(jnr.constants.platform.Errno newErrno) -
cloexecDup2
-
fdFixCloexec
-
addBlockingThread
Add a thread to the list of blocking threads for this IO.- Parameters:
thread- A thread blocking on this IO
-
removeBlockingThread
Remove a thread from the list of blocking threads for this IO.- Parameters:
thread- A thread blocking on this IO
-
interruptBlockingThreads
Fire an IOError in all threads blocking on this IO object -
waitForBlockingThreads
Wait until all blocking threads have exited their blocking area. Use in combination with interruptBlockingThreads to ensure every blocking thread has moved on before proceding to manipulate the IO. -
SET_BINARY_MODE
public void SET_BINARY_MODE() -
SET_TEXT_MODE
private void SET_TEXT_MODE() -
remainSize
public int remainSize() -
lock
public boolean lock() -
unlock
public void unlock() -
lockedByMe
public boolean lockedByMe() -
binwrite
@Deprecated public long binwrite(ThreadContext context, byte[] ptrBytes, int ptr, int len, boolean nosync) Deprecated.
-