org.jruby.util.io
Class ModeFlags

java.lang.Object
  extended by org.jruby.util.io.ModeFlags
All Implemented Interfaces:
java.lang.Cloneable

public class ModeFlags
extends java.lang.Object
implements java.lang.Cloneable

This file represents the POSIX-like mode flags an open channel (as in a ChannelDescriptor) can have. It provides the basic flags for read/write as well as flags for create, truncate, and others. In addition, it provides methods for querying specific flag settings and converting to two other formats: a Java mode string and an OpenFile mode int.

See Also:
org.jruby.io.util.ChannelDescriptor, org.jruby.io.util.Stream, org.jruby.io.util.OpenFile

Field Summary
static int ACCMODE
          accmode flag (?)
static int APPEND
          append flag, to seek to the end of the file
static int BINARY
          binary flag, to ensure no encoding changes are made while writing
static int CREAT
          create flag, to specify non-existing file should be created
static int EXCL
          exclusive access flag, to require locking the target file
static int NOCTTY
          no ctty flag (?)
static int NONBLOCK
          nonblock flag, to perform all operations non-blocking.
static int RDONLY
          read-only flag (default value if no other flags set)
static int RDWR
          read/write flag
static int TRUNC
          truncate flag, to truncate the target file to zero length
static int WRONLY
          write-only flag
 
Constructor Summary
ModeFlags()
          Construct a new ModeFlags object with the default read-only flag.
ModeFlags(long flags)
          Construct a new ModeFlags object with the specified flags
 
Method Summary
 int getOpenFileFlags()
          Convert the flags in this object to a set of flags appropriate for the OpenFile structure and logic therein.
 boolean isAppendable()
          Whether the flags specify to append to existing files.
 boolean isBinary()
          Whether the flags specify "binary" mode for reads and writes.
 boolean isCreate()
          Whether the flags specify to create nonexisting files.
 boolean isExclusive()
          Whether the flags specify exclusive access.
 boolean isReadable()
          Whether the flags specify "readable", either read/write or read-only.
 boolean isReadOnly()
          Whether the flags specify"read only".
 boolean isSubsetOf(ModeFlags superset)
          Check whether the target set of flags is a superset of this one; used to ensure that a file is not re-opened with more privileges than it already had.
 boolean isTruncate()
          Whether the flags specify to truncate the target file.
 boolean isWritable()
          Whether the flags specify "writable", either read/write or write-only
 java.lang.String toJavaModeString()
          Produce a Java IO mode string from the flags in this object.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RDONLY

public static final int RDONLY
read-only flag (default value if no other flags set)

See Also:
Constant Field Values

WRONLY

public static final int WRONLY
write-only flag

See Also:
Constant Field Values

RDWR

public static final int RDWR
read/write flag

See Also:
Constant Field Values

CREAT

public static final int CREAT
create flag, to specify non-existing file should be created

See Also:
Constant Field Values

EXCL

public static final int EXCL
exclusive access flag, to require locking the target file

See Also:
Constant Field Values

NOCTTY

public static final int NOCTTY
no ctty flag (?)

See Also:
Constant Field Values

TRUNC

public static final int TRUNC
truncate flag, to truncate the target file to zero length

See Also:
Constant Field Values

APPEND

public static final int APPEND
append flag, to seek to the end of the file

See Also:
Constant Field Values

NONBLOCK

public static final int NONBLOCK
nonblock flag, to perform all operations non-blocking. Unused currently

See Also:
Constant Field Values

BINARY

public static final int BINARY
binary flag, to ensure no encoding changes are made while writing

See Also:
Constant Field Values

ACCMODE

public static final int ACCMODE
accmode flag (?)

See Also:
Constant Field Values
Constructor Detail

ModeFlags

public ModeFlags()
Construct a new ModeFlags object with the default read-only flag.


ModeFlags

public ModeFlags(long flags)
          throws InvalidValueException
Construct a new ModeFlags object with the specified flags

Parameters:
flags - The flags to use for this object
Throws:
InvalidValueException - If the modes are invalid
Method Detail

toJavaModeString

public java.lang.String toJavaModeString()
Produce a Java IO mode string from the flags in this object.

Returns:
A Java string suitable for opening files with RandomAccessFile

isReadOnly

public boolean isReadOnly()
Whether the flags specify"read only".

Returns:
true if read-only, false otherwise

isReadable

public boolean isReadable()
Whether the flags specify "readable", either read/write or read-only.

Returns:
true if readable, false otherwise

isBinary

public boolean isBinary()
Whether the flags specify "binary" mode for reads and writes.

Returns:
true if binary mode, false otherwise

isCreate

public boolean isCreate()
Whether the flags specify to create nonexisting files.

Returns:
true if nonexisting files should be created, false otherwise

isWritable

public boolean isWritable()
Whether the flags specify "writable", either read/write or write-only

Returns:
true if writable, false otherwise

isExclusive

public boolean isExclusive()
Whether the flags specify exclusive access.

Returns:
true if exclusive, false otherwise

isAppendable

public boolean isAppendable()
Whether the flags specify to append to existing files.

Returns:
true if append, false otherwise

isTruncate

public boolean isTruncate()
Whether the flags specify to truncate the target file.

Returns:
true if truncate, false otherwise

isSubsetOf

public boolean isSubsetOf(ModeFlags superset)
Check whether the target set of flags is a superset of this one; used to ensure that a file is not re-opened with more privileges than it already had.

Parameters:
superset - The ModeFlags object which should be a superset of this one
Returns:
true if the object is a superset, false otherwise

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getOpenFileFlags

public int getOpenFileFlags()
Convert the flags in this object to a set of flags appropriate for the OpenFile structure and logic therein.

Returns:
an int of flags appropriate for OpenFile


Copyright © 2002-2007 JRuby Team. All Rights Reserved.