public class ChannelDescriptor
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected static java.util.concurrent.atomic.AtomicInteger |
internalFilenoIndex |
| 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.
|
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.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.
|
java.nio.channels.Channel |
getChannel()
The channel associated with this descriptor.
|
static ChannelDescriptor |
getDescriptorByFileno(int aFileno) |
java.io.FileDescriptor |
getFileDescriptor()
Get the FileDescriptor object associated with this descriptor.
|
int |
getFileno()
Get this descriptor's file number.
|
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 |
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,
org.jruby.ext.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,
org.jruby.ext.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.
|
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.
|
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.
|
protected static final java.util.concurrent.atomic.AtomicInteger internalFilenoIndex
public ChannelDescriptor(java.nio.channels.Channel channel,
ModeFlags originalModes,
java.io.FileDescriptor fileDescriptor)
channel - The channel for the new descriptorfileno - The file number 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 descriptorfileDescriptor - The java.io.FileDescriptor object 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 descriptorfileno - The file number 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 descriptorfileDescriptor - The java.io.FileDescriptor object for the new descriptorpublic ChannelDescriptor(java.nio.channels.Channel channel,
java.io.FileDescriptor fileDescriptor)
throws InvalidValueException
channel - The channel for the new descriptorfileno - The file number 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 descriptorfileDescriptor - The java.io.FileDescriptor object for the new descriptorInvalidValueExceptionpublic int getFileno()
public java.io.FileDescriptor getFileDescriptor()
public java.nio.channels.Channel getChannel()
public boolean isSeekable()
public void setCanBeSeekable(boolean canBeSeekable)
seekable - Whether the channel is seekable or not.public boolean isNull()
public boolean isWritable()
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
fileno - The fileno to use for the new descriptorBadDescriptorExceptionjava.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.java.util.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
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(java.nio.ByteBuffer buffer)
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)
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.FileNotFoundException - if the target file could not be found
and the create flag was not specifiedDirectoryAsFileException - if the target file is
a directory being opened as a fileFileExistsException - if the target file should
be created anew, but already existsjava.io.IOException - if there is an exception during IOpublic 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.FileNotFoundException - if the target file could not be found
and the create flag was not specifiedDirectoryAsFileException - if the target file is
a directory being opened as a fileFileExistsException - if the target file should
be created anew, but already existsjava.io.IOException - if there is an exception during IOpublic static ChannelDescriptor open(java.lang.String cwd, java.lang.String path, ModeFlags flags, int perm, org.jruby.ext.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.FileNotFoundException - if the target file could not be found
and the create flag was not specifiedDirectoryAsFileException - if the target file is
a directory being opened as a fileFileExistsException - if the target file should
be created anew, but already existsjava.io.IOException - if there is an exception during IOpublic static ChannelDescriptor open(java.lang.String cwd, java.lang.String path, ModeFlags flags, int perm, org.jruby.ext.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.FileNotFoundException - if the target file could not be found
and the create flag was not specifiedDirectoryAsFileException - if the target file is
a directory being opened as a fileFileExistsException - if the target file should
be created anew, but already existsjava.io.IOException - if there is an exception during IOpublic void close()
throws BadDescriptorException,
java.io.IOException
BadDescriptorException - if the associated
channel is already closedjava.io.IOException - if there is an exception during IOpublic static int getNewFileno()
public static ChannelDescriptor getDescriptorByFileno(int aFileno)
Copyright © 2002-2009 JRuby Team. All Rights Reserved.