Class DataFile

    • 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 DataFile
        filename - the filename of the DataFile
      • DataFile

        public DataFile​(File parentFile,
                        String filename)
        Public constructor.
        Parameters:
        parentFile - the parent file of the DataFile
        filename - the filename of the DataFile
      • DataFile

        public DataFile​(Path parentPath,
                        String filename)
        Public constructor.
        Parameters:
        parentPath - the parent file of the DataFile
        filename - 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
      • 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 IOException
        Create a directory with the path of the DataFile.
        Throws:
        IOException - if an error occurs while creating the directory
      • mkdirs

        public void mkdirs()
                    throws IOException
        Create 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 file
        relativize - relativize the link target path
        Throws:
        IOException - if an error occurs while creating the symbolic link
      • delete

        public void delete()
                    throws IOException
        Delete the DataFile.
        Throws:
        IOException - if an error occurs while deleting the DataFile
      • delete

        public void delete​(boolean recursive)
                    throws IOException
        Delete 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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object