Verified Owner
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.Optional, org.jabref.logic.exporter.SaveConfiguration, org.jabref.logic.importer.ImportFormatPreferences, .Importer, .KeywordImportNormalizer, .ParserResult, org.jabref.logic.l10n.Localization, org.jabref.logic.util.StandardFileType, org.jabref.model.database.BibDatabaseModeDetection, org.jabref.model.util.FileUpdateMonitor, org.jspecify.annotations.NonNull, 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
public 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
getId()

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

Returns a slug, which identifies this importer.

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 filePath)

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

Parse the database in the specified file.

public ParserResult
public ParserResult
importDatabase(@NonNull BufferedReader 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
(@NonNull BufferedReader reader)

Overrides org.jabref.logic.importer.Importer.isRecognizedFormat.

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

private void
normalizeKeywordDelimiters(ParserResult result)

Postprocessing for imported entries that normalizes keyword separators to the library's delimiter.

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

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 isRecognizedFormat(BufferedReader) recognizes an 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

Annotations
@Override
getIdback to summary
public String getId()

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

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

Returns a slug, which identifies this importer. Used, for example, to identify the importer in CLI.

Typically, this name should be short, in English, and should not contain special characters like #, %, etc.

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. Typically, this is a string that denotes file type or format. It can also be localized, like "XMP-annotated PDF".

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.

Annotations
@Override
importDatabaseback to summary
public ParserResult importDatabase(InputStream filePath, BibtexImporter.EncodingResult result) throws IOException
importDatabaseback to summary
public ParserResult importDatabase(@NonNull 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

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

Overrides 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.

All implementations need to reset the input stream to the beginning again - to enable importing at subsequent calls.

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 behavior 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
normalizeKeywordDelimitersback to summary
private void normalizeKeywordDelimiters(ParserResult result)

Postprocessing for imported entries that normalizes keyword separators to the library's delimiter.

org.jabref.logic.importer.fileformat back to summary

public 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
public
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 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
public 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).
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.

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.