public class ChannelDescriptor
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
private java.io.InputStream |
baseInputStream
Used to work-around blocking problems with STDIN.
|
private boolean |
canBeSeekable
Process streams get Channel.newChannel()ed into FileChannel but are not actually
seekable.
|
private java.nio.channels.Channel |
channel
The java.nio.channels.Channel this descriptor wraps.
|
private static boolean |
DEBUG
Whether to log debugging information
|
private static java.lang.Class |
FILE_CHANNEL_IMPL |
private static java.lang.reflect.Field |
FILE_CHANNEL_IMPL_FD |
private static java.lang.reflect.Field |
FILE_DESCRIPTOR_FD |
private java.io.FileDescriptor |
fileDescriptor
The java.io.FileDescriptor object for this descriptor.
|
private static java.util.Map<java.lang.Integer,ChannelDescriptor> |
filenoDescriptorMap |
private int |
internalFileno
The file number (equivalent to the int file descriptor value in POSIX)
for this descriptor.
|
protected static java.util.concurrent.atomic.AtomicInteger |
internalFilenoIndex |
private boolean |
isInAppendMode
If the incoming channel is already in append mode (i.e.
|
private static Logger |
LOG |
private ModeFlags |
originalModes
The original org.jruby.util.io.ModeFlags with which the specified
channel was opened.
|
private boolean |
readableChannel
Whether the current channe is writable or not.
|
private java.util.concurrent.atomic.AtomicInteger |
refCounter
The reference count for the provided channel.
|
private boolean |
seekableChannel
Whether the current channel is seekable or not.
|
private static java.lang.Class |
SEL_CH_IMPL |
private static java.lang.reflect.Method |
SEL_CH_IMPL_GET_FD |
private boolean |
writableChannel
Whether the current channel is readable or not.
|
| Modifier | Constructor and Description |
|---|---|
|
ChannelDescriptor(java.nio.channels.Channel channel)
Construct a new ChannelDescriptor with the given channel, file number,
and file descriptor object.
|
|
ChannelDescriptor(java.nio.channels.Channel channel,
java.io.FileDescriptor fileDescriptor)
Construct a new ChannelDescriptor with the given channel, file number,
and file descriptor object.
|
|
ChannelDescriptor(java.nio.channels.Channel channel,
int fileno,
java.io.FileDescriptor fileDescriptor)
Deprecated.
|
private |
ChannelDescriptor(java.nio.channels.Channel channel,
int fileno,
ModeFlags originalModes,
java.io.FileDescriptor fileDescriptor) |
private |
ChannelDescriptor(java.nio.channels.Channel channel,
int fileno,
ModeFlags originalModes,
java.io.FileDescriptor fileDescriptor,
java.util.concurrent.atomic.AtomicInteger refCounter,
boolean canBeSeekable,
boolean isInAppendMode)
Construct a new ChannelDescriptor with the specified channel, file number,
mode flags, file descriptor object and reference counter.
|
|
ChannelDescriptor(java.nio.channels.Channel channel,
ModeFlags originalModes)
Construct a new ChannelDescriptor with the given channel, file number, mode flags,
and file descriptor object.
|
|
ChannelDescriptor(java.nio.channels.Channel channel,
ModeFlags originalModes,
java.io.FileDescriptor fileDescriptor)
Construct a new ChannelDescriptor with the given channel, file number, mode flags,
and file descriptor object.
|
|
ChannelDescriptor(java.nio.channels.Channel channel,
ModeFlags originalModes,
java.io.FileDescriptor fileDescriptor,
boolean isInAppendMode)
Construct a new ChannelDescriptor with the given channel, file number, mode flags,
and file descriptor object.
|
|
ChannelDescriptor(java.io.InputStream baseInputStream,
ModeFlags originalModes)
Special constructor to create the ChannelDescriptor out of the stream, file number,
mode flags, and file descriptor object.
|
|
ChannelDescriptor(java.io.InputStream baseInputStream,
ModeFlags originalModes,
java.io.FileDescriptor fileDescriptor)
Special constructor to create the ChannelDescriptor out of the stream, file number,
mode flags, and file descriptor object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
checkNewModes(ModeFlags newModes)
Check whether a specified set of mode flags is a superset of this
descriptor's original set of mode flags.
|
void |
checkOpen()
Check whether the isOpen returns true, raising a BadDescriptorException if
it returns false.
|
void |
close()
Close this descriptor.
|
ChannelDescriptor |
dup()
Mimics the POSIX dup(2) function, returning a new descriptor that references
the same open channel.
|
ChannelDescriptor |
dup2(int fileno)
Mimics the POSIX dup2(2) function, returning a new descriptor that references
the same open channel but with a specified fileno.
|
void |
dup2Into(ChannelDescriptor other)
Mimics the POSIX dup2(2) function, returning a new descriptor that references
the same open channel but with a specified fileno.
|
(package private) void |
finish(boolean close) |
(package private) java.io.InputStream |
getBaseInputStream()
This is intentionally non-public, since it should not be really
used outside of very limited use case (handling of STDIN).
|
java.nio.channels.Channel |
getChannel()
The channel associated with this descriptor.
|
static ChannelDescriptor |
getDescriptorByFileno(int aFileno) |
static java.io.FileDescriptor |
getDescriptorFromChannel(java.nio.channels.Channel channel) |
java.io.FileDescriptor |
getFileDescriptor()
Get the FileDescriptor object associated with this descriptor.
|
int |
getFileno()
Get this descriptor's file number.
|
static java.util.Map<java.lang.Integer,ChannelDescriptor> |
getFilenoDescriptorMapReadOnly() |
private static ModeFlags |
getModesFromChannel(java.nio.channels.Channel channel)
Build a set of mode flags using the specified channel's actual capabilities.
|
static int |
getNewFileno() |
ModeFlags |
getOriginalModes()
Get the original mode flags for the descriptor.
|
int |
internalWrite(java.nio.ByteBuffer buffer)
Write the bytes in the specified byte list to the associated channel.
|
boolean |
isNull()
Whether the channel associated with this descriptor is a NullChannel,
for which many operations are simply noops.
|
boolean |
isOpen()
Whether the channel associated with this descriptor is open.
|
boolean |
isReadable()
Whether the channel associated with this descriptor is readable (i.e.
|
boolean |
isSeekable()
Whether the channel associated with this descriptor is seekable (i.e.
|
boolean |
isWritable()
Whether the channel associated with this descriptor is writable (i.e.
|
long |
lseek(long offset,
int whence)
Perform a low-level seek operation on the associated channel if it is
instanceof FileChannel, or raise PipeException if it is not a FileChannel.
|
static ChannelDescriptor |
open(java.lang.String cwd,
java.lang.String path,
ModeFlags flags)
Open a new descriptor using the given working directory, file path,
mode flags, and file permission.
|
static ChannelDescriptor |
open(java.lang.String cwd,
java.lang.String path,
ModeFlags flags,
java.lang.ClassLoader classLoader)
Open a new descriptor using the given working directory, file path,
mode flags, and file permission.
|
static ChannelDescriptor |
open(java.lang.String cwd,
java.lang.String path,
ModeFlags flags,
int perm,
jnr.posix.POSIX posix)
Open a new descriptor using the given working directory, file path,
mode flags, and file permission.
|
static ChannelDescriptor |
open(java.lang.String cwd,
java.lang.String path,
ModeFlags flags,
int perm,
jnr.posix.POSIX posix,
java.lang.ClassLoader classLoader)
Open a new descriptor using the given working directory, file path,
mode flags, and file permission.
|
int |
read(java.nio.ByteBuffer buffer)
Perform a low-level read of the remaining number of bytes into the specified
byte buffer.
|
int |
read(int number,
org.jruby.util.ByteList byteList)
Perform a low-level read of the specified number of bytes into the specified
byte list.
|
private static void |
registerDescriptor(ChannelDescriptor descriptor) |
ChannelDescriptor |
reopen(java.nio.channels.Channel channel,
ModeFlags modes) |
ChannelDescriptor |
reopen(java.io.RandomAccessFile file,
ModeFlags modes) |
void |
setCanBeSeekable(boolean canBeSeekable)
Set the channel to be explicitly seekable or not, for streams that appear
to be seekable with the instanceof FileChannel check.
|
static void |
unregisterDescriptor(int aFileno) |
int |
write(java.nio.ByteBuffer buffer)
Write the bytes in the specified byte list to the associated channel.
|
int |
write(org.jruby.util.ByteList buf)
Write the bytes in the specified byte list to the associated channel.
|
int |
write(org.jruby.util.ByteList buf,
int offset,
int len)
Write the bytes in the specified byte list to the associated channel.
|
int |
write(int c)
Write the byte represented by the specified int to the associated channel.
|
private static final Logger LOG
private static final boolean DEBUG
private java.nio.channels.Channel channel
private int internalFileno
private java.io.FileDescriptor fileDescriptor
private ModeFlags originalModes
private java.util.concurrent.atomic.AtomicInteger refCounter
private java.io.InputStream baseInputStream
null.
See ChannelDescriptor(java.io.InputStream, ModeFlags, java.io.FileDescriptor)
for more details. You probably should not use it.private boolean canBeSeekable
private boolean isInAppendMode
private boolean readableChannel
private boolean writableChannel
private boolean seekableChannel
protected static final java.util.concurrent.atomic.AtomicInteger internalFilenoIndex
private static final java.util.Map<java.lang.Integer,ChannelDescriptor> filenoDescriptorMap
private static final java.lang.Class SEL_CH_IMPL
private static final java.lang.reflect.Method SEL_CH_IMPL_GET_FD
private static final java.lang.Class FILE_CHANNEL_IMPL
private static final java.lang.reflect.Field FILE_CHANNEL_IMPL_FD
private static final java.lang.reflect.Field FILE_DESCRIPTOR_FD
private ChannelDescriptor(java.nio.channels.Channel channel,
int fileno,
ModeFlags originalModes,
java.io.FileDescriptor fileDescriptor,
java.util.concurrent.atomic.AtomicInteger refCounter,
boolean canBeSeekable,
boolean isInAppendMode)
channel - The channel for the new descriptor, which will be shared with anotherfileno - The new file number for the new descriptororiginalModes - The mode flags to use as the "origina" set for this descriptorfileDescriptor - The java.io.FileDescriptor object to associate with this ChannelDescriptorrefCounter - The reference counter from another ChannelDescriptor being duped.canBeSeekable - If the underlying channel can be considered seekable.isInAppendMode - If the underlying channel is already in append mode.private ChannelDescriptor(java.nio.channels.Channel channel,
int fileno,
ModeFlags originalModes,
java.io.FileDescriptor fileDescriptor)
public ChannelDescriptor(java.nio.channels.Channel channel,
ModeFlags originalModes,
java.io.FileDescriptor fileDescriptor)
channel - The channel for the new descriptororiginalModes - The mode flags for the new descriptorfileDescriptor - The java.io.FileDescriptor object for the new descriptorpublic ChannelDescriptor(java.nio.channels.Channel channel,
ModeFlags originalModes,
java.io.FileDescriptor fileDescriptor,
boolean isInAppendMode)
channel - The channel for the new descriptororiginalModes - The mode flags for the new descriptorfileDescriptor - The java.io.FileDescriptor object for the new descriptorpublic ChannelDescriptor(java.nio.channels.Channel channel,
ModeFlags originalModes)
channel - The channel for the new descriptororiginalModes - The mode flags for the new descriptorpublic ChannelDescriptor(java.io.InputStream baseInputStream,
ModeFlags originalModes,
java.io.FileDescriptor fileDescriptor)
baseInputStream - The stream to create the channel for the new descriptororiginalModes - The mode flags for the new descriptorfileDescriptor - The java.io.FileDescriptor object for the new descriptorpublic ChannelDescriptor(java.io.InputStream baseInputStream,
ModeFlags originalModes)
baseInputStream - The stream to create the channel for the new descriptororiginalModes - The mode flags for the new descriptorpublic ChannelDescriptor(java.nio.channels.Channel channel,
java.io.FileDescriptor fileDescriptor)
throws InvalidValueException
channel - The channel for the new descriptorfileDescriptor - The java.io.FileDescriptor object for the new descriptorInvalidValueException@Deprecated
public ChannelDescriptor(java.nio.channels.Channel channel,
int fileno,
java.io.FileDescriptor fileDescriptor)
throws InvalidValueException
InvalidValueExceptionpublic ChannelDescriptor(java.nio.channels.Channel channel)
throws InvalidValueException
channel - The channel for the new descriptorInvalidValueExceptionpublic int getFileno()
public java.io.FileDescriptor getFileDescriptor()
public java.nio.channels.Channel getChannel()
java.io.InputStream getBaseInputStream()
ChannelDescriptor(java.io.InputStream, ModeFlags, java.io.FileDescriptor)
for more info.public boolean isSeekable()
public void setCanBeSeekable(boolean canBeSeekable)
canBeSeekable - Whether the channel is seekable or not.public boolean isNull()
public boolean isWritable()
public boolean isReadable()
public boolean isOpen()
public void checkOpen()
throws BadDescriptorException
BadDescriptorException - if isOpen returns falsepublic ModeFlags getOriginalModes()
public void checkNewModes(ModeFlags newModes) throws InvalidValueException
newModes - The modes to confirm as supersetInvalidValueException - if the modes are not a supersetpublic ChannelDescriptor dup()
public ChannelDescriptor dup2(int fileno)
fileno - The fileno to use for the new descriptorpublic void dup2Into(ChannelDescriptor other) throws BadDescriptorException, java.io.IOException
other - the descriptor to dup this one intoBadDescriptorExceptionjava.io.IOExceptionpublic ChannelDescriptor reopen(java.nio.channels.Channel channel, ModeFlags modes)
public ChannelDescriptor reopen(java.io.RandomAccessFile file, ModeFlags modes) throws java.io.IOException
java.io.IOExceptionpublic long lseek(long offset,
int whence)
throws java.io.IOException,
InvalidValueException,
PipeException,
BadDescriptorException
offset - the offset value to usewhence - whence to seekjava.io.IOException - If there is an exception while seekingInvalidValueException - If the value specified for
offset or whence is invalidPipeException - If the target channel is not seekableBadDescriptorException - If the target channel is
already closed.public int read(int number,
org.jruby.util.ByteList byteList)
throws java.io.IOException,
BadDescriptorException
number - the number of bytes to readbyteList - the byte list on which to append the incoming bytesjava.io.IOException - if there is an exception during IOBadDescriptorException - if the associated
channel is already closed.ByteListpublic int read(java.nio.ByteBuffer buffer)
throws java.io.IOException,
BadDescriptorException
buffer - the java.nio.ByteBuffer in which to put the incoming bytesjava.io.IOException - if there is an exception during IOBadDescriptorException - if the associated
channel is already closedByteBufferpublic int internalWrite(java.nio.ByteBuffer buffer)
throws java.io.IOException,
BadDescriptorException
buffer - the byte list containing the bytes to be writtenjava.io.IOException - if there is an exception during IOBadDescriptorException - if the associated
channel is already closedpublic int write(java.nio.ByteBuffer buffer)
throws java.io.IOException,
BadDescriptorException
buffer - the byte list containing the bytes to be writtenjava.io.IOException - if there is an exception during IOBadDescriptorException - if the associated
channel is already closedpublic int write(org.jruby.util.ByteList buf)
throws java.io.IOException,
BadDescriptorException
buf - the byte list containing the bytes to be writtenjava.io.IOException - if there is an exception during IOBadDescriptorException - if the associated
channel is already closedpublic int write(org.jruby.util.ByteList buf,
int offset,
int len)
throws java.io.IOException,
BadDescriptorException
buf - the byte list containing the bytes to be writtenoffset - the offset to start at. this is relative to the begin variable in the butlen - the amount of bytes to write. this should not be longer than the bufferjava.io.IOException - if there is an exception during IOBadDescriptorException - if the associated
channel is already closedpublic int write(int c)
throws java.io.IOException,
BadDescriptorException
c - The byte to writejava.io.IOException - If there was an exception during IOBadDescriptorException - if the associated
channel is already closedpublic static ChannelDescriptor open(java.lang.String cwd, java.lang.String path, ModeFlags flags) throws java.io.FileNotFoundException, DirectoryAsFileException, FileExistsException, java.io.IOException
cwd - the "current working directory" to use when opening the filepath - the file path to openflags - the mode flags to use for opening the filejava.io.FileNotFoundExceptionDirectoryAsFileExceptionFileExistsExceptionjava.io.IOExceptionpublic static ChannelDescriptor open(java.lang.String cwd, java.lang.String path, ModeFlags flags, java.lang.ClassLoader classLoader) throws java.io.FileNotFoundException, DirectoryAsFileException, FileExistsException, java.io.IOException
cwd - the "current working directory" to use when opening the filepath - the file path to openflags - the mode flags to use for opening the fileclassLoader - a ClassLoader to use for classpath: resourcesjava.io.FileNotFoundExceptionDirectoryAsFileExceptionFileExistsExceptionjava.io.IOExceptionpublic static ChannelDescriptor open(java.lang.String cwd, java.lang.String path, ModeFlags flags, int perm, jnr.posix.POSIX posix) throws java.io.FileNotFoundException, DirectoryAsFileException, FileExistsException, java.io.IOException
cwd - the "current working directory" to use when opening the filepath - the file path to openflags - the mode flags to use for opening the fileperm - the file permissions to use when creating a new file (currently
unobserved)posix - a POSIX api implementation, used for setting permissions; if null, permissions are ignoredjava.io.FileNotFoundExceptionDirectoryAsFileExceptionFileExistsExceptionjava.io.IOExceptionpublic static ChannelDescriptor open(java.lang.String cwd, java.lang.String path, ModeFlags flags, int perm, jnr.posix.POSIX posix, java.lang.ClassLoader classLoader) throws java.io.FileNotFoundException, DirectoryAsFileException, FileExistsException, java.io.IOException
cwd - the "current working directory" to use when opening the filepath - the file path to openflags - the mode flags to use for opening the fileperm - the file permissions to use when creating a new file (currently
unobserved)posix - a POSIX api implementation, used for setting permissions; if null, permissions are ignoredclassLoader - a ClassLoader to use for classpath: resourcesjava.io.FileNotFoundExceptionDirectoryAsFileExceptionFileExistsExceptionjava.io.IOExceptionpublic void close()
throws BadDescriptorException,
java.io.IOException
BadDescriptorException - if the associated
channel is already closedjava.io.IOException - if there is an exception during IOvoid finish(boolean close)
throws BadDescriptorException,
java.io.IOException
BadDescriptorExceptionjava.io.IOExceptionprivate static ModeFlags getModesFromChannel(java.nio.channels.Channel channel) throws InvalidValueException
channel - the channel to examine for capabilitiesInvalidValueExceptionpublic static int getNewFileno()
private static void registerDescriptor(ChannelDescriptor descriptor)
public static void unregisterDescriptor(int aFileno)
public static ChannelDescriptor getDescriptorByFileno(int aFileno)
public static java.util.Map<java.lang.Integer,ChannelDescriptor> getFilenoDescriptorMapReadOnly()
public static java.io.FileDescriptor getDescriptorFromChannel(java.nio.channels.Channel channel)