Class OpenFile

java.lang.Object
org.jruby.util.io.OpenFile
All Implemented Interfaces:
Finalizable

public class OpenFile extends Object implements Finalizable
  • Field Details

  • Constructor Details

  • Method Details

    • ascii8bitBinmode

      public void ascii8bitBinmode(Ruby runtime)
    • checkReopenSeek

      public void checkReopenSeek(ThreadContext context, Ruby runtime, long pos)
    • clearStdio

      public void clearStdio()
    • PREP_STDIO_NAME

      public String 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

      public void READ_CHECK(ThreadContext context)
    • IS_PREP_STDIO

      public boolean IS_PREP_STDIO()
    • setFD

      public void setFD(ChannelFD fd)
    • setChannel

      public void setChannel(Channel fd)
    • getMode

      public int getMode()
    • getModeAsString

      public String getModeAsString(Ruby runtime)
    • getModeFlagsAsIntFrom

      public static int getModeFlagsAsIntFrom(int fmode)
    • ioOflagsModestr

      public static String ioOflagsModestr(Ruby runtime, int oflags)
    • ioModestrOflags

      public static int ioModestrOflags(Ruby runtime, String modestr)
    • ioFmodeOflags

      public static int ioFmodeOflags(int fmode)
    • ioModestrFmode

      public static int ioModestrFmode(Ruby runtime, String modestr)
    • ioEncnameBomP

      static boolean ioEncnameBomP(String name, long len)
    • MODE_BINARY

      private static String MODE_BINARY(int oflags, String a, String b)
    • getStringFromMode

      public static String getStringFromMode(int mode)
    • checkCharReadable

      public void checkCharReadable(ThreadContext context)
    • checkByteReadable

      public void checkByteReadable(ThreadContext context)
    • checkReadable

      public void checkReadable(ThreadContext context)
    • io_fflush

      public int io_fflush(ThreadContext context)
    • waitWritable

      public boolean waitWritable(ThreadContext context, long timeout)
    • waitWritable

      public boolean waitWritable(ThreadContext context)
    • waitReadable

      public boolean waitReadable(ThreadContext context, long timeout)
    • waitReadable

      public boolean waitReadable(ThreadContext context)
    • ready

      public boolean ready(Ruby runtime, RubyThread thread, int ops, long timeout)
      Wait until the channel is available for the given operations or the timeout expires.
      Parameters:
      runtime -
      ops -
      timeout -
      Returns:
      See Also:
    • readyNow

      public boolean readyNow(ThreadContext context)
      Like ready(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

      public long seek(ThreadContext context, long offset, int whence)
    • flushBeforeSeek

      private void flushBeforeSeek(ThreadContext context)
    • checkWritable

      public void checkWritable(ThreadContext context)
    • 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

      public Process getProcess()
    • setProcess

      public void setProcess(Process process)
    • getPid

      public long getPid()
    • setPid

      public void setPid(long pid)
    • getLineNumber

      public int getLineNumber()
    • setLineNumber

      public void setLineNumber(int lineNumber)
    • getPath

      public String getPath()
    • setPath

      public void setPath(String path)
    • isAutoclose

      public boolean isAutoclose()
    • setAutoclose

      public void setAutoclose(boolean autoclose)
    • getFinalizer

      public OpenFile.Finalizer getFinalizer()
    • setFinalizer

      public void setFinalizer(OpenFile.Finalizer finalizer)
    • cleanup

      public void cleanup(Ruby runtime, boolean noraise)
    • finalize

      public void finalize()
      Specified by:
      finalize in interface Finalizable
      Overrides:
      finalize in class Object
    • finalize

      public void finalize(ThreadContext context, boolean noraise)
    • finalizeFlush

      public void finalizeFlush(ThreadContext context, boolean noraise)
    • needsReadConversion

      public boolean needsReadConversion()
    • needsWriteConversion

      public boolean needsWriteConversion(ThreadContext context)
    • makeReadConversion

      public void makeReadConversion(ThreadContext context, int size)
    • makeReadConversion

      public void makeReadConversion(ThreadContext context)
    • makeWriteConversion

      public void makeWriteConversion(ThreadContext context)
    • clearReadConversion

      public void clearReadConversion()
    • clearCodeConversion

      public void clearCodeConversion()
    • IO_RBUF_CAPA_FOR

      public int IO_RBUF_CAPA_FOR()
    • appendline

      public int appendline(ThreadContext context, int delim, ByteList[] strp, int[] lp)
    • 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

      public int moreChar(ThreadContext context)
    • fillCbuf

      private Object fillCbuf(ThreadContext context, int ec_flags)
    • readBufferedData

      public int readBufferedData(byte[] ptrBytes, int ptr, int len)
    • fillbuf

      public int fillbuf(ThreadContext context)
    • readInternal

      public static int readInternal(ThreadContext context, OpenFile fptr, ChannelFD fd, byte[] bufBytes, int buf, int count)
    • waitReadable

      boolean waitReadable(ThreadContext context, ChannelFD fd)
      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

      public org.jcodings.Encoding readEncoding(Ruby runtime)
    • inputEncoding

      public org.jcodings.Encoding inputEncoding(Ruby runtime)
    • swallow

      public boolean swallow(ThreadContext context, int term)
    • shiftCbuf

      public RubyString shiftCbuf(ThreadContext context, int len, IRubyObject strp)
    • shiftCbuf

      public RubyString shiftCbuf(int len, RubyString str)
    • getlineFast

      public IRubyObject getlineFast(ThreadContext context, org.jcodings.Encoding enc, RubyIO io, boolean chomp)
    • incrementLineno

      public void incrementLineno(Ruby runtime, RubyIO io)
    • incrementLineno

      @Deprecated public void incrementLineno(Ruby runtime)
      Deprecated.
    • readAll

      public IRubyObject readAll(ThreadContext context, int siz, IRubyObject str)
    • ioBufread

      private int ioBufread(ThreadContext context, byte[] ptrBytes, int ptr, int len)
    • fread

      public int fread(ThreadContext context, byte[] buffer, int offset, int size)
    • ungetbyte

      public void ungetbyte(ThreadContext context, IRubyObject str)
    • getc

      public IRubyObject getc(ThreadContext context, org.jcodings.Encoding enc)
    • tell

      public long tell(ThreadContext context)
    • unread

      public void unread(ThreadContext context)
    • unreadPosix

      private void unreadPosix()
    • unreadWindows

      private void unreadWindows(ThreadContext context)
    • fwrite

      public long fwrite(ThreadContext context, RubyString str, boolean nosync)
    • fwrite

      public int fwrite(ThreadContext context, byte[] bytes, int start, int length, org.jcodings.Encoding encoding, boolean nosync)
    • rbW32WriteConsole

      public static long rbW32WriteConsole(RubyString buffer)
    • rbW32WriteConsole

      public static int rbW32WriteConsole(byte[] bytes, int start, int length, org.jcodings.Encoding encoding)
    • doWriteconv

      public RubyString doWriteconv(ThreadContext context, RubyString str)
    • 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

      public int binwriteInt(ThreadContext context, byte[] ptrBytes, int ptr, int len, boolean nosync)
    • binwriteString

      static int binwriteString(OpenFile fptr, byte[] bytes, int start, int length)
    • writeInternal

      public static int writeInternal(ThreadContext context, OpenFile fptr, byte[] bufBytes, int buf, int count)
    • writeInternal2

      int writeInternal2(ChannelFD fd, byte[] bufBytes, int buf, int count)
    • fd

      public ChannelFD fd()
    • channel

      public Channel channel()
    • readChannel

      public ReadableByteChannel readChannel()
    • writeChannel

      public WritableByteChannel writeChannel()
    • seekChannel

      public SeekableByteChannel seekChannel()
    • selectChannel

      public SelectableChannel selectChannel()
    • fileChannel

      public FileChannel fileChannel()
    • socketChannel

      public SocketChannel socketChannel()
    • finishWriteconv

      IRubyObject finishWriteconv(ThreadContext context, boolean noalloc)
    • setNonblock

      public void setNonblock(Ruby runtime)
    • setBlock

      public void setBlock(Ruby runtime)
    • setBlocking

      public void setBlocking(Ruby runtime, boolean blocking)
    • 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 public static int getFModeFromString(String modesString) throws InvalidValueException
      Deprecated.
      Throws:
      InvalidValueException
    • getFileno

      public int getFileno()
    • threadFlock

      public int threadFlock(ThreadContext context, int lockMode)
    • errno

      public jnr.constants.platform.Errno errno()
    • errno

      public void errno(jnr.constants.platform.Errno newErrno)
    • cloexecDup2

      public static int cloexecDup2(PosixShim posix, ChannelFD oldfd, ChannelFD newfd)
    • fdFixCloexec

      public static void fdFixCloexec(PosixShim posix, int fd)
    • addBlockingThread

      public void addBlockingThread(RubyThread thread)
      Add a thread to the list of blocking threads for this IO.
      Parameters:
      thread - A thread blocking on this IO
    • removeBlockingThread

      public void removeBlockingThread(RubyThread thread)
      Remove a thread from the list of blocking threads for this IO.
      Parameters:
      thread - A thread blocking on this IO
    • interruptBlockingThreads

      public void interruptBlockingThreads(ThreadContext context)
      Fire an IOError in all threads blocking on this IO object
    • waitForBlockingThreads

      public void waitForBlockingThreads(ThreadContext context)
      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.