Top Description Inners Fields Constructors Methods
org.jabref.logic.importer.fileformat

public Class BibtexImporter

extends Importer
Class Inheritance
Imports
java.io.BufferedInputStream, .BufferedReader, .IOException, .InputStream, .InputStreamReader, java.nio.charset.Charset, .CharsetDecoder, .CodingErrorAction, java.nio.file.Files, .Path, java.util.Objects, .Optional, org.jabref.logic.exporter.SaveConfiguration, org.jabref.logic.importer.ImportFormatPreferences, .Importer, .ParserResult, org.jabref.logic.util.StandardFileType, org.jabref.model.database.BibDatabaseModeDetection, org.jabref.model.util.FileUpdateMonitor, org.slf4j.Logger, .LoggerFactory

This is a full class to read .bib files. It is used for --import and --importToOpen , too.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record

Field Summary

Modifier and TypeField and Description
private final FileUpdateMonitor
private final ImportFormatPreferences
private static final Logger
private static final String

Constructor Summary

AccessConstructor and Description
public
BibtexImporter(ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor)

Method Summary

Modifier and TypeMethod and Description
public String
getDescription()

Implements abstract org.jabref.logic.importer.Importer.getDescription.

Returns the description of the import format.

public static Charset
getEncoding(Path filePath)

private static BibtexImporter.EncodingResult
getEncodingResult(Path filePath)

Determines the encoding of the supplied BibTeX file.

public StandardFileType
getFileType()

Implements abstract org.jabref.logic.importer.Importer.getFileType.

Returns the type of files that this importer can read

public String
getName()

Implements abstract org.jabref.logic.importer.Importer.getName.

Returns the name of this import format.

private static Optional<Charset>
getSuppliedEncoding(BufferedReader reader)

Searches the file for "Encoding: myEncoding" and returns the found supplied encoding.

public ParserResult
importDatabase(Path
the path to the file which should be imported
filePath
)

Overrides org.jabref.logic.importer.Importer.importDatabase.

Parse the database in the specified file.

public ParserResult
importDatabase(BufferedReader
the input to read from
reader
)

Implements abstract org.jabref.logic.importer.Importer.importDatabase.

This method does not set the metadata encoding information.

public boolean

Returns:

true as we have no effective way to decide whether a file is in bibtex format or not. See https://github.com/JabRef/jabref/pull/379#issuecomment-158685726 for more details.
isRecognizedFormat
(BufferedReader reader)

Implements abstract org.jabref.logic.importer.Importer.isRecognizedFormat.

Check whether the source is in the correct format for this importer.

Inherited from org.jabref.logic.importer.Importer:
compareToequalsgetCharsetgetIdgetReadergetReaderhashCodeimportDatabaseisRecognizedFormatisRecognizedFormattoString

Field Detail

fileMonitorback to summary
private final FileUpdateMonitor fileMonitor
importFormatPreferencesback to summary
private final ImportFormatPreferences importFormatPreferences
LOGGERback to summary
private static final Logger LOGGER

Hides org.jabref.logic.importer.Importer.LOGGER.

SIGNATUREback to summary
private static final String SIGNATURE

Constructor Detail

BibtexImporterback to summary
public BibtexImporter(ImportFormatPreferences importFormatPreferences, FileUpdateMonitor fileMonitor)

Method Detail

getDescriptionback to summary
public String getDescription()

Implements abstract org.jabref.logic.importer.Importer.getDescription.

Doc from org.jabref.logic.importer.Importer.getDescription.

Returns the description of the import format.

The description should specify

  • what kind of entries from what sources and based on what specification it is able to import
  • by what criteria it recognizes an import format
Returns:String

description of the import format

Annotations
@Override
getEncodingback to summary
public static Charset getEncoding(Path filePath) throws IOException
getEncodingResultback to summary
private static BibtexImporter.EncodingResult getEncodingResult(Path filePath) throws IOException

Determines the encoding of the supplied BibTeX file. If a JabRef encoding information is present, this information is used. If there is none present, com.ibm.icu.text.CharsetDetector#CharsetDetector() is used.

getFileTypeback to summary
public StandardFileType getFileType()

Implements abstract org.jabref.logic.importer.Importer.getFileType.

Doc from org.jabref.logic.importer.Importer.getFileType.

Returns the type of files that this importer can read

Returns:StandardFileType

FileType corresponding to the importer

Annotations
@Override
getNameback to summary
public String getName()

Implements abstract org.jabref.logic.importer.Importer.getName.

Doc from org.jabref.logic.importer.Importer.getName.

Returns the name of this import format.

The name must be unique.

Returns:String

format name, must be unique and not null

Annotations
@Override
getSuppliedEncodingback to summary
private static Optional<Charset> getSuppliedEncoding(BufferedReader reader)

Searches the file for "Encoding: myEncoding" and returns the found supplied encoding.

importDatabaseback to summary
public ParserResult importDatabase(Path filePath) throws IOException

Overrides org.jabref.logic.importer.Importer.importDatabase.

Doc from org.jabref.logic.importer.Importer.importDatabase.

Parse the database in the specified file.

Parameters
filePath:Path

the path to the file which should be imported

Annotations
@Override
importDatabaseback to summary
public ParserResult importDatabase(BufferedReader reader) throws IOException

Implements abstract org.jabref.logic.importer.Importer.importDatabase.

This method does not set the metadata encoding information. The caller needs to set the encoding of the supplied reader manually to the metadata

Parameters
reader:BufferedReader

Doc from org.jabref.logic.importer.Importer.importDatabase.

the input to read from

Annotations
@Override
isRecognizedFormatback to summary
public boolean isRecognizedFormat(BufferedReader reader)

Implements abstract org.jabref.logic.importer.Importer.isRecognizedFormat.

Doc from org.jabref.logic.importer.Importer.isRecognizedFormat.

Check whether the source is in the correct format for this importer.

The effect of this method is primarily to avoid unnecessary processing of files when searching for a suitable import format. If this method returns false, the import routine will move on to the next import format.

Thus, the correct behaviour is to return false if it is certain that the file is not of the suitable type, and true otherwise. Returning true is the safe choice if not certain.

Returns:boolean

true as we have no effective way to decide whether a file is in bibtex format or not. See https://github.com/JabRef/jabref/pull/379#issuecomment-158685726 for more details.

Annotations
@Override
org.jabref.logic.importer.fileformat back to summary

private final Record BibtexImporter.EncodingResult

extends Record
Class Inheritance
Record Components
encoding:Charset 
encodingExplicitlySupplied:boolean 

Field Summary

Modifier and TypeField and Description
private final Charset
encoding

Record Component accessed by encoding().

private final boolean

Constructor Summary

AccessConstructor and Description
private
EncodingResult(Charset encoding, boolean encodingExplicitlySupplied)

Method Summary

Modifier and TypeMethod and Description
public Charset
encoding()

Record Component getter of encoding.

public boolean
public final boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

encodingback to summary
private final Charset encoding

Record Component accessed by encoding().

encodingExplicitlySuppliedback to summary
private final boolean encodingExplicitlySupplied

Record Component accessed by encodingExplicitlySupplied().

Constructor Detail

EncodingResultback to summary
private EncodingResult(Charset encoding, boolean encodingExplicitlySupplied)

Method Detail

encodingback to summary
public Charset encoding()

Record Component getter of encoding.

encodingExplicitlySuppliedback to summary
public boolean encodingExplicitlySupplied()

Record Component getter of encodingExplicitlySupplied.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Returns:String

a string representation of the object.