Class BibliographyFileReader


  • public class BibliographyFileReader
    extends Object
    A convenience class providing methods to load any supported kind of bibliography files. The class automatically detects the correct file format and returns a ItemDataProvider that holds all bibliography items read from the file.
    Author:
    Michel Kraemer
    • Constructor Detail

      • BibliographyFileReader

        public BibliographyFileReader()
    • Method Detail

      • readBibliographyFile

        public ItemDataProvider readBibliographyFile​(InputStream bibstream,
                                                     String filename)
                                              throws IOException
        Reads all items from an input stream and returns a provider serving these items. Note that you can supply an additional file name to help the method to determine the exact bibliography file format. If you don't know the file name you can pass null, but in this case the method's result might try to read the input stream using the wrong file format (depending on the input stream's contents). Also note that the caller is responsible for closing the given input stream.
        Parameters:
        bibstream - the input stream
        filename - the name of the input file (can be null if you don't know the name)
        Returns:
        the provider
        Throws:
        IOException - if the input stream could not be read
      • readBibliographyFile

        public ItemDataProvider readBibliographyFile​(InputStream bibstream,
                                                     BibliographyFileReader.FileFormat format)
                                              throws IOException
        Reads all items from an input stream using the given file format and returns a provider serving these items.
        Parameters:
        bibstream - the input stream
        format - the bibliography file format
        Returns:
        the provider
        Throws:
        IOException - if the input stream could not be read
      • determineFileFormat

        public BibliographyFileReader.FileFormat determineFileFormat​(BufferedInputStream bis,
                                                                     String filename)
                                                              throws IOException
        Reads the first bytes of the given input stream and tries to determine the file format. Resets the input stream to the position it had when the method was called. Reads up to 100 KB and before giving up. Note that you can supply an additional file name to help the method to determine the exact file format. If you don't know the file name you can pass null, but in this case the method's result might be wrong (depending on the input stream's contents).
        Parameters:
        bis - a buffered input stream that supports the mark and reset methods
        filename - the name of the input file (can be null if you don't know the name)
        Returns:
        the file format (or BibliographyFileReader.FileFormat.UNKNOWN if the format could not be determined)
        Throws:
        IOException - if the input stream could not be read