Interface FeatureCodec<FEATURE_TYPE extends Feature,​SOURCE>

    • Method Detail

      • decodeLoc

        Feature decodeLoc​(SOURCE source)
                   throws IOException
        Decode a line to obtain just its FeatureLoc for indexing -- contig, start, and stop.
        Parameters:
        source - the input stream from which to decode the next record
        Returns:
        Return the FeatureLoc encoded by the line, or null if the line does not represent a feature (e.g. is a comment)
        Throws:
        IOException
      • decode

        FEATURE_TYPE decode​(SOURCE source)
                     throws IOException
        Decode a single Feature from the FeatureCodec, reading no further in the underlying source than beyond that feature.
        Parameters:
        source - the input stream from which to decode the next record
        Returns:
        Return the Feature encoded by the line, or null if the line does not represent a feature (e.g. is a comment)
        Throws:
        IOException
      • readHeader

        FeatureCodecHeader readHeader​(SOURCE source)
                               throws IOException
        Read and return the header, or null if there is no header. Note: Implementers of this method must be careful to read exactly as much from FeatureCodec as needed to parse the header, and no more. Otherwise, data that might otherwise be fed into parsing a Feature may be lost.
        Parameters:
        source - the source from which to decode the header
        Returns:
        header object
        Throws:
        IOException
      • getFeatureType

        Class<FEATURE_TYPE> getFeatureType()

        This function returns the object the codec generates. This is allowed to be Feature in the case where conditionally different types are generated. Be as specific as you can though.

        This function is used by reflections based tools, so we can know the underlying type

        Returns:
        the feature type this codec generates.
      • makeSourceFromStream

        SOURCE makeSourceFromStream​(InputStream bufferedInputStream)
        Generates a reader of type FeatureCodec appropriate for use by this codec from the generic input stream. Implementers should assume the stream is buffered.
      • isDone

        boolean isDone​(SOURCE source)
        Adapter method that assesses whether the provided FeatureCodec has more data. True if it does, false otherwise.
      • close

        void close​(SOURCE source)
        Adapter method that closes the provided FeatureCodec.
      • canDecode

        boolean canDecode​(String path)

        This function returns true iff the File potentialInput can be parsed by this codec. Note that checking the file's extension is a perfectly acceptable implementation of this method and file contents only rarely need to be checked.

        There is an assumption that there's never a situation where two different Codecs return true for the same file. If this occurs, the recommendation would be to error out.

        Note this function must never throw an error. All errors should be trapped and false returned.
        Parameters:
        path - the file to test for parsability with this codec
        Returns:
        true if potentialInput can be parsed, false otherwise
      • getPathToDataFile

        default String getPathToDataFile​(String path)
        Codecs may override this method if the file that they recognize with canDecode(String) is different than the file that contains the data they parse. This enables a class of codecs where the input file is a configuration that defines how to locate and handle the datafile. The default implementation returns the same path which was passed in.
        Parameters:
        path - the path to a file that this codec canDecode(java.lang.String)
        Returns:
        the path to the data file that should be parsed by this codec to produce Features.
        Throws:
        TribbleException - codecs may throw if they cannot decode the path.