Class SCMFile
SCMFileSystem.-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConstructs a child/descendantSCMFileinstance path relative from this object.children()If this object represents a directory, lists up all the immediate children.abstract InputStreamcontent()Reads the content of this file.byte[]A convenience method that reads the content and then turns it into a byte array.A convenience method that reads the content and then turns it into a string.Encoding of this file.Returns the MIME type of this file.final booleanexists()Returns true if this object represents something that exists.final StringgetName()Gets the file name of this file without any path portion, such as just "foo.txt"getPath()Gets the file name including the path portion, such as "foo/bar/manchu.txt".final SCMFile.TypegetType()The type of this object.booleanChecks if this file is a binary file.booleanThe opposite ofisContentBinary()final booleanReturns true if this object represents a directory.final booleanisFile()Returns true if this object represents a file.final booleanisRoot()Tests if this instance is the root of the filesystem.abstract longReturns the time that theSCMFilewas last modified.protected abstract SCMFileConstructs an immediate child with the supplied type hint.parent()Retrieves the parentSCMFileinstance.protected abstract SCMFile.Typetype()The type of this object.protected final voidtype(SCMFile.Type type) Proactively seeds the type information where that has been already obtained in a different request.
-
Constructor Details
-
SCMFile
protected SCMFile()Constructor for the root entry.- Since:
- 2.0
-
SCMFile
Constructor for any entry that is not the root.- Parameters:
parent- the parent reference ornullif this is the root object.name- the name of this entry (cannot contain '/').- Since:
- 2.0
-
-
Method Details
-
getName
Gets the file name of this file without any path portion, such as just "foo.txt"This method is the equivalent of
File.getName().- Returns:
- the file name of this file without any path portion.
-
getPath
Gets the file name including the path portion, such as "foo/bar/manchu.txt". Will never end in/.- Returns:
- the pathname of this file.
- Since:
- 2.0
-
isRoot
public final boolean isRoot()Tests if this instance is the root of the filesystem.- Returns:
trueif this instance is the root of the filesystem.- Since:
- 2.0
-
parent
Retrieves the parentSCMFileinstance.- Returns:
- the parent or
nullif this instance is the root already. - Since:
- 2.0
-
child
Constructs a child/descendantSCMFileinstance path relative from this object.- Parameters:
path- Relative path of the child to return.- Returns:
- The instance.
-
newChild
Constructs an immediate child with the supplied type hint.- Parameters:
name- the name of the immediate child, nevernull, never empty and never containing a/.assumeIsDirectory-trueif it this entry is being used as an intermediate in a multi-segment path and should thus be assumed to be a directory.- Returns:
- the instance.
- Since:
- 2.0.1
-
children
If this object represents a directory, lists up all the immediate children.This method is the equivalent of
File.listFiles().- Returns:
- Always non-null. If this method is not a directory, this method returns an empty iterable.
- Throws:
IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.
-
lastModified
Returns the time that theSCMFilewas last modified.- Returns:
- A
longvalue representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970) or0Lif the operation is unsupported. - Throws:
FileNotFoundException- if thisSCMFileinstance does not exist in the remote system (e.g. if you created a nonexistent instance viachild(String))IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.
-
exists
Returns true if this object represents something that exists.This method is the equivalent of
File.exists().NOTE: Typically to minimize round trips,
getType()would be preferred- Returns:
- true if this object represents something that exists.
- Throws:
IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.- See Also:
-
isFile
Returns true if this object represents a file.This method is the equivalent of
File.isFile().NOTE: Typically to minimize round trips,
getType()would be preferred- Returns:
- true if this object represents a file.
- Throws:
IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.- See Also:
-
isDirectory
Returns true if this object represents a directory.This method is the equivalent of
File.isDirectory().NOTE: Typically to minimize round trips,
getType()would be preferred- Returns:
- true if this object represents a directory.
- Throws:
IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.- See Also:
-
getType
The type of this object.- Returns:
- the
SCMFile.Typeof this object, specificallySCMFile.Type.NONEXISTENTif thisSCMFileinstance does not exist in the remote system (e.g. if you created a nonexistent instance viachild(String)) - Throws:
IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.
-
type
Proactively seeds the type information where that has been already obtained in a different request.- Parameters:
type- the type of this object.- Since:
- 2.0
-
type
The type of this object.- Returns:
- the
SCMFile.Typeof this object, specificallySCMFile.Type.NONEXISTENTif thisSCMFileinstance does not exist in the remote system (e.g. if you created a nonexistent instance viachild(String)) - Throws:
IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.- Since:
- 2.0
-
content
Reads the content of this file.- Returns:
- an open stream to read the file content. The caller must close the stream.
- Throws:
FileNotFoundException- if thisSCMFileinstance does not exist in the remote system (e.g. if you created a nonexistent instance viachild(String))IOException- if this object represents a directory or if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.
-
contentAsBytes
A convenience method that reads the content and then turns it into a byte array.- Returns:
- the file content as a byte array.
- Throws:
FileNotFoundException- if thisSCMFileinstance does not exist in the remote system (e.g. if you created a nonexistent instance viachild(String))IOException- if this object represents a directory or if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.
-
contentAsString
A convenience method that reads the content and then turns it into a string.- Returns:
- the file content as a string.
- Throws:
FileNotFoundException- if thisSCMFileinstance does not exist in the remote system (e.g. if you created a nonexistent instance viachild(String))IOException- if this object represents a directory or if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.
-
contentMimeType
Returns the MIME type of this file.The default implementation infers this based on the file name, but sophisticated server might provide this information from different sources, such as "svn:mime-type" in Subversion.
- Returns:
- the MIME type of this file.
- Throws:
FileNotFoundException- if thisSCMFileinstance does not exist in the remote system (e.g. if you created a nonexistent instance viachild(String))IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.
-
isContentBinary
Checks if this file is a binary file.What exactly is a binary file is up to the implementation. Some SCMs (such as Subversion) has a way of letting users mark files as binaries.
- Returns:
- true if this file is a binary file.
- Throws:
FileNotFoundException- if thisSCMFileinstance does not exist in the remote system (e.g. if you created a nonexistent instance viachild(String))IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.
-
isContentText
The opposite ofisContentBinary()- Returns:
- true if this file is not a binary file.
- Throws:
FileNotFoundException- if thisSCMFileinstance does not exist in the remote system (e.g. if you created a nonexistent instance viachild(String))IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.
-
contentEncoding
Encoding of this file.This is used to interpret text files.
Some SCM implementations allow users to mark content encoding of files, and this method may provide those. As a fallback, the default implementation returns the platform default encoding.
- Returns:
- the encoding of this file.
- Throws:
FileNotFoundException- if thisSCMFileinstance does not exist in the remote system (e.g. if you created a nonexistent instance viachild(String))IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.
-