Top Fields Constructors Methods
org.jabref.logic.util.io

public Class FileNameUniqueness

extends Object
Class Inheritance
Imports
java.io.IOException, java.nio.file.Files, .Path, java.util.Objects, .Optional, java.util.regex.Matcher, .Pattern, org.jabref.gui.DialogService, org.jabref.logic.l10n.Localization, org.slf4j.Logger, .LoggerFactory

Field Summary

Modifier and TypeField and Description
private static final Pattern
private static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static String

Returns:

Suggested name for the file without extensionSuffix and duplicate marks such as " (1)"
eraseDuplicateMarks
(String
Suggested name for the file without extensionSuffix, if it has duplicate file name with other file, it will end with something like " (1)"
fileName
)

This is the opposite function of getNonOverWritingFileName It will recover the file name to origin if it has duplicate mark such as " (1)" change the String whose format is "xxxxxx (number)" into "xxxxxx", while return the same String when it does not match the format This is the opposite function of getNonOverWritingFileName

public static Path
public static String

Returns:

a file name such that it does not match any existing files in targetDirectory
getNonOverWritingFileName
(Path
The directory in which file name should be unique
targetDirectory
,
String
Suggested name for the file
fileName
)

Returns a file name such that it does not match any existing files in targetDirectory

public static boolean

Returns:

true when the content of the newly downloaded file is same as the file with "similar" name, false when there is no "similar" file name or the content is different from that of files with "similar" name
isDuplicatedFile
(Path
The directory which saves the files (.pdf, for example)
directory
,
Path
Suggest name for the newly downloaded file
fileName
,
DialogService
To display the error and success message
dialogService
)

This function decide whether the newly downloaded file has the same content with other files It returns ture when the content is duplicate, while returns false if it is not

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DUPLICATE_MARK_PATTERNback to summary
private static final Pattern DUPLICATE_MARK_PATTERN
LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

FileNameUniquenessback to summary
public FileNameUniqueness()

Method Detail

eraseDuplicateMarksback to summary
public static String eraseDuplicateMarks(String fileName)

This is the opposite function of getNonOverWritingFileName It will recover the file name to origin if it has duplicate mark such as " (1)" change the String whose format is "xxxxxx (number)" into "xxxxxx", while return the same String when it does not match the format This is the opposite function of getNonOverWritingFileName

Parameters
fileName:String

Suggested name for the file without extensionSuffix, if it has duplicate file name with other file, it will end with something like " (1)"

Returns:String

Suggested name for the file without extensionSuffix and duplicate marks such as " (1)"

eraseDuplicateMarksback to summary
public static Path eraseDuplicateMarks(Path filePath)
getNonOverWritingFileNameback to summary
public static String getNonOverWritingFileName(Path targetDirectory, String fileName)

Returns a file name such that it does not match any existing files in targetDirectory

Parameters
targetDirectory:Path

The directory in which file name should be unique

fileName:String

Suggested name for the file

Returns:String

a file name such that it does not match any existing files in targetDirectory

isDuplicatedFileback to summary
public static boolean isDuplicatedFile(Path directory, Path fileName, DialogService dialogService) throws IOException

This function decide whether the newly downloaded file has the same content with other files It returns ture when the content is duplicate, while returns false if it is not

Parameters
directory:Path

The directory which saves the files (.pdf, for example)

fileName:Path

Suggest name for the newly downloaded file

dialogService:DialogService

To display the error and success message

Returns:boolean

true when the content of the newly downloaded file is same as the file with "similar" name, false when there is no "similar" file name or the content is different from that of files with "similar" name

Exceptions
IOException:
Fail when the file is not exist or something wrong when reading the file