Class FileType

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  FileType.ReadOnlyException
      Signals that the file cannot be written to.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String BZIP2  
      static java.lang.String CR  
      protected boolean createBackup  
      static Encoding DEFAULT_ENCODING
      A String representation of the default encoding.
      protected java.io.File filename
      The file this file type identifies.
      static java.lang.String GZIP  
      static java.lang.String JSON  
      protected boolean readonly
      true iff file is readonly.
      static java.lang.String XML  
      static java.lang.String ZIP  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      FileType checkConnection()
      Tests if an InputStream can be opened for this FileType.
      static BOMReader createEncodingReader​(java.io.InputStream is, java.lang.String encoding)
      Creates a Reader.
      static java.io.OutputStreamWriter createEncodingWriter​(java.io.OutputStream os, java.lang.String encoding)
      Creates a Writer with the specified encoding.
      protected java.io.InputStream createInputStream()
      Creates an InputStream for the underlying file.
      protected java.io.OutputStream createOutputStream()
      Creates an OutputStream for the underlying file.
      java.io.Reader createReader()
      Creates a Reader for this FileType.
      java.io.Writer createWriter​(java.lang.String encoding)
      Creates a backup of the underlying file and returns a Writer for this.
      java.io.Writer createWriter​(java.lang.String encoding, int numberOfBackups)
      Creates a backup of the underlying file and returns a Writer for this.
      java.lang.String getEncoding()
      This method tries to find the encoding tag in the CR file.
      java.io.File getFile()
      Returns the underlying file.
      java.lang.String getInnerName()
      Returns the most inner name of the FileType.
      java.lang.String getName()
      Returns the name of the FileType.
      boolean isBZIP2File()
      Deprecated.
      we don't seem to need this any more
      boolean isCRFile()
      Deprecated.
      we don't seem to need this any more
      boolean isGZIPFile()
      Deprecated.
      we don't seem to need this any more
      boolean isXMLFile()
      Deprecated.
      we don't seem to need this any more
      boolean isZIPFile()
      Deprecated.
      we don't seem to need this any more
      void setCreateBackup​(boolean aCreateBackup)
      Enables or disables creation of backup files.
      void setReadonly​(boolean readonly)
      Sets whether file is readonly.
      java.lang.String toString()
      Returns a String representation of the FileType.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_ENCODING

        public static final Encoding DEFAULT_ENCODING
        A String representation of the default encoding.
      • filename

        protected java.io.File filename
        The file this file type identifies.
      • readonly

        protected boolean readonly
        true iff file is readonly.
      • createBackup

        protected boolean createBackup
    • Method Detail

      • setReadonly

        public void setReadonly​(boolean readonly)
        Sets whether file is readonly.
      • setCreateBackup

        public void setCreateBackup​(boolean aCreateBackup)
        Enables or disables creation of backup files.
        Parameters:
        aCreateBackup - true if backups shall be created
      • checkConnection

        public FileType checkConnection()
                                 throws java.io.IOException
        Tests if an InputStream can be opened for this FileType.
        Returns:
        this
        Throws:
        java.io.IOException - If the file cannot be opened for the required operation (reading or writing).
      • getFile

        public java.io.File getFile()
                             throws java.io.IOException
        Returns the underlying file.
        Returns:
        a File object
        Throws:
        java.io.IOException - if file cannot be determined, e.g. for an url pointing to an InputStream.
      • getInnerName

        public java.lang.String getInnerName()
        Returns the most inner name of the FileType. Will be overwritten in ZipFileType
        Returns:
        the most inner name of a FileType.
      • getName

        public java.lang.String getName()
        Returns the name of the FileType.
        Returns:
        the name of the FileType
      • toString

        public java.lang.String toString()
        Returns a String representation of the FileType.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a String representation of the FileType.
      • createReader

        public java.io.Reader createReader()
                                    throws java.io.IOException
        Creates a Reader for this FileType.
        Returns:
        a Reader of the underlying File.
        Throws:
        java.io.IOException - Never
      • createWriter

        public java.io.Writer createWriter​(java.lang.String encoding)
                                    throws java.io.IOException
        Creates a backup of the underlying file and returns a Writer for this.
        Parameters:
        encoding - The name of a supported charset
        Returns:
        a Writer of the underlying File.
        Throws:
        FileType.ReadOnlyException - If file is marked as readonly or cannot be opened
        java.io.IOException - If another IOException occured
      • createWriter

        public java.io.Writer createWriter​(java.lang.String encoding,
                                           int numberOfBackups)
                                    throws java.io.IOException
        Creates a backup of the underlying file and returns a Writer for this.
        Parameters:
        encoding - The name of a supported charset
        numberOfBackups - This many backup files (marked with ~#~ will) be created.
        Returns:
        a Writer of the underlying File.
        Throws:
        FileType.ReadOnlyException - If file is marked as readonly or cannot be opened
        java.io.IOException - If the file cannot be created
      • createInputStream

        protected java.io.InputStream createInputStream()
                                                 throws java.io.IOException
        Creates an InputStream for the underlying file.
        Returns:
        an InputStream of the underlying file.
        Throws:
        java.io.IOException - If the file cannot be opened for reading
      • createOutputStream

        protected java.io.OutputStream createOutputStream()
                                                   throws java.io.IOException
        Creates an OutputStream for the underlying file.
        Returns:
        an OutputStream of the underlying file.
        Throws:
        java.io.IOException - If the file cannot be opened for writing
      • createEncodingReader

        public static BOMReader createEncodingReader​(java.io.InputStream is,
                                                     java.lang.String encoding)
                                              throws java.io.IOException
        Creates a Reader. Tries to determine encoding by looking at the BOM. If it cannot determine the encoding, the given encoding is used.
        Parameters:
        is - the InputStream
        encoding - The name of a supported charset
        Returns:
        a Reader for the given InputStream
        Throws:
        java.io.IOException - Never
      • createEncodingWriter

        public static java.io.OutputStreamWriter createEncodingWriter​(java.io.OutputStream os,
                                                                      java.lang.String encoding)
                                                               throws java.io.IOException
        Creates a Writer with the specified encoding.
        Parameters:
        os - the OutputStream
        encoding - The name of a supported charset
        Returns:
        a Writer for the given OutputStream
        Throws:
        java.io.IOException - If the named encoding is not supported
      • isXMLFile

        @Deprecated
        public boolean isXMLFile()
                          throws java.io.IOException
        Deprecated.
        we don't seem to need this any more
        Determines, whether a file is of XML filetype, moved from com.eressea.io.GameDataReader by Jonathan 20060917 (Fiete)
        Returns:
        true, if the file is of XML type
        Throws:
        java.io.IOException
      • isCRFile

        @Deprecated
        public boolean isCRFile()
                         throws java.io.IOException
        Deprecated.
        we don't seem to need this any more
        Determines, whether a file is of CR filetype, moved from com.eressea.io.GameDataReader by Jonathan 20060917 (Fiete)
        Returns:
        true, if the file is of CR type or of unknown type
        Throws:
        java.io.IOException
      • isZIPFile

        @Deprecated
        public boolean isZIPFile()
                          throws java.io.IOException
        Deprecated.
        we don't seem to need this any more
        Determines, whether a file is a ZIP filetype by Jonathan 20060917 (Fiete)
        Returns:
        true, if the file is of ZIP type
        Throws:
        java.io.IOException
      • isGZIPFile

        @Deprecated
        public boolean isGZIPFile()
                           throws java.io.IOException
        Deprecated.
        we don't seem to need this any more
        Determines, whether a file is a GZIP filetype by Jonathan 20060917 (Fiete)
        Returns:
        true, if the file is of GZIP type
        Throws:
        java.io.IOException
      • isBZIP2File

        @Deprecated
        public boolean isBZIP2File()
                            throws java.io.IOException
        Deprecated.
        we don't seem to need this any more
        Determines, whether a file is a BZIP2 filetype by Jonathan 20060917 (Fiete)
        Returns:
        true, if the file is of BZIP2 type
        Throws:
        java.io.IOException
      • getEncoding

        public java.lang.String getEncoding()
        This method tries to find the encoding tag in the CR file.