1
1
package org .jabref .logic .importer ;
2
2
3
- import java .io .File ;
4
3
import java .io .IOException ;
4
+ import java .nio .file .Files ;
5
+ import java .nio .file .Path ;
6
+ import java .nio .file .Paths ;
5
7
import java .util .Arrays ;
6
8
import java .util .List ;
7
9
@@ -29,31 +31,26 @@ private OpenDatabase() {
29
31
*
30
32
* @param name Name of the BIB-file to open
31
33
* @return ParserResult which never is null
34
+ * @deprecated use {@link #loadDatabase(Path, ImportFormatPreferences, FileUpdateMonitor)} instead
32
35
*/
36
+ @ Deprecated
33
37
public static ParserResult loadDatabase (String name , ImportFormatPreferences importFormatPreferences , FileUpdateMonitor fileMonitor ) {
34
- File file = new File ( name );
35
- LOGGER . info ( "Opening: " + name );
38
+ LOGGER . debug ( "Opening: " + name );
39
+ Path file = Paths . get ( name );
36
40
37
- if (!file .exists ()) {
41
+ if (!Files .exists (file )) {
38
42
ParserResult pr = ParserResult .fromErrorMessage (Localization .lang ("File not found" ));
39
- pr .setFile (file );
43
+ pr .setFile (file . toFile () );
40
44
41
45
LOGGER .error (Localization .lang ("Error" ) + ": " + Localization .lang ("File not found" ));
42
46
return pr ;
43
47
}
44
48
45
49
try {
46
- ParserResult pr = OpenDatabase .loadDatabase (file , importFormatPreferences , fileMonitor );
47
- pr .setFile (file );
48
- if (pr .hasWarnings ()) {
49
- for (String aWarn : pr .warnings ()) {
50
- LOGGER .warn (aWarn );
51
- }
52
- }
53
- return pr ;
50
+ return OpenDatabase .loadDatabase (file , importFormatPreferences , fileMonitor );
54
51
} catch (IOException ex ) {
55
52
ParserResult pr = ParserResult .fromError (ex );
56
- pr .setFile (file );
53
+ pr .setFile (file . toFile () );
57
54
LOGGER .error ("Problem opening .bib-file" , ex );
58
55
return pr ;
59
56
}
@@ -62,9 +59,9 @@ public static ParserResult loadDatabase(String name, ImportFormatPreferences imp
62
59
/**
63
60
* Opens a new database.
64
61
*/
65
- public static ParserResult loadDatabase (File fileToOpen , ImportFormatPreferences importFormatPreferences , FileUpdateMonitor fileMonitor )
62
+ public static ParserResult loadDatabase (Path fileToOpen , ImportFormatPreferences importFormatPreferences , FileUpdateMonitor fileMonitor )
66
63
throws IOException {
67
- ParserResult result = new BibtexImporter (importFormatPreferences , fileMonitor ).importDatabase (fileToOpen . toPath () ,
64
+ ParserResult result = new BibtexImporter (importFormatPreferences , fileMonitor ).importDatabase (fileToOpen ,
68
65
importFormatPreferences .getEncoding ());
69
66
70
67
if (importFormatPreferences .isKeywordSyncEnabled ()) {
0 commit comments