public abstract class SCMFile extends Object
SCMFileSystem
.Modifier and Type | Class and Description |
---|---|
static class |
SCMFile.Type
Represents the type of a
SCMFile . |
Modifier | Constructor and Description |
---|---|
protected |
SCMFile()
Constructor for the root entry.
|
protected |
SCMFile(SCMFile parent,
String name)
Constructor for any entry that is not the root.
|
Modifier and Type | Method and Description |
---|---|
SCMFile |
child(String path)
Constructs a child/descendant
SCMFile instance path relative from this object. |
abstract Iterable<SCMFile> |
children()
If this object represents a directory, lists up all the immediate children.
|
abstract InputStream |
content()
Reads the content of this file.
|
byte[] |
contentAsBytes()
A convenience method that reads the content and then turns it into a byte array.
|
String |
contentAsString()
A convenience method that reads the content and then turns it into a string.
|
Charset |
contentEncoding()
Encoding of this file.
|
String |
contentMimeType()
Returns the MIME type of this file.
|
boolean |
exists()
Returns true if this object represents something that exists.
|
String |
getName()
Gets the file name of this file without any path portion, such as just "foo.txt"
|
String |
getPath()
Gets the file name including the path portion, such as "foo/bar/manchu.txt".
|
SCMFile.Type |
getType()
The type of this object.
|
boolean |
isContentBinary()
Checks if this file is a binary file.
|
boolean |
isContentText()
The opposite of
isContentBinary() |
boolean |
isDirectory()
Returns true if this object represents a directory.
|
boolean |
isFile()
Returns true if this object represents a file.
|
boolean |
isRoot()
Tests if this instance is the root of the filesystem.
|
abstract long |
lastModified()
Returns the time that the
SCMFile was last modified. |
protected abstract SCMFile |
newChild(String name,
boolean assumeIsDirectory)
Constructs an immediate child with the supplied type hint.
|
SCMFile |
parent()
Retrieves the parent
SCMFile instance. |
protected abstract SCMFile.Type |
type()
The type of this object.
|
protected void |
type(SCMFile.Type type)
Proactively seeds the type information where that has been already obtained in a different request.
|
@NonNull public final String getName()
This method is the equivalent of File.getName()
.
@NonNull public String getPath()
/
.public final boolean isRoot()
true
if this instance is the root of the filesystem.@CheckForNull public SCMFile parent()
SCMFile
instance.null
if this instance is the root already.@NonNull public SCMFile child(String path)
SCMFile
instance path relative from this object.path
- Relative path of the child to return.@NonNull protected abstract SCMFile newChild(@NonNull String name, boolean assumeIsDirectory)
name
- the name of the immediate child, never null
, never empty and never containing
a /
.assumeIsDirectory
- true
if it this entry is being used as an intermediate in a multi-segment path
and should thus be assumed to be a directory.@NonNull public abstract Iterable<SCMFile> children() throws IOException, InterruptedException
This method is the equivalent of File.listFiles()
.
IOException
- if an error occurs while performing the operation.InterruptedException
- if interrupted while performing the operation.public abstract long lastModified() throws IOException, InterruptedException
SCMFile
was last modified.long
value representing the time the file was last modified, measured in milliseconds
since the epoch (00:00:00 GMT, January 1, 1970) or 0L
if the operation is unsupported.FileNotFoundException
- if this SCMFile
instance does not exist in the remote system (e.g. if you
created a nonexistent instance via child(String)
)IOException
- if an error occurs while performing the operation.InterruptedException
- if interrupted while performing the operation.public final boolean exists() throws IOException, InterruptedException
This method is the equivalent of File.exists()
.
NOTE: Typically to minimize round trips, getType()
would be preferred
IOException
- if an error occurs while performing the operation.InterruptedException
- if interrupted while performing the operation.getType()
public final boolean isFile() throws IOException, InterruptedException
This method is the equivalent of File.isFile()
.
NOTE: Typically to minimize round trips, getType()
would be preferred
IOException
- if an error occurs while performing the operation.InterruptedException
- if interrupted while performing the operation.getType()
public final boolean isDirectory() throws IOException, InterruptedException
This method is the equivalent of File.isDirectory()
.
NOTE: Typically to minimize round trips, getType()
would be preferred
IOException
- if an error occurs while performing the operation.InterruptedException
- if interrupted while performing the operation.getType()
@NonNull public final SCMFile.Type getType() throws IOException, InterruptedException
SCMFile.Type
of this object, specifically SCMFile.Type.NONEXISTENT
if this SCMFile
instance
does not exist in the remote system (e.g. if you created a nonexistent instance via child(String)
)IOException
- if an error occurs while performing the operation.InterruptedException
- if interrupted while performing the operation.protected final void type(@NonNull SCMFile.Type type)
type
- the type of this object.@NonNull protected abstract SCMFile.Type type() throws IOException, InterruptedException
SCMFile.Type
of this object, specifically SCMFile.Type.NONEXISTENT
if this SCMFile
instance
does not exist in the remote system (e.g. if you created a nonexistent instance via child(String)
)IOException
- if an error occurs while performing the operation.InterruptedException
- if interrupted while performing the operation.@NonNull public abstract InputStream content() throws IOException, InterruptedException
FileNotFoundException
- if this SCMFile
instance does not exist in the remote system (e.g. if you
created a nonexistent instance via child(String)
)IOException
- if this object represents a directory or if an error occurs while performing the
operation.InterruptedException
- if interrupted while performing the operation.@NonNull public byte[] contentAsBytes() throws IOException, InterruptedException
FileNotFoundException
- if this SCMFile
instance does not exist in the remote system (e.g. if you
created a nonexistent instance via child(String)
)IOException
- if this object represents a directory or if an error occurs while performing the
operation.InterruptedException
- if interrupted while performing the operation.@NonNull public String contentAsString() throws IOException, InterruptedException
FileNotFoundException
- if this SCMFile
instance does not exist in the remote system (e.g. if you
created a nonexistent instance via child(String)
)IOException
- if this object represents a directory or if an error occurs while performing the
operation.InterruptedException
- if interrupted while performing the operation.@NonNull public String contentMimeType() throws IOException, InterruptedException
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.
FileNotFoundException
- if this SCMFile
instance does not exist in the remote system (e.g. if you
created a nonexistent instance via child(String)
)IOException
- if an error occurs while performing the operation.InterruptedException
- if interrupted while performing the operation.public boolean isContentBinary() throws IOException, InterruptedException
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.
FileNotFoundException
- if this SCMFile
instance does not exist in the remote system (e.g. if you
created a nonexistent instance via child(String)
)IOException
- if an error occurs while performing the operation.InterruptedException
- if interrupted while performing the operation.public boolean isContentText() throws IOException, InterruptedException
isContentBinary()
FileNotFoundException
- if this SCMFile
instance does not exist in the remote system (e.g. if you
created a nonexistent instance via child(String)
)IOException
- if an error occurs while performing the operation.InterruptedException
- if interrupted while performing the operation.@NonNull public Charset contentEncoding() throws IOException, InterruptedException
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.
FileNotFoundException
- if this SCMFile
instance does not exist in the remote system (e.g. if you
created a nonexistent instance via child(String)
)IOException
- if an error occurs while performing the operation.InterruptedException
- if interrupted while performing the operation.Copyright © 2016–2022. All rights reserved.