Top Description Inners Fields Constructors Methods
com.badlogic.gdx.jnigen

public Class FileDescriptor

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .File, .FileInputStream, .FileNotFoundException, .FileOutputStream, .IOException, .InputStream, .InputStreamReader, .OutputStream, .OutputStreamWriter, .Reader, .UnsupportedEncodingException, .Writer

Represents a file or directory on the filesystem or classpath. Taken from libgdx's FileHandle.
Authors
mzechner, Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
FileDescriptor.FileType

Indicates how to resolve a path to a file.

Field Summary

Modifier and TypeField and Description
protected File
protected FileDescriptor.FileType

Constructor Summary

AccessConstructor and Description
protected
public
FileDescriptor(String
the filename.
fileName
)

Creates a new absolute FileHandle for the file name.

public
FileDescriptor(File
the file.
file
)

Creates a new absolute FileHandle for the File.

protected
protected

Method Summary

Modifier and TypeMethod and Description
public FileDescriptor
child(String name)

Returns a handle to the child with the specified name.

private static void
private static void
public void
copyTo(FileDescriptor dest)

Copies this file or directory to the specified file or directory.

public boolean
delete()

Deletes this file or empty directory and returns success.

public boolean
deleteDirectory()

Deletes this file or directory and all children, recursively.

private static boolean
public boolean
exists()

Returns true if the file exists.

public String
public File
file()

Returns a java.io.File that represents this file handle.

public boolean
isDirectory()

Returns true if this file is a directory.

public long
lastModified()

Returns the last modified time in milliseconds for this file.

public long
length()

Returns the length in bytes of this file, or 0 if this file is a directory, does not exist, or the size cannot otherwise be determined.

public FileDescriptor[]
list()

Returns the paths to the children of this directory.

public FileDescriptor[]
list(String suffix)

Returns the paths to the children of this directory with the specified suffix.

public boolean
public void
moveTo(FileDescriptor dest)

Moves this file to the specified file, overwriting the file if it already exists.

public String
name()

public String
public FileDescriptor
public String
path()

public InputStream
read()

Returns a stream for reading this file as bytes.

public byte[]
readBytes()

Reads the entire file into a byte array.

public int

Returns:

the number of read bytes
readBytes
(byte[]
the array to load the file into
bytes
,
int
the offset to start writing bytes
offset
,
int
the number of bytes to read, see length()
size
)

Reads the entire file into the byte array.

public Reader
reader()

Returns a reader for reading this file as characters.

public Reader
reader(String charset)

Returns a reader for reading this file as characters.

public BufferedReader
reader(int bufferSize)

Returns a buffered reader for reading this file as characters.

public BufferedReader
reader(int bufferSize, String charset)

Returns a buffered reader for reading this file as characters.

public String
readString()

Reads the entire file into a string using the platform's default charset.

public String
readString(String charset)

Reads the entire file into a string using the specified charset.

public static FileDescriptor
public static FileDescriptor
tempFile(String prefix)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public FileDescriptor.FileType
type()

public OutputStream
write(boolean
If false, this file will be overwritten if it exists, otherwise it will be appended.
append
)

Returns a stream for writing to this file.

public void
write(InputStream input, boolean
If false, this file will be overwritten if it exists, otherwise it will be appended.
append
)

Reads the remaining bytes from the specified stream and writes them to this file.

public void
writeBytes(byte[] bytes, boolean
If false, this file will be overwritten if it exists, otherwise it will be appended.
append
)

Writes the specified bytes to the file.

public Writer
writer(boolean
If false, this file will be overwritten if it exists, otherwise it will be appended.
append
)

Returns a writer for writing to this file using the default charset.

public Writer
writer(boolean
If false, this file will be overwritten if it exists, otherwise it will be appended.
append
,
String
May be null to use the default charset.
charset
)

Returns a writer for writing to this file.

public void
writeString(String string, boolean
If false, this file will be overwritten if it exists, otherwise it will be appended.
append
)

Writes the specified string to the file using the default charset.

public void
writeString(String string, boolean
If false, this file will be overwritten if it exists, otherwise it will be appended.
append
,
String
May be null to use the default charset.
charset
)

Writes the specified string to the file as UTF-8.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

fileback to summary
protected File file
typeback to summary
protected FileDescriptor.FileType type

Constructor Detail

FileDescriptorback to summary
protected FileDescriptor()
FileDescriptorback to summary
public FileDescriptor(String fileName)

Creates a new absolute FileHandle for the file name. Use this for tools on the desktop that don't need any of the backends. Do not use this constructor in case you write something cross-platform. Use the Files interface instead.

Parameters
fileName:String

the filename.

FileDescriptorback to summary
public FileDescriptor(File file)

Creates a new absolute FileHandle for the File. Use this for tools on the desktop that don't need any of the backends. Do not use this constructor in case you write something cross-platform. Use the Files interface instead.

Parameters
file:File

the file.

FileDescriptorback to summary
protected FileDescriptor(String fileName, FileDescriptor.FileType type)
FileDescriptorback to summary
protected FileDescriptor(File file, FileDescriptor.FileType type)

Method Detail

childback to summary
public FileDescriptor child(String name)

Returns a handle to the child with the specified name.

Exceptions
RuntimeException:
if this file handle is a FileType#Classpath or FileType#Internal and the child doesn't exist.
copyDirectoryback to summary
private static void copyDirectory(FileDescriptor sourceDir, FileDescriptor destDir)
copyFileback to summary
private static void copyFile(FileDescriptor source, FileDescriptor dest)
copyToback to summary
public void copyTo(FileDescriptor dest)

Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination doesn't exist, mkdirs() is called on the destination's parent and this file is copied into it with a new name. If this handle is a directory, then 1) if the destination is a file, RuntimeException is thrown, or 2) if the destination is a directory, this directory is copied recursively into it as a subdirectory, overwriting existing files, or 3) if the destination doesn't exist, mkdirs() is called on the destination and this directory is copied recursively into it as a subdirectory.

Exceptions
RuntimeException:
if the destination file handle is a FileType#Classpath or FileType#Internal file, or copying failed.
deleteback to summary
public boolean delete()

Deletes this file or empty directory and returns success. Will not delete a directory that has children.

Exceptions
RuntimeException:
if this file handle is a FileType#Classpath or FileType#Internal file.
deleteDirectoryback to summary
public boolean deleteDirectory()

Deletes this file or directory and all children, recursively.

Exceptions
RuntimeException:
if this file handle is a FileType#Classpath or FileType#Internal file.
deleteDirectoryback to summary
private static boolean deleteDirectory(File file)
existsback to summary
public boolean exists()

Returns true if the file exists. On Android, a FileType#Classpath or FileType#Internal handle to a directory will always return false.

extensionback to summary
public String extension()
fileback to summary
public File file()

Returns a java.io.File that represents this file handle. Note the returned file will only be usable for FileType#Absolute and FileType#External file handles.

isDirectoryback to summary
public boolean isDirectory()

Returns true if this file is a directory. Always returns false for classpath files. On Android, an FileType#Internal handle to an empty directory will return false. On the desktop, an FileType#Internal handle to a directory on the classpath will return false.

lastModifiedback to summary
public long lastModified()

Returns the last modified time in milliseconds for this file. Zero is returned if the file doesn't exist. Zero is returned for FileType#Classpath files. On Android, zero is returned for FileType#Internal files. On the desktop, zero is returned for FileType#Internal files on the classpath.

lengthback to summary
public long length()

Returns the length in bytes of this file, or 0 if this file is a directory, does not exist, or the size cannot otherwise be determined.

listback to summary
public FileDescriptor[] list()

Returns the paths to the children of this directory. Returns an empty list if this file handle represents a file and not a directory. On the desktop, an FileType#Internal handle to a directory on the classpath will return a zero length array.

Exceptions
RuntimeException:
if this file is an FileType#Classpath file.
listback to summary
public FileDescriptor[] list(String suffix)

Returns the paths to the children of this directory with the specified suffix. Returns an empty list if this file handle represents a file and not a directory. On the desktop, an FileType#Internal handle to a directory on the classpath will return a zero length array.

Exceptions
RuntimeException:
if this file is an FileType#Classpath file.
mkdirsback to summary
public boolean mkdirs()
Exceptions
RuntimeException:
if this file handle is a FileType#Classpath or FileType#Internal file.
moveToback to summary
public void moveTo(FileDescriptor dest)

Moves this file to the specified file, overwriting the file if it already exists.

Exceptions
RuntimeException:
if the source or destination file handle is a FileType#Classpath or FileType#Internal file.
nameback to summary
public String name()
nameWithoutExtensionback to summary
public String nameWithoutExtension()
parentback to summary
public FileDescriptor parent()
pathback to summary
public String path()
readback to summary
public InputStream read()

Returns a stream for reading this file as bytes.

Exceptions
RuntimeException:
if the file handle represents a directory, doesn't exist, or could not be read.
readBytesback to summary
public byte[] readBytes()

Reads the entire file into a byte array.

Exceptions
RuntimeException:
if the file handle represents a directory, doesn't exist, or could not be read.
readBytesback to summary
public int readBytes(byte[] bytes, int offset, int size)

Reads the entire file into the byte array. The byte array must be big enough to hold the file's data.

Parameters
bytes:byte[]

the array to load the file into

offset:int

the offset to start writing bytes

size:int

the number of bytes to read, see length()

Returns:int

the number of read bytes

readerback to summary
public Reader reader()

Returns a reader for reading this file as characters.

Exceptions
RuntimeException:
if the file handle represents a directory, doesn't exist, or could not be read.
readerback to summary
public Reader reader(String charset)

Returns a reader for reading this file as characters.

Exceptions
RuntimeException:
if the file handle represents a directory, doesn't exist, or could not be read.
readerback to summary
public BufferedReader reader(int bufferSize)

Returns a buffered reader for reading this file as characters.

Exceptions
RuntimeException:
if the file handle represents a directory, doesn't exist, or could not be read.
readerback to summary
public BufferedReader reader(int bufferSize, String charset)

Returns a buffered reader for reading this file as characters.

Exceptions
RuntimeException:
if the file handle represents a directory, doesn't exist, or could not be read.
readStringback to summary
public String readString()

Reads the entire file into a string using the platform's default charset.

Exceptions
RuntimeException:
if the file handle represents a directory, doesn't exist, or could not be read.
readStringback to summary
public String readString(String charset)

Reads the entire file into a string using the specified charset.

Exceptions
RuntimeException:
if the file handle represents a directory, doesn't exist, or could not be read.
tempDirectoryback to summary
public static FileDescriptor tempDirectory(String prefix)
tempFileback to summary
public static FileDescriptor tempFile(String prefix)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

typeback to summary
public FileDescriptor.FileType type()
writeback to summary
public OutputStream write(boolean append)

Returns a stream for writing to this file. Parent directories will be created if necessary.

Parameters
append:boolean

If false, this file will be overwritten if it exists, otherwise it will be appended.

Exceptions
RuntimeException:
if this file handle represents a directory, if it is a FileType#Classpath or FileType#Internal file, or if it could not be written.
writeback to summary
public void write(InputStream input, boolean append)

Reads the remaining bytes from the specified stream and writes them to this file. The stream is closed. Parent directories will be created if necessary.

Parameters
append:boolean

If false, this file will be overwritten if it exists, otherwise it will be appended.

Exceptions
RuntimeException:
if this file handle represents a directory, if it is a FileType#Classpath or FileType#Internal file, or if it could not be written.
writeBytesback to summary
public void writeBytes(byte[] bytes, boolean append)

Writes the specified bytes to the file. Parent directories will be created if necessary.

Parameters
append:boolean

If false, this file will be overwritten if it exists, otherwise it will be appended.

Exceptions
RuntimeException:
if this file handle represents a directory, if it is a FileType#Classpath or FileType#Internal file, or if it could not be written.
writerback to summary
public Writer writer(boolean append)

Returns a writer for writing to this file using the default charset. Parent directories will be created if necessary.

Parameters
append:boolean

If false, this file will be overwritten if it exists, otherwise it will be appended.

Exceptions
RuntimeException:
if this file handle represents a directory, if it is a FileType#Classpath or FileType#Internal file, or if it could not be written.
writerback to summary
public Writer writer(boolean append, String charset)

Returns a writer for writing to this file. Parent directories will be created if necessary.

Parameters
append:boolean

If false, this file will be overwritten if it exists, otherwise it will be appended.

charset:String

May be null to use the default charset.

Exceptions
RuntimeException:
if this file handle represents a directory, if it is a FileType#Classpath or FileType#Internal file, or if it could not be written.
writeStringback to summary
public void writeString(String string, boolean append)

Writes the specified string to the file using the default charset. Parent directories will be created if necessary.

Parameters
append:boolean

If false, this file will be overwritten if it exists, otherwise it will be appended.

Exceptions
RuntimeException:
if this file handle represents a directory, if it is a FileType#Classpath or FileType#Internal file, or if it could not be written.
writeStringback to summary
public void writeString(String string, boolean append, String charset)

Writes the specified string to the file as UTF-8. Parent directories will be created if necessary.

Parameters
append:boolean

If false, this file will be overwritten if it exists, otherwise it will be appended.

charset:String

May be null to use the default charset.

Exceptions
RuntimeException:
if this file handle represents a directory, if it is a FileType#Classpath or FileType#Internal file, or if it could not be written.
com.badlogic.gdx.jnigen back to summary

public final Enum FileDescriptor.FileType

extends Enum<FileDescriptor.FileType>
Class Inheritance

Indicates how to resolve a path to a file.
Authors
mzechner, Nathan Sweet

Field Summary

Modifier and TypeField and Description
public static final FileDescriptor.FileType
Absolute

Path that is a fully qualified, absolute filesystem path.

public static final FileDescriptor.FileType
Classpath

Path relative to the root of the classpath.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static FileDescriptor.FileType
public static FileDescriptor.FileType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

Absoluteback to summary
public static final FileDescriptor.FileType Absolute

Path that is a fully qualified, absolute filesystem path. To ensure portability across platforms use absolute files only when absolutely (heh) necessary.

Classpathback to summary
public static final FileDescriptor.FileType Classpath

Path relative to the root of the classpath. Classpath files are always readonly. Note that classpath files are not compatible with some functionality on Android, such as Audio#newSound(FileHandle) and Audio#newMusic(FileHandle).

Constructor Detail

FileTypeback to summary
private FileType()

Method Detail

valueOfback to summary
public static FileDescriptor.FileType valueOf(String name)
valuesback to summary
public static FileDescriptor.FileType[] values()