Package de.espirit.firstspirit.io
Interface FileHandle
- All Superinterfaces:
Comparable<FileHandle>
- All Known Subinterfaces:
ExportInfoFileHandle
Interface for file handles provided by a
FileSystem
.- Since:
- 5.0.413
-
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(InputStream content) IfisFile()
returnstrue
, appends the stream-given content to the file.void
delete()
Deletes this file or (recursiv) this directoryboolean
exists()
Indicates, whether the file referred to with the handle exists.Get a handle on the child with the given name.long
getCrc()
Delivers the crc checksum ifhasCrc()
returnstrue
, else returns 0long
Get the last modification time of the referenced file in milliseconds.getName()
The name of the file (without path), or the last part of the name its a directory@NotNull OutputStream
Returns an OutputStream to store content to the file.@NotNull OutputStream
getOutputStream
(boolean append) Provides an OutputStream to store content to the file.@Nullable FileHandle
Get a handle on the parent file.getPath()
The path of the file (including file name ifgetType()
deliversFileType.FILE
).
Path elements are seperated with slashes "/".long
getSize()
The size of the file in bytes, delivers 0 ifgetType()
is notFileType.FILE
@NotNull FileType
getType()
Returns thetype
of the file handle.boolean
hasCrc()
Deliverstrue
ifgetType()
==FileType.FILE
) and the crc checksum could be calculated (which may not work for someFileSystem
's)boolean
boolean
isFile()
@NotNull List<FileHandle>
Returns the files in the directory referenced by the handle.@NotNull InputStream
load()
IfisFile()
returns true, returns a stream handle on the file's content.void
mkDirs()
Create all necessary directories up to this one.void
Rename this file or directory.
The provided name must not contain any slashes!void
save
(InputStream content) IfisFile()
returnstrue
, saves the stream-given content to the file.void
setLastModified
(long time) Set the last modification time of the referenced file in milliseconds.void
Swap the file with the another on stored at the given path.Methods inherited from interface java.lang.Comparable
compareTo
-
Method Details
-
exists
boolean exists()Indicates, whether the file referred to with the handle exists.- Returns:
true
, iff the file exists.- Since:
- 5.0.413
-
getType
Returns thetype
of the file handle.- Returns:
- The file's type.
- Since:
- 5.0.413
-
isFile
boolean isFile()- Since:
- 5.0.413
-
isDirectory
boolean isDirectory()- Since:
- 5.0.413
-
listFiles
Returns the files in the directory referenced by the handle.- Returns:
- A list of file handles.
- Throws:
IOException
- If an error occurred accessing the file.de.espirit.firstspirit.server.io.InvalidOperationOnTypeException
- If the file is no directory.- Since:
- 5.0.413
-
mkDirs
Create all necessary directories up to this one.Note: The creation process may partially succeed before failing!
- Throws:
IOException
- If creating directories failed.de.espirit.firstspirit.server.io.InvalidOperationOnTypeException
- If the file is no directory.- Since:
- 5.0.413
-
load
IfisFile()
returns true, returns a stream handle on the file's content.- Returns:
- An
InputStream
or null. - Throws:
IOException
- If an error occured accessing the file.de.espirit.firstspirit.server.io.InvalidOperationOnTypeException
- If the file is no file.- Since:
- 5.0.413
-
save
IfisFile()
returnstrue
, saves the stream-given content to the file.Note: The given
InputStream
will be closed when finished!- Parameters:
content
- The content providing stream.- Throws:
IOException
- If an error occurred writing the file.de.espirit.firstspirit.server.io.InvalidOperationOnTypeException
- If the file is no file.- Since:
- 5.0.413
-
append
IfisFile()
returnstrue
, appends the stream-given content to the file.Note: closes given
InputStream
when finished!- Parameters:
content
- The content providing stream.- Throws:
IOException
- If an error occurred writing the file.de.espirit.firstspirit.server.io.InvalidOperationOnTypeException
- If the file is no file.- Since:
- 5.0.413
-
getOutputStream
Returns an OutputStream to store content to the file. Short form forgetOutputStream(false)
Attention: ensure to close the stream!- Returns:
- an OutputStream to store content to the file.
- Throws:
IOException
- If an error occurred writing the file.de.espirit.firstspirit.server.io.InvalidOperationOnTypeException
- If this handle is no file or writing is not allowed.- Since:
- 5.0.413
- See Also:
-
getOutputStream
Provides an OutputStream to store content to the file. The stream may be opened anew or for appending content. Attention: ensure to close the stream after usage!- Parameters:
append
- Iftrue
, will open the stream for appending to existing content.- Returns:
- An OutputStream for storing content to the related file.
- Throws:
IOException
- If an error occured writing the file.de.espirit.firstspirit.server.io.InvalidOperationOnTypeException
- If this handle is no file or writing is not allowed.- Since:
- 5.2.2
-
getName
String getName()The name of the file (without path), or the last part of the name its a directory- Since:
- 5.0.413
-
getPath
String getPath()The path of the file (including file name ifgetType()
deliversFileType.FILE
).
Path elements are seperated with slashes "/".- Since:
- 5.0.413
-
getSize
long getSize()The size of the file in bytes, delivers 0 ifgetType()
is notFileType.FILE
- Since:
- 5.0.413
-
hasCrc
boolean hasCrc()Deliverstrue
ifgetType()
==FileType.FILE
) and the crc checksum could be calculated (which may not work for someFileSystem
's)- Since:
- 5.0.413
-
getCrc
Delivers the crc checksum ifhasCrc()
returnstrue
, else returns 0- Throws:
IOException
- Since:
- 5.0.413
-
delete
Deletes this file or (recursiv) this directory- Throws:
IOException
- Since:
- 5.0.413
-
rename
Rename this file or directory.
The provided name must not contain any slashes!- Throws:
IOException
- Since:
- 5.0.413
-
swapWith
Swap the file with the another on stored at the given path. If no file is stored at the given path, the file is being renamed.- Parameters:
path
- The path to the file to be swapped.- Throws:
IOException
- Since:
- 5.0.413
-
getLastModified
long getLastModified()Get the last modification time of the referenced file in milliseconds.- Returns:
- The last modification time.
- Since:
- 5.0.413
-
setLastModified
Set the last modification time of the referenced file in milliseconds. This operation may not be supported by the underlyingFileSystem
and, thus, may have no effect.- Parameters:
time
- The last modification time to set.- Throws:
IOException
- Since:
- 5.0.413
-
getParent
Get a handle on the parent file.- Returns:
- The parent's handle or null, if there is no parent.
- Throws:
IOException
- Since:
- 5.0.413
-
getChild
Get a handle on the child with the given name.- Parameters:
name
- The name of the child file.- Returns:
- The handle on the child.
- Throws:
IOException
- Since:
- 5.0.413
-