Top Description Fields Constructors Methods
org.jruby

public Class RubyFile

extends RubyIO
implements EncodingCapable
Class Inheritance
All Implemented Interfaces
org.jruby.runtime.encoding.EncodingCapable
Annotations
@JRubyClass
name:File
parent:IO
include:FileTest
Imports
jnr.constants.platform.OpenFlags, jnr.posix.POSIX, jnr.posix.util.Platform, org.jcodings.Encoding, org.jcodings.specific.ASCIIEncoding, .UTF8Encoding, org.jruby.anno.JRubyClass, .JRubyMethod, org.jruby.api.API, org.jruby.exceptions.NotImplementedError, org.jruby.ir.runtime.IRRuntimeHelpers, org.jruby.runtime.*, .JavaSites.FileSites, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.encoding.EncodingCapable, org.jruby.util.*, org.jruby.util.io.EncodingUtils, .IOEncodable, .ModeFlags, .OpenFile, .PosixShim, java.io.File, .IOException, .InputStream, .Reader, java.net.MalformedURLException, .URI, .URL, java.nio.channels.Channels, .FileChannel, java.nio.charset.StandardCharsets, java.nio.file.*, java.nio.file.attribute.FileTime, .PosixFileAttributeView, java.util.ArrayList, .Enumeration, .List, java.util.jar.JarFile, java.util.regex.Matcher, .Pattern, java.util.zip.ZipEntry, .ZipFile

The Ruby File class.

Field Summary

Modifier and TypeField and Description
pack-priv static final ByteList
private static final byte[]
private static final int
private static final int
private static final int
private static final int
private static final int
private static final int
public static final int
public static final int
public static final int
public static final int
private static final int
protected String
path

Deprecated
pack-priv static final Pattern
private static final Pattern
private static final Pattern
private static final long
pack-priv static final ByteList
private static final String[]
private static final Pattern
private static final String
Inherited from org.jruby.RubyIO:
ALL_SPAWN_OPTIONSCLOSED_STREAM_MSGFD_CLOEXECopenFilePARAGRAPH_SEPARATORpopenSpecialUNSUPPORTED_SPAWN_OPTIONS

Constructor Summary

AccessConstructor and Description
public
RubyFile(Ruby runtime, RubyClass type)

pack-priv
RubyFile(Ruby runtime, String path, final Reader reader)

public
RubyFile(Ruby runtime, String path, InputStream in)

public
RubyFile(Ruby runtime, String path, FileChannel channel)

Method Summary

Modifier and TypeMethod and Description
public static IRubyObject
absolute_path(ThreadContext context, IRubyObject recv, IRubyObject path)

Converts a pathname to an absolute pathname.

public static IRubyObject
absolute_path(ThreadContext context, IRubyObject recv, IRubyObject path, IRubyObject dir)

Converts a pathname to an absolute pathname.

public static IRubyObject
absolute_path(ThreadContext context, IRubyObject recv, IRubyObject[] args)
Deprecated

public static IRubyObject
private static String
pack-priv static String
private static StringBuilder
appendSlash(final CharSequence canonicalPath)

public IRubyObject
public static IRubyObject
atime(ThreadContext context, IRubyObject recv, IRubyObject filename)

public static RubyString
public static RubyString
public static IRubyObject
basename(ThreadContext context, IRubyObject recv, IRubyObject[] args)
Deprecated

private static RubyString
public IRubyObject
public static IRubyObject
public static String
private static CharSequence
canonicalize(CharSequence canonicalPath, String remaining)

private static String
private static String
private void
private static RubyString
checkHome(ThreadContext context)

Check if HOME environment variable is not nil nor empty

public IRubyObject
public static IRubyObject
chmod(ThreadContext context, IRubyObject recv, IRubyObject[] args)

private static int
chomp(final StringBuilder buffer)

public IRubyObject
public static IRubyObject
chown(ThreadContext context, IRubyObject recv, IRubyObject[] args)

private static String
private static long[]
convertTimespecToTimeval(long[] timespec)

Converts a timespec (array of 2 longs: seconds and nanoseconds from epoch) into a timeval (array of 2 longs: seconds and microseconds from epoch).

private static String
countSlashes(String stringToCheck)

Returns a string consisting of n-1 slashes, where n is the number of slashes at the beginning of the input string.

public static RubyClass
public IRubyObject
public static IRubyObject
ctime(ThreadContext context, IRubyObject recv, IRubyObject filename)

public static IRubyObject
private static boolean
dir_fnmatch(ByteList pattern, ByteList path, int flags)

public static IRubyObject
public static IRubyObject
public static String
dirname(ThreadContext context, final String filename)

public static String
dirname(ThreadContext context, final String filename, int level)

public static IRubyObject
dirname(ThreadContext context, IRubyObject recv, IRubyObject[] args)
Deprecated

private static RubyString
dirnameCommon(ThreadContext context, RubyString filename, int level)

private static RubyString
public static IRubyObject

Returns:

Resulting absolute path as a String
expand_path
(ThreadContext context, IRubyObject recv, IRubyObject path)

Converts a pathname to an absolute pathname.

public static IRubyObject

Returns:

Resulting absolute path as a String
expand_path
(ThreadContext context, IRubyObject recv, IRubyObject path, IRubyObject wd)

Converts a pathname to an absolute pathname.

public static IRubyObject
expand_path(ThreadContext context, IRubyObject recv, IRubyObject... args)
Deprecated

public static String
expandPath(ThreadContext context, String relativePath, Encoding[] enc, String cwd, boolean expandUser, boolean canonicalize)

private static RubyString
expandPathInternal(ThreadContext context, IRubyObject arg0, boolean expandUser, boolean canonicalize)

private static RubyString
expandPathInternal(ThreadContext context, IRubyObject _path, IRubyObject _wd, boolean expandUser, boolean canonicalize)

pack-priv static RubyString
expandPathInternal(ThreadContext context, RubyString path, RubyString wd, boolean expandUser, boolean canonicalize)

private static RubyString
expandPathInternal(ThreadContext context, IRubyObject[] args, boolean expandUser, boolean canonicalize)
Deprecated

public static String

Returns:

Expanded path
expandUserPath
(ThreadContext context, String
Path to check
path
)

This method checks a path, and if it starts with ~, then it expands the path to the absolute path of the user's home directory.

public static String
expandUserPath(ThreadContext context, String path, final boolean raiseOnRelativePath)

public static IRubyObject

Returns:

Extension, including the dot, or an empty string
extname
(ThreadContext context, IRubyObject recv, IRubyObject
Path to get extension name of
arg
)

Returns the extension name of the file.

private static long[]
extractTimespec(ThreadContext context, IRubyObject value)

Extract a timespec (an array of 2 longs: seconds and nanoseconds from epoch) from an IRubyObject.

public static JRubyFile
file(IRubyObject pathOrFile)
Deprecated

public IRubyObject
fileOpenGeneric(ThreadContext context, IRubyObject filename, int oflags, int fmode, IOEncodable convConfig, int perm)

protected static RubyString
public static FileResource
fileResource(ThreadContext
current thread context
context
,
IRubyObject
the string or IO to use for the path
pathOrFile
)

Get the fully-qualified JRubyFile object for the path, taking into account the runtime's current directory.

public static FileResource
fileResource(IRubyObject
the string or IO to use for the path
pathOrFile
)
Deprecated since 9.4-.

Get the fully-qualified JRubyFile object for the path, taking into account the runtime's current directory.

public IRubyObject
flock(ThreadContext context, IRubyObject operation)

public static IRubyObject
fnmatch(ThreadContext context, IRubyObject recv, IRubyObject _pattern, IRubyObject _path)

Returns true if path matches against pattern The pattern is not a regular expression; instead it follows rules similar to shell filename globbing.

public static IRubyObject
fnmatch(ThreadContext context, IRubyObject recv, IRubyObject _pattern, IRubyObject _path, IRubyObject _flags)

public static IRubyObject
fnmatch(ThreadContext context, IRubyObject recv, IRubyObject[] args)
Deprecated

private static RubyBoolean
fnmatchCommon(ThreadContext context, IRubyObject _path, IRubyObject _pattern, int flags)

public static IRubyObject
ftype(ThreadContext context, IRubyObject recv, IRubyObject filename)

public static RubyString
public static String
public static String
getAdjustedPath(ThreadContext context, IRubyObject fileOrPath, String currentDirectory)

private static int
public static final FileTime
private static String
public static ZipEntry
getDirOrFileEntry(String jar, String path)
Deprecated

public static ZipEntry
getDirOrFileEntry(ZipFile jar, String path)
Deprecated

public Encoding
private static ZipEntry
getFileEntry(ZipFile jar, String path, final String prefixForNoEntry)

private static String
private static int
pack-priv final long
public IRubyObject
initialize(ThreadContext context, IRubyObject[] args, Block block)

public RubyString
inspect(ThreadContext context)

Overrides org.jruby.RubyIO.inspect.

Overrides default org.jruby.runtime.builtin.IRubyObject.inspect.

Returns a string containing a human-readable representation of obj.

private static boolean
private static boolean
private static boolean
private static boolean
isLocalURI(String canonicalPathString)

private static boolean
public static RubyString
join(ThreadContext context, IRubyObject recv, IRubyObject[] args)

private static boolean
joinImpl(final StringBuilder buffer, final String separator, ThreadContext context, IRubyObject recv, RubyArray<T extends IRubyObject> args)

private static StringBuilder
joinImplInspecting(final String separator, ThreadContext context, IRubyObject recv, RubyArray<T extends IRubyObject> parent, RubyArray<T extends IRubyObject> array)

public static IRubyObject
public static IRubyObject
public IRubyObject
public static IRubyObject
lstat(ThreadContext context, IRubyObject recv, IRubyObject filename)

public static IRubyObject
public static IRubyObject
public static IRubyObject
public static IRubyObject
mkfifo(ThreadContext context, RubyString path, int mode)

public IRubyObject
public static IRubyObject
mtime(ThreadContext context, IRubyObject recv, IRubyObject filename)

protected IRubyObject
public static IRubyObject
public IRubyObject
protected IRubyObject
public static IRubyObject
public static IRubyObject
public static IRubyObject
realdirpath(ThreadContext context, IRubyObject recv, IRubyObject[] args)
Deprecated

public static IRubyObject
public static IRubyObject
public static IRubyObject
realpath(ThreadContext context, IRubyObject recv, IRubyObject[] args)
Deprecated

private static RubyString
public static IRubyObject
rename(ThreadContext context, IRubyObject recv, IRubyObject oldName, IRubyObject newName)

private static String
replace(final String str, CharSequence target, CharSequence replace)

public void
private static JavaSites.FileSites
sites(ThreadContext context)

Hides org.jruby.RubyIO.sites.

Retrieve the call sites for this class.

public IRubyObject
public static RubyArray<T extends IRubyObject>
public static String[]
public static boolean
pack-priv static boolean
public static IRubyObject
stat(ThreadContext context, IRubyObject recv, IRubyObject filename)

public <T> T
toJava(Class<T>
The target type to which the object should be converted.
target
)

Overrides org.jruby.RubyIO.toJava.

Implements org.jruby.runtime.builtin.IRubyObject.toJava.

Convert the object to the specified Java class, if possible.

public String
toString()

Overrides org.jruby.RubyIO.toString.

The default toString method is just a wrapper that calls the Ruby "to_s" method.

public IRubyObject
public static IRubyObject
public static IRubyObject
truncate19(ThreadContext context, IRubyObject recv, IRubyObject path, IRubyObject length)
Deprecated

private static IRubyObject
public static IRubyObject
umask(ThreadContext context, IRubyObject recv, IRubyObject[] args)

public static IRubyObject
utime(ThreadContext context, IRubyObject recv, IRubyObject[] args)

Inherited from org.jruby.RubyIO:
addBlockingThreadadviceArgCheckadviseautocloseautoclose_setbinmodebinmodebinreadbinwritebytescharscheckExecEnvcheckExecOptionscheckLengthcheckPopenOptionscheckSpawnOptionscheckUnsupportedOptionscheckValidSpawnOptionscloexecOpenclosecloseclose_on_exec_pclose_on_exec_setclose_readclose_writeclosed_pcodepointsconvertToIOcopy_streamcopy_streamcopy_streamcreateIOClassdoReaddoReadNonblockdoReadNonblockdoReadNonblockdoReadNonblockdoWriteNonblockeacheacheacheacheacheach_byteeach_byteInternaleach_chareach_charInternaleach_codepointeach_lineeach_lineeach_lineeach_lineeach_lineensureYieldCloseensureYieldClosePipeseof_pexternal_encodingfailIfDirectoryfcntlfcntlfilenoflushflushflushRawfor_fdforeachfsyncgetBlockinggetBOMgetbytegetBytegetcgetcgetChannelgetEcflagsgetEcoptsgetEncgetEnc2getInputEncodinggetInStreamgetIOModesgetIOModesIntFromStringgetlinegetlinegetlinegetlinegetlinegetlinegetlineImplgetNativeClassIndexgetOpenFilegetOpenFileCheckedgetOpenFileInitializedgetOutStreamgetPartialgetPartialgetPartialgetPartialgetPartialgetPathgetReadEncodinggetsgetsgetsgetsgetSyncGetWriteIOinitializeinitializeinitializeinitialize_copyinternal_encodingioCloseioctlioOpenioOpenioOpenioStaticWriteisAutocloseisClosedlinenolineno_setlinesMakeOpenFilenewInstancenewIOnewIOOptionsnewIOOptionsnewIOOptionsnewIOOptionsnewIOOptionsnewModeFlagsnewModeFlagsnewModeFlagsnonblockEOFobliterateProcessop_appendop_binmodeopenparseIOOptionspidpipepipepipepipepipepipepopenpopen3popen4popenSpecialpospos_setpreadpreadprepStdioprepStdioprintprintprintprintprintprintprint0print1print2print3printfprintfputcputcputsputsputsputsputsputsputs0puts1puts2puts3pwritereadreadreadreadreadreadreadreadread_nonblockread_nonblockread_nonblockread_nonblockreadbytereadcharreadcharreadlinereadlinereadlinereadlinereadlinereadlinesreadlinesreadlinesreadlinesreadlinesreadlinesreadpartialreadpartialreadpartialremoveBlockingThreadreopenreopenIOrewindseekseekseekseekBeforeAccessselectselect_staticset_encodingset_encodingset_encodingset_encoding_by_bomsetAscii8bitBinmodesetAutoclosesetBlockingsetBOMsetEcflagssetEcoptssetEncsetEnc2setEncodingsetPathsetSyncstatsyncsync_setsync_setsysopensysopensysopensysreadsysreadsysreadsysseeksyswriteto_iotryConverttty_pungetbyteungetcupdateIOOptionsFromOptionswaitwaitwait_readablewait_readablewait_writablewait_writablewritewritewritewritewritewritewritewritewritewritewritewritewritewritewritewritewrite2write3write_nonblockwrite_nonblockwrite_nonblockwriteStaticwritevwritevwritevwritevwritev