Package com.yahoo.config.application.api
Class ApplicationFile
- java.lang.Object
-
- com.yahoo.config.application.api.ApplicationFile
-
- All Implemented Interfaces:
java.lang.Comparable<ApplicationFile>
public abstract class ApplicationFile extends java.lang.Object implements java.lang.Comparable<ApplicationFile>
An application file represents a file within an application package. This class can be used to traverse the entire application package file structure, as well as read and write files to it, and create directories.- Author:
- Ulf Lilleengen
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ApplicationFile.MetaData
static interface
ApplicationFile.PathFilter
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ContentStatusChanged
static java.lang.String
ContentStatusDeleted
static java.lang.String
ContentStatusNew
protected com.yahoo.path.Path
path
-
Constructor Summary
Constructors Modifier Constructor Description protected
ApplicationFile(com.yahoo.path.Path path)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract ApplicationFile
appendFile(java.lang.String value)
Appends the given string to this text file.abstract ApplicationFile
createDirectory()
Create a directory at the path represented by this file.abstract java.io.InputStream
createInputStream()
Create anInputStream
for the contents of this file.abstract java.io.Reader
createReader()
Create aReader
for the contents of this file.abstract ApplicationFile
delete()
Delete the file pointed to by this.boolean
equals(java.lang.Object other)
abstract boolean
exists()
Test whether or not this file exists.abstract ApplicationFile.MetaData
getMetaData()
protected com.yahoo.path.Path
getMetaPath()
com.yahoo.path.Path
getPath()
Get the path that this file represents.abstract boolean
isDirectory()
Check whether or not this file is a directory.java.util.List<ApplicationFile>
listFiles()
List the files under this directory.java.util.List<ApplicationFile>
listFiles(boolean recurse)
List the files in this directory, optionally list files for subdirectories recursively as well.abstract java.util.List<ApplicationFile>
listFiles(ApplicationFile.PathFilter filter)
List the files under this directory.java.lang.String
toString()
abstract ApplicationFile
writeFile(java.io.Reader input)
Write the contents from this reader to this file.
-
-
-
Field Detail
-
ContentStatusNew
public static final java.lang.String ContentStatusNew
- See Also:
- Constant Field Values
-
ContentStatusChanged
public static final java.lang.String ContentStatusChanged
- See Also:
- Constant Field Values
-
ContentStatusDeleted
public static final java.lang.String ContentStatusDeleted
- See Also:
- Constant Field Values
-
path
protected final com.yahoo.path.Path path
-
-
Method Detail
-
isDirectory
public abstract boolean isDirectory()
Check whether or not this file is a directory.- Returns:
- true if it is, false if not.
-
exists
public abstract boolean exists()
Test whether or not this file exists.- Returns:
- true if it exists, false if not.
-
createReader
public abstract java.io.Reader createReader() throws java.io.FileNotFoundException
Create aReader
for the contents of this file.- Returns:
- A
Reader
that should be closed after use. - Throws:
java.io.FileNotFoundException
- if the file is not found.
-
createInputStream
public abstract java.io.InputStream createInputStream() throws java.io.FileNotFoundException
Create anInputStream
for the contents of this file.- Returns:
- An
InputStream
that should be closed after use. - Throws:
java.io.FileNotFoundException
- if the file is not found.
-
createDirectory
public abstract ApplicationFile createDirectory()
Create a directory at the path represented by this file. Parent directories will be automatically created.- Returns:
- this
- Throws:
java.lang.IllegalArgumentException
- if the directory already exists.
-
writeFile
public abstract ApplicationFile writeFile(java.io.Reader input)
Write the contents from this reader to this file. Any existing content will be overwritten!- Parameters:
input
- A reader pointing to the content that should be written.- Returns:
- this
-
appendFile
public abstract ApplicationFile appendFile(java.lang.String value)
Appends the given string to this text file.- Returns:
- this
-
listFiles
public java.util.List<ApplicationFile> listFiles()
List the files under this directory. If this is file, an empty list is returned. Only immediate files/subdirectories are returned.- Returns:
- a list of files in this directory.
-
listFiles
public abstract java.util.List<ApplicationFile> listFiles(ApplicationFile.PathFilter filter)
List the files under this directory. If this is file, an empty list is returned. Only immediate files/subdirectories are returned.- Parameters:
filter
- A filter functor for filtering path names- Returns:
- a list of files in this directory.
-
listFiles
public java.util.List<ApplicationFile> listFiles(boolean recurse)
List the files in this directory, optionally list files for subdirectories recursively as well.- Parameters:
recurse
- Set to true if all files in the directory tree should be returned.- Returns:
- a list of files in this directory.
-
delete
public abstract ApplicationFile delete()
Delete the file pointed to by this. If it is a non-empty directory, the operation will throw.- Returns:
- this.
- Throws:
java.lang.RuntimeException
- if the file is a directory and not empty.
-
getPath
public com.yahoo.path.Path getPath()
Get the path that this file represents.- Returns:
- a Path
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
getMetaPath
protected com.yahoo.path.Path getMetaPath()
-
getMetaData
public abstract ApplicationFile.MetaData getMetaData()
-
-