FileStorageAPI#fileExists method #PL-4817

This commit is contained in:
Gleb Gorelov 2015-02-09 08:21:52 +00:00
parent 38371b4381
commit 55c1949ce4
4 changed files with 35 additions and 0 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -25,4 +25,6 @@ public interface FileStorageService {
void removeFile(FileDescriptor fileDescr) throws FileStorageException;
byte[] loadFile(FileDescriptor fileDescr) throws FileStorageException;
boolean fileExists(FileDescriptor fileDescr);
}