- java.lang.Object
-
- org.refcodes.filesystem.FileHandleImpl
-
- All Implemented Interfaces:
FileHandle,FileSizeAccessor,org.refcodes.mixin.CreatedDateAccessor,org.refcodes.mixin.ModifiedDateAccessor,org.refcodes.mixin.NameAccessor,org.refcodes.mixin.PathAccessor
- Direct Known Subclasses:
FileHandleImpl.MutableFileHandleImpl
public class FileHandleImpl extends Object implements FileHandle
Straight forward implementation of theFileHandle,.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classFileHandleImpl.MutableFileHandleImplThe implementation of aFileHandle.MutableFileHandle. ------------------------------------------------------------------------- CAUTION: fiddling with the path and the name attributes causes theFileHandleImpl.MutableFileHandleImpl.hashCode()andFileHandleImpl.MutableFileHandleImpl.equals(Object)methods to change behavior which can cause problems especially in collections!-
Nested classes/interfaces inherited from interface org.refcodes.mixin.CreatedDateAccessor
org.refcodes.mixin.CreatedDateAccessor.CreatedDateMutator, org.refcodes.mixin.CreatedDateAccessor.CreatedDateProperty
-
Nested classes/interfaces inherited from interface org.refcodes.filesystem.FileHandle
FileHandle.MutableFileHandle
-
Nested classes/interfaces inherited from interface org.refcodes.filesystem.FileSizeAccessor
FileSizeAccessor.FileSizeMutator, FileSizeAccessor.FileSizeProperty
-
Nested classes/interfaces inherited from interface org.refcodes.mixin.ModifiedDateAccessor
org.refcodes.mixin.ModifiedDateAccessor.ModifiedDateMutator, org.refcodes.mixin.ModifiedDateAccessor.ModifiedDateProperty
-
-
Field Summary
Fields Modifier and Type Field Description protected Date_createdDateprotected Date_modifiedDateprotected String_nameprotected String_pathprotected long_size
-
Constructor Summary
Constructors Constructor Description FileHandleImpl(String aKey)Constructs aFileHandleobject with the given properties.FileHandleImpl(String aPath, String aName)Constructs aFileHandleobject with the given properties.FileHandleImpl(String aPath, String aName, long aSize, Date aCreatedDate, Date aModifiedDate)Constructs aFileHandleobject with the given properties.FileHandleImpl(FileHandle aFileHandle)Constructs aFileHandleobject with the properties of the givenFileHandle.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)DategetCreatedDate()The date when the file was created.longgetFileSize()The size of the content of the file.DategetModifiedDate()The date when the file was modified.StringgetName()The name is the part of the key without the path.StringgetPath()The path is the part of the key without the name.inthashCode()StringtoKey()The key is the fully qualified name to identify the file.FileHandle.MutableFileHandletoMutableFileHandle()Converts the giveFileHandleto aFileHandle.MutableFileHandle.
-
-
-
Constructor Detail
-
FileHandleImpl
public FileHandleImpl(String aPath, String aName, long aSize, Date aCreatedDate, Date aModifiedDate)
Constructs aFileHandleobject with the given properties.- Parameters:
aPath- The path to which the file handle points.aName- The name to which the path pointsaSize- The size of the fileaCreatedDate- The creation date of the fileaModifiedDate- The modified date of the file
-
FileHandleImpl
public FileHandleImpl(String aKey)
Constructs aFileHandleobject with the given properties.- Parameters:
aKey- The path and the name (= the key) to which the file handle points.
-
FileHandleImpl
public FileHandleImpl(String aPath, String aName)
Constructs aFileHandleobject with the given properties.- Parameters:
aPath- The path to which the file handle points.aName- The name to which the path points
-
FileHandleImpl
public FileHandleImpl(FileHandle aFileHandle)
Constructs aFileHandleobject with the properties of the givenFileHandle.- Parameters:
aFileHandle- TheFileHandlefrom which to take the required properties.
-
-
Method Detail
-
getPath
public String getPath()
The path is the part of the key without the name. The path separator is not implementation specific and should be retrieved from the file system'sFileSystem.PATH_DELIMITERattribute.- Specified by:
getPathin interfaceFileHandle- Specified by:
getPathin interfaceorg.refcodes.mixin.PathAccessor- Returns:
- The path of the file's key without the name.
-
getName
public String getName()
The name is the part of the key without the path. The path separator is not implementation specific and should be retrieved from the file system'sFileSystem.PATH_DELIMITERattribute.- Specified by:
getNamein interfaceFileHandle- Specified by:
getNamein interfaceorg.refcodes.mixin.NameAccessor- Returns:
- The name of the file's key without the path.
-
toKey
public String toKey()
The key is the fully qualified name to identify the file. The key usually is physically (directory path and filename) or virtually composed of the path and the name.- Specified by:
toKeyin interfaceFileHandle- Returns:
- The fully qualified key of the file.
-
getFileSize
public long getFileSize()
The size of the content of the file.- Specified by:
getFileSizein interfaceFileHandle- Specified by:
getFileSizein interfaceFileSizeAccessor- Returns:
- The content size of the file.
-
getCreatedDate
public Date getCreatedDate()
The date when the file was created.- Specified by:
getCreatedDatein interfaceorg.refcodes.mixin.CreatedDateAccessor- Specified by:
getCreatedDatein interfaceFileHandle- Returns:
- The creation date.
-
getModifiedDate
public Date getModifiedDate()
The date when the file was modified.- Specified by:
getModifiedDatein interfaceFileHandle- Specified by:
getModifiedDatein interfaceorg.refcodes.mixin.ModifiedDateAccessor- Returns:
- The modification date.
-
toMutableFileHandle
public FileHandle.MutableFileHandle toMutableFileHandle()
Converts the giveFileHandleto aFileHandle.MutableFileHandle. The mutableFileHandleallows the modification of (fiddling around with) attributes. ------------------------------------------------------------------------- ATTENTION: Usually fiddling around with attributes is not necessary, as theFileSystemitself provides the sufficient functionality to work with files. In some cases though this might be necessary: This method is being provided to allow modification of file attributes while making sure that theFileHandleitself creates a copy so that any additional attributes provided by extensions of this interface of whom the developer does not know (yet) are preserved. So extensions of theFileHandleknow how to create aFileHandle.MutableFileHandlewithout information loss, the business logic does not require to take care of any yet unknown extensions. ------------------------------------------------------------------------- CAUTION: Working with modifiedFileHandles on theFileSystemcan cause unexpected (severe) behavior (data loss), so we assume that you know what you do when using theFileHandle.MutableFileHandle! ------------------------------------------------------------------------- UseFileHandle.MutableFileHandle.toFileHandle()to get back to aFileHandleto avoid hassle with collections, theObject.hashCode()and theObject.equals(Object)operations.- Specified by:
toMutableFileHandlein interfaceFileHandle- Returns:
- the mutable file handle
-
-