Package de.undercouch.citeproc
Class BibliographyFileReader
- java.lang.Object
-
- de.undercouch.citeproc.BibliographyFileReader
-
public class BibliographyFileReader extends java.lang.ObjectA convenience class providing methods to load any supported kind of bibliography files. The class automatically detects the correct file format and returns aItemDataProviderthat holds all bibliography items read from the file.- Author:
- Michel Kraemer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBibliographyFileReader.FileFormatSupported file formats for bibliography files
-
Constructor Summary
Constructors Constructor Description BibliographyFileReader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BibliographyFileReader.FileFormatdetermineFileFormat(java.io.BufferedInputStream bis, java.lang.String filename)Reads the first bytes of the given input stream and tries to determine the file format.BibliographyFileReader.FileFormatdetermineFileFormat(java.io.File bibfile)Reads the first 100 KB of the given bibliography file and tries to determine the file formatItemDataProviderreadBibliographyFile(java.io.File bibfile)Reads all items from an input bibliography file and returns a provider serving these itemsItemDataProviderreadBibliographyFile(java.io.InputStream bibstream, BibliographyFileReader.FileFormat format)Reads all items from an input stream using the given file format and returns a provider serving these items.ItemDataProviderreadBibliographyFile(java.io.InputStream bibstream, java.lang.String filename)Reads all items from an input stream and returns a provider serving these items.
-
-
-
Method Detail
-
readBibliographyFile
public ItemDataProvider readBibliographyFile(java.io.File bibfile) throws java.io.FileNotFoundException, java.io.IOException
Reads all items from an input bibliography file and returns a provider serving these items- Parameters:
bibfile- the input file- Returns:
- the provider
- Throws:
java.io.FileNotFoundException- if the input file was not foundjava.io.IOException- if the input file could not be read
-
readBibliographyFile
public ItemDataProvider readBibliographyFile(java.io.InputStream bibstream, java.lang.String filename) throws java.io.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 streamfilename- the name of the input file (can be null if you don't know the name)- Returns:
- the provider
- Throws:
java.io.IOException- if the input stream could not be read
-
readBibliographyFile
public ItemDataProvider readBibliographyFile(java.io.InputStream bibstream, BibliographyFileReader.FileFormat format) throws java.io.IOException
Reads all items from an input stream using the given file format and returns a provider serving these items.- Parameters:
bibstream- the input streamformat- the bibliography file format- Returns:
- the provider
- Throws:
java.io.IOException- if the input stream could not be read
-
determineFileFormat
public BibliographyFileReader.FileFormat determineFileFormat(java.io.File bibfile) throws java.io.FileNotFoundException, java.io.IOException
Reads the first 100 KB of the given bibliography file and tries to determine the file format- Parameters:
bibfile- the input file- Returns:
- the file format (or
BibliographyFileReader.FileFormat.UNKNOWNif the format could not be determined) - Throws:
java.io.FileNotFoundException- if the input file was not foundjava.io.IOException- if the input file could not be read
-
determineFileFormat
public BibliographyFileReader.FileFormat determineFileFormat(java.io.BufferedInputStream bis, java.lang.String filename) throws java.io.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 methodsfilename- the name of the input file (can be null if you don't know the name)- Returns:
- the file format (or
BibliographyFileReader.FileFormat.UNKNOWNif the format could not be determined) - Throws:
java.io.IOException- if the input stream could not be read
-
-