Class DataFile
- java.lang.Object
-
- fr.ens.biologie.genomique.eoulsan.data.DataFile
-
- All Implemented Interfaces:
Serializable,Comparable<DataFile>
public class DataFile extends Object implements Comparable<DataFile>, Serializable
This class define a DataFile.- Since:
- 1.0
- Author:
- Laurent Jourdren
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringseparatorThe separator char ('/') as a String.static charseparatorCharThe separator char ('/').
-
Constructor Summary
Constructors Constructor Description DataFile(DataFile parentFile, String filename)Public constructor.DataFile(File file)Public constructor.DataFile(File parentFile, String filename)Public constructor.DataFile(String source)Public constructor.DataFile(URI uri)Public constructor.DataFile(Path path)Public constructor.DataFile(Path parentPath, String filename)Public constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(DataFile o)voidcopyTo(DataFile dest)Copy this DataFile in a other DataFile.OutputStreamcreate()Create an OutputStream for the DataFile.voiddelete()Delete the DataFile.voiddelete(boolean recursive)Delete the DataFile.booleanequals(Object o)booleanexists()Check if this DataFile exists.booleanexists(boolean followLink)Check if this DataFile exists.StringgetBasename()Get the base name of this DataFile without all its extensions.StringgetCompressionExtension()Get the compression extension of this DataFile.fr.ens.biologie.genomique.kenetre.io.CompressionTypegetCompressionType()Get the compression Type of this DataFile.DataFormatgetDataFormat()Get the DataFormat of the DataFile.StringgetExtension()Get the extension of this DataFile without compression extension.StringgetFullExtension()Get the base name of this DataFile with all its extensions (include compression extension).DataFileMetadatagetMetaData()Get the metadata for this DataFile.StringgetName()Get the name of this DataFile.DataFilegetParent()Get the parent of this DataFile.DataProtocolgetProtocol()Get the protocol of this DataFile.StringgetProtocolPrefixInSource()Get the prefix of the protocol in the source name of the DataFile.StringgetSource()Get the source of this DataFile.inthashCode()booleanisLocalFile()Test if the DataFile use the defaultProtocol.List<DataFile>list()List the content of a directory.voidmkdir()Create a directory with the path of the DataFile.voidmkdirs()Create a directory and its parents if not exists with the path of the DataFile.InputStreamopen()Create an InputStream for the DataFile.OutputStreamrawCreate()Create an OutputStream for the DataFile.InputStreamrawOpen()Create an InputStream for the DataFile.voidrenameTo(DataFile dest)Rename the DataFile.voidsymlink(DataFile link)Create a symbolic link that target is the current file.voidsymlink(DataFile link, boolean relativize)Create a symbolic link that target is the current file.DataFiletoAbsoluteDataFile()Convert the the DataFile to a absolute DataFile.FiletoFile()Convert the DataFile object to File object if the underlying protocol allow it.PathtoPath()Convert the DataFile object to Path object if the underlying protocol allow it.DataFiletoRealDataFile()Convert the the DataFile to a DataFile where all the indirection has been solved.StringtoString()URItoUri()Convert the DataFile object to an URI.
-
-
-
Field Detail
-
separatorChar
public static final char separatorChar
The separator char ('/').- See Also:
- Constant Field Values
-
separator
public static final String separator
The separator char ('/') as a String.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DataFile
public DataFile(String source)
Public constructor.- Parameters:
source- the source of the DataFile
-
DataFile
public DataFile(DataFile parentFile, String filename)
Public constructor.- Parameters:
parentFile- the parent file of the DataFilefilename- the filename of the DataFile
-
DataFile
public DataFile(File parentFile, String filename)
Public constructor.- Parameters:
parentFile- the parent file of the DataFilefilename- the filename of the DataFile
-
DataFile
public DataFile(Path parentPath, String filename)
Public constructor.- Parameters:
parentPath- the parent file of the DataFilefilename- the filename of the DataFile
-
DataFile
public DataFile(File file)
Public constructor.- Parameters:
file- the source file of the DataFile
-
DataFile
public DataFile(Path path)
Public constructor.- Parameters:
path- the source path of the DataFile
-
DataFile
public DataFile(URI uri)
Public constructor.- Parameters:
uri- the URI of the DataFile
-
-
Method Detail
-
getSource
public String getSource()
Get the source of this DataFile.- Returns:
- a String with the source of this DataFile
-
getName
public String getName()
Get the name of this DataFile.- Returns:
- a String with the name of this DataFile
-
getBasename
public String getBasename()
Get the base name of this DataFile without all its extensions. The result is computed with the output of the getName() method.- Returns:
- a String with the base name of this DataFile
-
getExtension
public String getExtension()
Get the extension of this DataFile without compression extension. The result is computed with the output of the getName() method.- Returns:
- a String with the extension of this DataFile. The result String is empty if there is no extension
-
getFullExtension
public String getFullExtension()
Get the base name of this DataFile with all its extensions (include compression extension). The result is computed with the output of the getName() method.- Returns:
- a String with the base name of this DataFile. The result String is empty if there is no extension
-
getCompressionExtension
public String getCompressionExtension()
Get the compression extension of this DataFile. The result is computed with the output of the getName() method.- Returns:
- a String with the compression extension of this DataFile. The result String is empty if there is no compression extension
-
getCompressionType
public fr.ens.biologie.genomique.kenetre.io.CompressionType getCompressionType()
Get the compression Type of this DataFile. The result is computed with the output of the getName() method.- Returns:
- a CompressionType object
-
getDataFormat
public DataFormat getDataFormat()
Get the DataFormat of the DataFile. The result is computed with the output of the getName() method. This is an alias for getDataFormatFromFilename() of the DataFormatRegistry.- Returns:
- the DataFormat of the DataFile
-
getParent
public DataFile getParent() throws IOException
Get the parent of this DataFile.- Returns:
- the parent DataFile
- Throws:
IOException- if an error occurs while the parent
-
getProtocol
public DataProtocol getProtocol() throws IOException
Get the protocol of this DataFile.- Returns:
- a DataProtocol
- Throws:
IOException
-
getMetaData
public DataFileMetadata getMetaData() throws IOException
Get the metadata for this DataFile.- Returns:
- a DataFileMetadata with all metadata information about this DataFile
- Throws:
IOException- if the protocol is unknown or if the DataFile does not exists
-
getProtocolPrefixInSource
public String getProtocolPrefixInSource()
Get the prefix of the protocol in the source name of the DataFile.- Returns:
- the prefix of the protocol
-
isLocalFile
public boolean isLocalFile()
Test if the DataFile use the defaultProtocol.- Returns:
- true if the DataFile use the default protocol
-
toFile
public File toFile()
Convert the DataFile object to File object if the underlying protocol allow it. Only local protocol can return a value.- Returns:
- a File object or null if the underlying protocol does not allow it
-
toPath
public Path toPath()
Convert the DataFile object to Path object if the underlying protocol allow it.- Returns:
- a Path object or null if the underlying protocol does not allow it
-
toUri
public URI toUri()
Convert the DataFile object to an URI.- Returns:
- an URI object or null if the DataFile cannot be converted into URI
-
toRealDataFile
public DataFile toRealDataFile()
Convert the the DataFile to a DataFile where all the indirection has been solved. This method use the JDK Path.toRealPath() method. This method has only an effect for local DataFiles.- Returns:
- a DataFile
-
toAbsoluteDataFile
public DataFile toAbsoluteDataFile()
Convert the the DataFile to a absolute DataFile. This method use the JDK File.getAbsoluteFile() method. This method has only an effect for local DataFiles.- Returns:
- a DataFile
-
create
public OutputStream create() throws IOException
Create an OutputStream for the DataFile. If the DataFile is declared as compressed by its content type or its extension, the output stream will be automatically compress data.- Returns:
- an OutputStream object
- Throws:
IOException- if an error occurs while creating the DataFile
-
rawCreate
public OutputStream rawCreate() throws IOException
Create an OutputStream for the DataFile. The output stream will not automatically compress data.- Returns:
- an OutputStream object
- Throws:
IOException- if an error occurs while creating the DataFile
-
open
public InputStream open() throws IOException
Create an InputStream for the DataFile. If the DataFile is compressed, the input stream will be automatically uncompress.- Returns:
- an InputStream object
- Throws:
IOException- if an error occurs while opening the DataFile
-
rawOpen
public InputStream rawOpen() throws IOException
Create an InputStream for the DataFile. The input stream will not automatically uncompress data.- Returns:
- an InputStream object
- Throws:
IOException- if an error occurs while opening the DataFile
-
copyTo
public void copyTo(DataFile dest) throws IOException
Copy this DataFile in a other DataFile.- Parameters:
dest- destination DataFile- Throws:
IOException- if an error occurs while copying the DataFile
-
exists
public boolean exists()
Check if this DataFile exists.- Returns:
- true if this DataFile exists
-
exists
public boolean exists(boolean followLink)
Check if this DataFile exists.- Parameters:
followLink- follow the link target if the file is a symbolic link- Returns:
- true if this DataFile exists
-
mkdir
public void mkdir() throws IOExceptionCreate a directory with the path of the DataFile.- Throws:
IOException- if an error occurs while creating the directory
-
mkdirs
public void mkdirs() throws IOExceptionCreate a directory and its parents if not exists with the path of the DataFile.- Throws:
IOException- if an error occurs while creating the directory
-
symlink
public void symlink(DataFile link) throws IOException
Create a symbolic link that target is the current file.- Parameters:
link- symbolic file- Throws:
IOException- if an error occurs while creating the symbolic link
-
symlink
public void symlink(DataFile link, boolean relativize) throws IOException
Create a symbolic link that target is the current file.- Parameters:
link- symbolic filerelativize- relativize the link target path- Throws:
IOException- if an error occurs while creating the symbolic link
-
delete
public void delete() throws IOExceptionDelete the DataFile.- Throws:
IOException- if an error occurs while deleting the DataFile
-
delete
public void delete(boolean recursive) throws IOExceptionDelete the DataFile.- Parameters:
recursive- recursive deletion- Throws:
IOException- if an error occurs while deleting the DataFile
-
list
public List<DataFile> list() throws IOException
List the content of a directory.- Returns:
- a List with the content of the directory
- Throws:
IOException- if an error occurs while listing the directory
-
renameTo
public void renameTo(DataFile dest) throws IOException
Rename the DataFile.- Parameters:
dest- destination DataFile- Throws:
IOException- if an error occurs while renaming the DataFile
-
compareTo
public int compareTo(DataFile o)
- Specified by:
compareToin interfaceComparable<DataFile>
-
-