Top Description Fields Constructors Methods
org.jruby.util.io

public Class ModeFlags

extends Object
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Imports
com.sun.nio.file.ExtendedOpenOption, jnr.constants.platform.Fcntl, .OpenFlags, jnr.posix.POSIX, org.jruby.Ruby, org.jruby.platform.Platform, java.nio.channels.Channel, .FileChannel, .ReadableByteChannel, .WritableByteChannel, java.nio.file.OpenOption, .StandardOpenOption

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.

Note

In MRI these are called oflags.

See Also
org.jruby.util.io.OpenFile

Field Summary

Modifier and TypeField and Description
public static final int
ACCMODE

accmode flag, used to mask the read/write mode

public static final int
APPEND

append flag, to seek to the end of the file

public static final int
BINARY

binary flag, to ensure no encoding changes are made while writing (Windows only)

public static final int
CREAT

create flag, to specify non-existing file should be created

public static final int
EXCL

exclusive access flag, to require locking the target file

private final int
flags

the set of flags for this ModeFlags instance

public static final int
NONBLOCK

nonblock flag, to perform all operations non-blocking.

public static final OpenOption
NOSHARE_DELETE

try to access special mode flag, failover to default SHARE_DELETE otherwise

private OpenOption[]
openOptions

a cached array of OpenOption equivalent to these mode flags

public static final int
RDONLY

read-only flag (default value if no other flags set)

public static final int
RDWR

read/write flag

public static final int
SHARE_DELETE

delete shared file flag for windows, otherwise zero

public static final int
TEXT

textmode flag, MRI has no equivalent but we use ModeFlags currently to also capture what are oflags.

public static final int
TMPFILE

tmpfile flag (Linux only)

public static final int
TRUNC

truncate flag, to truncate the target file to zero length

public static final int
WRONLY

write-only flag

Constructor Summary

AccessConstructor and Description
public
ModeFlags()

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

public
ModeFlags(long
The flags to use for this object
flags
)

Construct a new ModeFlags object with the specified flags

public
ModeFlags(String flagString)

Method Summary

Modifier and TypeMethod and Description
public static ModeFlags
createModeFlags(int oflags)

public int

Returns:

an int of flags appropriate for fcntl
getFcntlFileFlags
()

Convert the flags in this object to a set of flags appropriate for the fcntl.

public int

Returns:

an int of the private flags variable.
getFlags
()

Return a value that, when passed to our constructor, would create a copy of this instance.

public static ModeFlags

Returns:

the mode flags
getModesFromChannel
(Channel
the channel to examine for capabilities
channel
)
Deprecated

Build a set of mode flags using the specified channel's actual capabilities.

public static int
public static int
getOFlagsFromString(Ruby runtime, String modesString)

public int

Returns:

an int of flags appropriate for OpenFile
getOpenFileFlags
()

Convert the flags in this object to a set of flags appropriate for the OpenFile structure and logic therein.

public static int
getOpenFileFlagsFor(int flags)

With the provided open flags parameter what fmode values should be set (fmode for us is represented by OpenFile).

public boolean

Returns:

true if append, false otherwise
isAppendable
()

Whether the flags specify to append to existing files.

public boolean

Returns:

true if binary mode, false otherwise
isBinary
()

Whether the flags specify "binary" mode for reads and writes.

public boolean

Returns:

true if nonexisting files should be created, false otherwise
isCreate
()

Whether the flags specify to create nonexisting files.

public boolean

Returns:

true if exclusive, false otherwise
isExclusive
()

Whether the flags specify exclusive access.

public boolean

Returns:

true if readable, false otherwise
isReadable
()

Whether the flags specify "readable", either read/write or read-only.

public final boolean

Returns:

true if read-only, false otherwise
isReadOnly
()

Whether the flags specify"read only".

public boolean

Returns:

true if read/write flag is set, false otherwise
isReadWrite
()

Whether the flags specify "read/write".

public boolean

Returns:

true if shared delete is allowed, false otherwise
isShareDelete
()

Whether the flags specify to allow deleting shared files (Windows FILE_SHARE_DELETE).

public boolean

Returns:

true if the object is a superset, false otherwise
isSubsetOf
(ModeFlags
The ModeFlags object which should be a superset of this one
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.

public boolean

Returns:

true if unnamed temporary mode, false otherwise
isTemporary
()

Whether the flags specify "unnamed temporary".

public boolean

Returns:

true if text mode, false otherwise
isText
()

Whether the flags specify "text" mode for reads and writes.

public boolean

Returns:

true if truncate, false otherwise
isTruncate
()

Whether the flags specify to truncate the target file.

public boolean

Returns:

true if writable, false otherwise
isWritable
()

Whether the flags specify "writable", either read/write or write-only

public boolean

Returns:

true if the write only flag is set, false otherwise
isWriteOnly
()

Whether the flags specify "write only".

public static int

Returns:

the mode flags
oflagsFrom
(POSIX posix, Channel
the channel to examine for capabilities
channel
)

Build a set of mode flags using the specified channel's actual capabilities.

public String

Returns:

A Java string suitable for opening files with RandomAccessFile
toJavaModeString
()

Produce a Java IO mode string from the flags in this object.

public OpenOption[]

Returns:

an array of OpenOption that matches these mode flags.
toOpenOptions
(boolean includeAppend, boolean
whether to include truncation in the options
includeTruncate
)

Produce an array of OpenOption equivalent to these mode flags, including TRUNCATE_EXISTING only if includeTruncate is set to true.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

ACCMODEback to summary
public static final int ACCMODE

accmode flag, used to mask the read/write mode

APPENDback to summary
public static final int APPEND

append flag, to seek to the end of the file

BINARYback to summary
public static final int BINARY

binary flag, to ensure no encoding changes are made while writing (Windows only)

CREATback to summary
public static final int CREAT

create flag, to specify non-existing file should be created

EXCLback to summary
public static final int EXCL

exclusive access flag, to require locking the target file

flagsback to summary
private final int flags

the set of flags for this ModeFlags instance

NONBLOCKback to summary
public static final int NONBLOCK

nonblock flag, to perform all operations non-blocking. Unused currently

NOSHARE_DELETEback to summary
public static final OpenOption NOSHARE_DELETE

try to access special mode flag, failover to default SHARE_DELETE otherwise

openOptionsback to summary
private OpenOption[] openOptions

a cached array of OpenOption equivalent to these mode flags

RDONLYback to summary
public static final int RDONLY

read-only flag (default value if no other flags set)

RDWRback to summary
public static final int RDWR

read/write flag

SHARE_DELETEback to summary
public static final int SHARE_DELETE

delete shared file flag for windows, otherwise zero

TEXTback to summary
public static final int TEXT

textmode flag, MRI has no equivalent but we use ModeFlags currently to also capture what are oflags.

TMPFILEback to summary
public static final int TMPFILE

tmpfile flag (Linux only)

TRUNCback to summary
public static final int TRUNC

truncate flag, to truncate the target file to zero length

WRONLYback to summary
public static final int WRONLY

write-only flag

Constructor Detail

ModeFlagsback to summary
public ModeFlags()

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

ModeFlagsback to summary
public ModeFlags(long flags) throws InvalidValueException

Construct a new ModeFlags object with the specified flags

Parameters
flags:long

The flags to use for this object

Exceptions
InvalidValueException:
If the modes are invalid
ModeFlagsback to summary
public ModeFlags(String flagString) throws InvalidValueException

Method Detail

createModeFlagsback to summary
public static ModeFlags createModeFlags(int oflags)
getFcntlFileFlagsback to summary
public int getFcntlFileFlags()

Convert the flags in this object to a set of flags appropriate for the fcntl.

Returns:int

an int of flags appropriate for fcntl

getFlagsback to summary
public int getFlags()

Return a value that, when passed to our constructor, would create a copy of this instance.

Returns:int

an int of the private flags variable.

getModesFromChannelback to summary
public static ModeFlags getModesFromChannel(Channel channel)

Deprecated

Build a set of mode flags using the specified channel's actual capabilities.

Parameters
channel:Channel

the channel to examine for capabilities

Returns:ModeFlags

the mode flags

Annotations
@Deprecated
getOFlagsFromStringback to summary
public static int getOFlagsFromString(String modesString) throws InvalidValueException
getOFlagsFromStringback to summary
public static int getOFlagsFromString(Ruby runtime, String modesString)
getOpenFileFlagsback to summary
public int getOpenFileFlags()

Convert the flags in this object to a set of flags appropriate for the OpenFile structure and logic therein.

Returns:int

an int of flags appropriate for OpenFile

getOpenFileFlagsForback to summary
public static int getOpenFileFlagsFor(int flags)

With the provided open flags parameter what fmode values should be set (fmode for us is represented by OpenFile).

isAppendableback to summary
public boolean isAppendable()

Whether the flags specify to append to existing files.

Returns:boolean

true if append, false otherwise

isBinaryback to summary
public boolean isBinary()

Whether the flags specify "binary" mode for reads and writes.

Returns:boolean

true if binary mode, false otherwise

isCreateback to summary
public boolean isCreate()

Whether the flags specify to create nonexisting files.

Returns:boolean

true if nonexisting files should be created, false otherwise

isExclusiveback to summary
public boolean isExclusive()

Whether the flags specify exclusive access.

Returns:boolean

true if exclusive, false otherwise

isReadableback to summary
public boolean isReadable()

Whether the flags specify "readable", either read/write or read-only.

Returns:boolean

true if readable, false otherwise

isReadOnlyback to summary
public final boolean isReadOnly()

Whether the flags specify"read only".

Returns:boolean

true if read-only, false otherwise

isReadWriteback to summary
public boolean isReadWrite()

Whether the flags specify "read/write".

Returns:boolean

true if read/write flag is set, false otherwise

isShareDeleteback to summary
public boolean isShareDelete()

Whether the flags specify to allow deleting shared files (Windows FILE_SHARE_DELETE).

Returns:boolean

true if shared delete is allowed, false otherwise

isSubsetOfback to summary
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:ModeFlags

The ModeFlags object which should be a superset of this one

Returns:boolean

true if the object is a superset, false otherwise

isTemporaryback to summary
public boolean isTemporary()

Whether the flags specify "unnamed temporary".

Returns:boolean

true if unnamed temporary mode, false otherwise

isTextback to summary
public boolean isText()

Whether the flags specify "text" mode for reads and writes.

Returns:boolean

true if text mode, false otherwise

isTruncateback to summary
public boolean isTruncate()

Whether the flags specify to truncate the target file.

Returns:boolean

true if truncate, false otherwise

isWritableback to summary
public boolean isWritable()

Whether the flags specify "writable", either read/write or write-only

Returns:boolean

true if writable, false otherwise

isWriteOnlyback to summary
public boolean isWriteOnly()

Whether the flags specify "write only".

Returns:boolean

true if the write only flag is set, false otherwise

oflagsFromback to summary
public static int oflagsFrom(POSIX posix, Channel channel)

Build a set of mode flags using the specified channel's actual capabilities.

Parameters
channel:Channel

the channel to examine for capabilities

Returns:int

the mode flags

toJavaModeStringback to summary
public String toJavaModeString()

Produce a Java IO mode string from the flags in this object.

Returns:String

A Java string suitable for opening files with RandomAccessFile

toOpenOptionsback to summary
public OpenOption[] toOpenOptions(boolean includeAppend, boolean includeTruncate)

Produce an array of OpenOption equivalent to these mode flags, including TRUNCATE_EXISTING only if includeTruncate is set to true. Set includeTruncate to false if you intend to truncate the file separately. The resulting array may be shared and should not be modified.

Parameters
includeTruncate:boolean

whether to include truncation in the options

Returns:OpenOption[]

an array of OpenOption that matches these mode flags.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override