Top Description Inners Constructors Methods
de.undercouch.citeproc

public Class BibliographyFileReader

extends Object
Class Inheritance
Imports
de.undercouch.citeproc.bibtex.BibTeXConverter, .BibTeXItemDataProvider, de.undercouch.citeproc.csl.CSLItemData, de.undercouch.citeproc.endnote.EndNoteConverter, .EndNoteItemDataProvider, .EndNoteLibrary, de.undercouch.citeproc.helper.json.JsonLexer, .JsonParser, de.undercouch.citeproc.ris.RISConverter, .RISItemDataProvider, .RISLibrary, org.jbibtex.BibTeXDatabase, .ParseException, org.yaml.snakeyaml.Yaml, java.io.BufferedInputStream, .File, .FileInputStream, .FileNotFoundException, .IOException, .InputStream, .InputStreamReader, java.nio.charset.StandardCharsets, java.util.ArrayList, .Collection, .Collections, .List, .Map

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
BibliographyFileReader.FileFormat

Supported file formats for bibliography files

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public BibliographyFileReader.FileFormat

Returns:

the file format (or FileFormat#UNKNOWN if the format could not be determined)
determineFileFormat
(File
the input file
bibfile
)

Reads the first 100 KB of the given bibliography file and tries to determine the file format

public BibliographyFileReader.FileFormat

Returns:

the file format (or FileFormat#UNKNOWN if the format could not be determined)
determineFileFormat
(BufferedInputStream
a buffered input stream that supports the mark and reset methods
bis
,
String
the name of the input file (can be null if you don't know the name)
filename
)

Reads the first bytes of the given input stream and tries to determine the file format.

public ItemDataProvider

Returns:

the provider
readBibliographyFile
(File
the input file
bibfile
)

Reads all items from an input bibliography file and returns a provider serving these items

public ItemDataProvider

Returns:

the provider
readBibliographyFile
(InputStream
the input stream
bibstream
,
String
the name of the input file (can be null if you don't know the name)
filename
)

Reads all items from an input stream and returns a provider serving these items.

public ItemDataProvider

Returns:

the provider
readBibliographyFile
(InputStream
the input stream
bibstream
,
BibliographyFileReader.FileFormat
the bibliography file format
format
)

Reads all items from an input stream using the given file format and returns a provider serving these items.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

BibliographyFileReaderback to summary
public BibliographyFileReader()

Method Detail

determineFileFormatback to summary
public BibliographyFileReader.FileFormat determineFileFormat(File bibfile) throws FileNotFoundException, IOException

Reads the first 100 KB of the given bibliography file and tries to determine the file format

Parameters
bibfile:File

the input file

Returns:BibliographyFileReader.FileFormat

the file format (or FileFormat#UNKNOWN if the format could not be determined)

Exceptions
FileNotFoundException:
if the input file was not found
IOException:
if the input file could not be read
determineFileFormatback to summary
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:BufferedInputStream

a buffered input stream that supports the mark and reset methods

filename:String

the name of the input file (can be null if you don't know the name)

Returns:BibliographyFileReader.FileFormat

the file format (or FileFormat#UNKNOWN if the format could not be determined)

Exceptions
IOException:
if the input stream could not be read
readBibliographyFileback to summary
public ItemDataProvider readBibliographyFile(File bibfile) throws FileNotFoundException, IOException

Reads all items from an input bibliography file and returns a provider serving these items

Parameters
bibfile:File

the input file

Returns:ItemDataProvider

the provider

Exceptions
FileNotFoundException:
if the input file was not found
IOException:
if the input file could not be read
readBibliographyFileback to summary
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:InputStream

the input stream

filename:String

the name of the input file (can be null if you don't know the name)

Returns:ItemDataProvider

the provider

Exceptions
IOException:
if the input stream could not be read
readBibliographyFileback to summary
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:InputStream

the input stream

format:BibliographyFileReader.FileFormat

the bibliography file format

Returns:ItemDataProvider

the provider

Exceptions
IOException:
if the input stream could not be read
de.undercouch.citeproc back to summary

public final Enum BibliographyFileReader.FileFormat

extends Enum<BibliographyFileReader.FileFormat>
Class Inheritance

Supported file formats for bibliography files

Field Summary

Modifier and TypeField and Description
public static final BibliographyFileReader.FileFormat
BIBTEX

A BibTeX file

public static final BibliographyFileReader.FileFormat
ENDNOTE

An EndNote file

public static final BibliographyFileReader.FileFormat
JSON_ARRAY

An array of CSL JSON objects

public static final BibliographyFileReader.FileFormat
JSON_OBJECT

A CSL JSON object

public static final BibliographyFileReader.FileFormat
RIS

An RIS file

public static final BibliographyFileReader.FileFormat
UNKNOWN

Unknown file format

public static final BibliographyFileReader.FileFormat
YAML

A YAML document

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static BibliographyFileReader.FileFormat
public static BibliographyFileReader.FileFormat[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BIBTEXback to summary
public static final BibliographyFileReader.FileFormat BIBTEX

A BibTeX file

ENDNOTEback to summary
public static final BibliographyFileReader.FileFormat ENDNOTE

An EndNote file

JSON_ARRAYback to summary
public static final BibliographyFileReader.FileFormat JSON_ARRAY

An array of CSL JSON objects

JSON_OBJECTback to summary
public static final BibliographyFileReader.FileFormat JSON_OBJECT

A CSL JSON object

RISback to summary
public static final BibliographyFileReader.FileFormat RIS

An RIS file

UNKNOWNback to summary
public static final BibliographyFileReader.FileFormat UNKNOWN

Unknown file format

YAMLback to summary
public static final BibliographyFileReader.FileFormat YAML

A YAML document

Since
1.1.0

Constructor Detail

FileFormatback to summary
private FileFormat()

Method Detail

valueOfback to summary
public static BibliographyFileReader.FileFormat valueOf(String name)
valuesback to summary
public static BibliographyFileReader.FileFormat[] values()