public class ChannelStream extends java.lang.Object implements Stream, Finalizable
| Modifier and Type | Class and Description |
|---|---|
private static class |
ChannelStream.InputStreamAdapter |
private static class |
ChannelStream.OutputStreamAdapter |
| Modifier and Type | Field and Description |
|---|---|
private boolean |
autoclose |
private boolean |
blocking |
protected java.nio.ByteBuffer |
buffer |
static int |
BUFSIZE
The size of the read/write buffer allocated for this stream.
|
private static int |
BULK_READ_SIZE
The size at which a single read should turn into a chunkier bulk read.
|
private boolean |
closedExplicitly |
private static boolean |
DEBUG |
private ChannelDescriptor |
descriptor |
private static java.nio.ByteBuffer |
EMPTY_BUFFER |
private boolean |
eof |
private static java.io.EOFException |
eofException
A cached EOFException.
|
private static Logger |
LOG |
protected ModeFlags |
modes |
protected boolean |
reading |
private Ruby |
runtime |
protected boolean |
sync |
private org.jruby.util.ByteList |
ungotChars |
PARAGRAPH_DELIMETER, PARAGRAPH_SEPARATOR, SEEK_CUR, SEEK_END, SEEK_SET| Modifier | Constructor and Description |
|---|---|
private |
ChannelStream(Ruby runtime,
ChannelDescriptor descriptor,
boolean autoclose) |
private |
ChannelStream(Ruby runtime,
ChannelDescriptor descriptor,
ModeFlags modes,
boolean autoclose) |
| Modifier and Type | Method and Description |
|---|---|
private int |
bufferedInputBytesRemaining()
Returns a count of how many bytes are available in the read buffer
|
private int |
bufferedOutputSpaceRemaining()
Returns a count of how many bytes of space is available in the write buffer.
|
private int |
bufferedRead() |
private int |
bufferedRead(java.nio.ByteBuffer dst,
boolean partial) |
private int |
bufferedRead(org.jruby.util.ByteList dst,
int number) |
private org.jruby.util.ByteList |
bufferedRead(int number) |
private int |
bufferedWrite(java.nio.ByteBuffer buf) |
private int |
bufferedWrite(org.jruby.util.ByteList buf) |
private int |
bufferedWrite(int c) |
void |
checkPermissionsSubsetOf(ModeFlags subsetModes) |
void |
checkReadable() |
void |
checkWritable() |
void |
clearerr() |
private void |
clearUngotChars() |
private void |
close()
Internal close.
|
private int |
copyBufferedBytes(byte[] dst,
int off,
int len)
Copies bytes from the channel buffer into a destination ByteBuffer
|
private int |
copyBufferedBytes(java.nio.ByteBuffer dst)
Copies bytes from the channel buffer into a destination ByteBuffer
|
private int |
copyBufferedBytes(org.jruby.util.ByteList dst,
int len)
Copies bytes from the channel buffer into a destination ByteBuffer
|
private void |
ensureRead()
Ensure buffer is ready for reading, flushing remaining writes if required
|
private void |
ensureReadNonBuffered()
Ensure buffer is ready for reading, flushing remaining writes if required
|
private void |
ensureWrite()
Ensure buffer is ready for writing.
|
void |
fclose()
Closes IO handler resources.
|
static Stream |
fdopen(Ruby runtime,
ChannelDescriptor descriptor,
ModeFlags modes) |
static Stream |
fdopen(Ruby runtime,
ChannelDescriptor descriptor,
ModeFlags modes,
boolean autoclose) |
boolean |
feof()
Return true when at end of file (EOF).
|
int |
fflush() |
int |
fgetc() |
long |
fgetpos()
Get the current position within the file associated with this
handler.
|
org.jruby.util.ByteList |
fgets(org.jruby.util.ByteList separatorString) |
void |
finalize()
Ensure close (especially flush) when we're finished with.
|
private void |
finish(boolean close) |
private void |
flushWrite()
Flush the write buffer to the channel (if needed)
|
private boolean |
flushWrite(boolean block)
Flush the write buffer to the channel (if needed)
|
static Stream |
fopen(Ruby runtime,
java.lang.String path,
ModeFlags modes) |
void |
fputc(int c) |
org.jruby.util.ByteList |
fread(int number) |
void |
freopen(Ruby runtime,
java.lang.String path,
ModeFlags modes) |
void |
ftruncate(long newLength) |
int |
fwrite(org.jruby.util.ByteList string) |
java.nio.channels.Channel |
getChannel() |
ChannelDescriptor |
getDescriptor() |
int |
getline(org.jruby.util.ByteList dst,
byte terminator)
Read all bytes up to and including a terminator byte.
|
int |
getline(org.jruby.util.ByteList dst,
byte terminator,
long limit)
Reads all bytes up to and including a terminator byte or until limit is reached.
|
ModeFlags |
getModes() |
Ruby |
getRuntime() |
private boolean |
hasBufferedInputBytes()
Tests if there are bytes remaining in the read buffer.
|
private boolean |
hasBufferedOutputSpace()
Tests if there is space available in the write buffer.
|
private boolean |
hasUngotChars() |
private void |
invalidateBuffer()
Invalidate buffer before a position change has occurred (e.g.
|
boolean |
isAutoclose() |
boolean |
isBinmode() |
boolean |
isBlocking() |
boolean |
isSync() |
void |
lseek(long offset,
int type)
Implementation of libc "lseek", which seeks on seekable streams, raises
EPIPE if the fd is assocated with a pipe, socket, or FIFO, and doesn't
do anything for other cases (like stdio).
|
private static Stream |
maybeWrapWithLineEndingWrapper(Stream stream,
ModeFlags modes) |
private java.io.EOFException |
newEOFException() |
java.io.InputStream |
newInputStream() |
java.io.OutputStream |
newOutputStream() |
static Stream |
open(Ruby runtime,
ChannelDescriptor descriptor) |
static Stream |
open(Ruby runtime,
ChannelDescriptor descriptor,
boolean autoclose) |
int |
read() |
int |
read(java.nio.ByteBuffer dst) |
int |
read(java.nio.ByteBuffer dst,
boolean partial) |
org.jruby.util.ByteList |
read(int number) |
org.jruby.util.ByteList |
readall()
Deprecated.
readall do busy loop for the IO which has NONBLOCK bit. You
should implement the logic by yourself with fread().
|
boolean |
readDataBuffered() |
org.jruby.util.ByteList |
readnonblock(int number) |
org.jruby.util.ByteList |
readpartial(int number) |
int |
ready()
Implement IO#ready? as per io/wait in MRI.
|
private int |
refillBuffer() |
private void |
resetForWrite() |
void |
setAutoclose(boolean autoclose) |
void |
setBinmode() |
void |
setBlocking(boolean block) |
void |
setModes(ModeFlags modes) |
void |
setSync(boolean sync) |
void |
sync()
Flush and sync all writes to the filesystem.
|
int |
ungetc(int c) |
void |
waitUntilReady()
Implement IO#wait as per io/wait in MRI.
|
int |
write(java.nio.ByteBuffer buf) |
boolean |
writeDataBuffered() |
int |
writenonblock(org.jruby.util.ByteList buf) |
private static final Logger LOG
private static final boolean DEBUG
public static final int BUFSIZE
private static final int BULK_READ_SIZE
private static final java.nio.ByteBuffer EMPTY_BUFFER
private static java.io.EOFException eofException
private volatile Ruby runtime
protected ModeFlags modes
protected boolean sync
protected volatile java.nio.ByteBuffer buffer
protected boolean reading
private ChannelDescriptor descriptor
private boolean blocking
private org.jruby.util.ByteList ungotChars
private volatile boolean closedExplicitly
private volatile boolean eof
private volatile boolean autoclose
private ChannelStream(Ruby runtime, ChannelDescriptor descriptor, boolean autoclose)
private ChannelStream(Ruby runtime, ChannelDescriptor descriptor, ModeFlags modes, boolean autoclose)
public Ruby getRuntime()
public void checkReadable()
throws java.io.IOException
java.io.IOExceptionpublic void checkWritable()
throws java.io.IOException
java.io.IOExceptionpublic void checkPermissionsSubsetOf(ModeFlags subsetModes)
public void setBinmode()
setBinmode in interface Streampublic boolean isAutoclose()
isAutoclose in interface Streampublic void setAutoclose(boolean autoclose)
setAutoclose in interface Streampublic void waitUntilReady()
throws java.io.IOException,
java.lang.InterruptedException
waitUntilReady in interface Streamjava.io.IOExceptionjava.lang.InterruptedExceptionpublic boolean readDataBuffered()
readDataBuffered in interface Streamprivate boolean hasUngotChars()
public boolean writeDataBuffered()
writeDataBuffered in interface Streamprivate final int refillBuffer()
throws java.io.IOException
java.io.IOExceptionpublic org.jruby.util.ByteList fgets(org.jruby.util.ByteList separatorString)
throws java.io.IOException,
BadDescriptorException
fgets in interface Streamjava.io.IOExceptionBadDescriptorExceptionpublic int getline(org.jruby.util.ByteList dst,
byte terminator)
throws java.io.IOException,
BadDescriptorException
StreamIf the terminator byte is found, it will be the last byte in the output buffer.
getline in interface Streamdst - The output buffer.terminator - The byte to terminate reading.java.io.IOExceptionBadDescriptorExceptionpublic int getline(org.jruby.util.ByteList dst,
byte terminator,
long limit)
throws java.io.IOException,
BadDescriptorException
StreamIf the terminator byte is found, it will be the last byte in the output buffer.
getline in interface Streamdst - The output buffer.terminator - The byte to terminate reading.limit - the number of bytes to read unless EOF or terminator is foundjava.io.IOExceptionBadDescriptorExceptionprivate void clearUngotChars()
@Deprecated
public org.jruby.util.ByteList readall()
throws java.io.IOException,
BadDescriptorException
readall in interface Streamjava.io.IOExceptionBadDescriptorExceptionprivate final int copyBufferedBytes(java.nio.ByteBuffer dst)
dst - A ByteBuffer to place the data in.private final int copyBufferedBytes(byte[] dst,
int off,
int len)
dst - A ByteBuffer to place the data in.private final int copyBufferedBytes(org.jruby.util.ByteList dst,
int len)
dst - A ByteList to place the data in.len - The maximum number of bytes to copy.private final int bufferedInputBytesRemaining()
private final boolean hasBufferedInputBytes()
private final int bufferedOutputSpaceRemaining()
private final boolean hasBufferedOutputSpace()
public void fclose()
throws java.io.IOException,
BadDescriptorException
fclose in interface Streamjava.io.IOExceptionBadDescriptorExceptionprivate void close()
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionprivate void finish(boolean close)
throws BadDescriptorException,
java.io.IOException
BadDescriptorExceptionjava.io.IOExceptionpublic int fflush()
throws java.io.IOException,
BadDescriptorException
fflush in interface Streamjava.io.IOExceptionBadDescriptorExceptionprivate void flushWrite()
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionprivate boolean flushWrite(boolean block)
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionpublic java.io.InputStream newInputStream()
newInputStream in interface Streampublic java.io.OutputStream newOutputStream()
newOutputStream in interface Streampublic boolean feof()
throws java.io.IOException,
BadDescriptorException
StreamReturn true when at end of file (EOF).
feof in interface Streamjava.io.IOExceptionBadDescriptorExceptionpublic long fgetpos()
throws java.io.IOException,
PipeException,
InvalidValueException,
BadDescriptorException
StreamGet the current position within the file associated with this handler.
fgetpos in interface Streamjava.io.IOExceptionPipeException - ESPIPE (illegal seek) when not a fileInvalidValueExceptionBadDescriptorExceptionpublic void lseek(long offset,
int type)
throws java.io.IOException,
InvalidValueException,
PipeException,
BadDescriptorException
lseek in interface Streamjava.io.IOExceptionInvalidValueExceptionPipeExceptionBadDescriptorExceptionpublic void sync()
throws java.io.IOException,
BadDescriptorException
StreamFlush and sync all writes to the filesystem.
sync in interface Streamjava.io.IOException - if the sync does not workBadDescriptorExceptionprivate void ensureRead()
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionprivate void ensureReadNonBuffered()
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionprivate void resetForWrite()
throws java.io.IOException
java.io.IOExceptionprivate void ensureWrite()
throws java.io.IOException
java.io.IOExceptionpublic org.jruby.util.ByteList read(int number)
throws java.io.IOException,
BadDescriptorException
read in interface Streamjava.io.IOExceptionBadDescriptorExceptionprivate org.jruby.util.ByteList bufferedRead(int number)
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionprivate int bufferedRead(org.jruby.util.ByteList dst,
int number)
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionprivate java.io.EOFException newEOFException()
private int bufferedRead(java.nio.ByteBuffer dst,
boolean partial)
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionprivate int bufferedRead()
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionprivate int bufferedWrite(org.jruby.util.ByteList buf)
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionprivate int bufferedWrite(java.nio.ByteBuffer buf)
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionprivate int bufferedWrite(int c)
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionpublic void ftruncate(long newLength)
throws java.io.IOException,
BadDescriptorException,
InvalidValueException
ftruncate in interface Streamjava.io.IOExceptionBadDescriptorExceptionInvalidValueExceptionprivate void invalidateBuffer()
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionpublic void finalize()
throws java.lang.Throwable
finalize in interface Finalizablefinalize in class java.lang.Objectjava.lang.Throwablepublic int ready()
throws java.io.IOException
Streampublic void fputc(int c)
throws java.io.IOException,
BadDescriptorException
fputc in interface Streamjava.io.IOExceptionBadDescriptorExceptionpublic int fgetc()
throws java.io.IOException,
BadDescriptorException
fgetc in interface Streamjava.io.IOExceptionBadDescriptorExceptionpublic int fwrite(org.jruby.util.ByteList string)
throws java.io.IOException,
BadDescriptorException
fwrite in interface Streamjava.io.IOExceptionBadDescriptorExceptionpublic int write(java.nio.ByteBuffer buf)
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionpublic int writenonblock(org.jruby.util.ByteList buf)
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionpublic org.jruby.util.ByteList fread(int number)
throws java.io.IOException,
BadDescriptorException
fread in interface Streamjava.io.IOExceptionBadDescriptorExceptionpublic org.jruby.util.ByteList readnonblock(int number)
throws java.io.IOException,
BadDescriptorException,
java.io.EOFException
java.io.IOExceptionBadDescriptorExceptionjava.io.EOFExceptionpublic org.jruby.util.ByteList readpartial(int number)
throws java.io.IOException,
BadDescriptorException,
java.io.EOFException
java.io.IOExceptionBadDescriptorExceptionjava.io.EOFExceptionpublic int read(java.nio.ByteBuffer dst)
throws java.io.IOException,
BadDescriptorException,
java.io.EOFException
java.io.IOExceptionBadDescriptorExceptionjava.io.EOFExceptionpublic int read(java.nio.ByteBuffer dst,
boolean partial)
throws java.io.IOException,
BadDescriptorException,
java.io.EOFException
java.io.IOExceptionBadDescriptorExceptionjava.io.EOFExceptionpublic int read()
throws java.io.IOException,
BadDescriptorException
java.io.IOExceptionBadDescriptorExceptionpublic ChannelDescriptor getDescriptor()
getDescriptor in interface Streampublic void setBlocking(boolean block)
throws java.io.IOException
setBlocking in interface Streamjava.io.IOExceptionpublic boolean isBlocking()
isBlocking in interface Streampublic void freopen(Ruby runtime, java.lang.String path, ModeFlags modes) throws DirectoryAsFileException, java.io.IOException, InvalidValueException, PipeException, BadDescriptorException
freopen in interface StreamDirectoryAsFileExceptionjava.io.IOExceptionInvalidValueExceptionPipeExceptionBadDescriptorExceptionpublic static Stream open(Ruby runtime, ChannelDescriptor descriptor)
public static Stream fdopen(Ruby runtime, ChannelDescriptor descriptor, ModeFlags modes) throws InvalidValueException
InvalidValueExceptionpublic static Stream open(Ruby runtime, ChannelDescriptor descriptor, boolean autoclose)
public static Stream fdopen(Ruby runtime, ChannelDescriptor descriptor, ModeFlags modes, boolean autoclose) throws InvalidValueException
InvalidValueExceptionprivate static Stream maybeWrapWithLineEndingWrapper(Stream stream, ModeFlags modes)
public static Stream fopen(Ruby runtime, java.lang.String path, ModeFlags modes) throws java.io.FileNotFoundException, DirectoryAsFileException, FileExistsException, java.io.IOException, InvalidValueException, PipeException, BadDescriptorException
java.io.FileNotFoundExceptionDirectoryAsFileExceptionFileExistsExceptionjava.io.IOExceptionInvalidValueExceptionPipeExceptionBadDescriptorExceptionpublic java.nio.channels.Channel getChannel()
getChannel in interface Stream