mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 12:17:41 +08:00
FileStorageAPI#fileExists method #PL-4817
This commit is contained in:
parent
38371b4381
commit
55c1949ce4
@ -261,6 +261,26 @@ public class FileStorage implements FileStorageAPI {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fileExists(FileDescriptor fileDescr) {
|
||||
checkNotNull(fileDescr, "No file descriptor");
|
||||
checkNotNull(fileDescr.getCreateDate(), "Empty creation date");
|
||||
|
||||
File[] roots = getStorageRoots();
|
||||
if (roots.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (File root : roots) {
|
||||
File dir = getStorageDir(root, fileDescr.getCreateDate());
|
||||
File file = new File(dir, getFileName(fileDescr));
|
||||
if (file.exists()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public File getStorageDir(File rootDir, Date createDate) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(createDate);
|
||||
|
@ -67,4 +67,11 @@ public interface FileStorageAPI {
|
||||
* @throws FileStorageException if something goes wrong
|
||||
*/
|
||||
byte[] loadFile(FileDescriptor fileDescr) throws FileStorageException;
|
||||
|
||||
/**
|
||||
* Tests whether the file denoted by this file descriptor exists.
|
||||
* @param fileDescr file descriptor
|
||||
* @return <code>true</code> if and only if the file denoted by this file descriptor exists; <code>false</code> otherwise
|
||||
*/
|
||||
boolean fileExists(FileDescriptor fileDescr);
|
||||
}
|
||||
|
@ -33,4 +33,10 @@ public class FileStorageServiceBean implements FileStorageService {
|
||||
FileStorageAPI mbean = Locator.lookup(FileStorageAPI.NAME);
|
||||
return mbean.loadFile(fileDescr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fileExists(FileDescriptor fileDescr) {
|
||||
FileStorageAPI mbean = Locator.lookup(FileStorageAPI.NAME);
|
||||
return mbean.fileExists(fileDescr);
|
||||
}
|
||||
}
|
@ -25,4 +25,6 @@ public interface FileStorageService {
|
||||
void removeFile(FileDescriptor fileDescr) throws FileStorageException;
|
||||
|
||||
byte[] loadFile(FileDescriptor fileDescr) throws FileStorageException;
|
||||
|
||||
boolean fileExists(FileDescriptor fileDescr);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user