Files
briar/briar-tests/src/org/briarproject/TestDatabaseConfig.java
akwizgran 53d0b8b21e Check whether File#listFiles() returns null.
The docs say this can happen for a directory if there's an I/O error.
2016-09-27 15:52:57 +01:00

46 lines
882 B
Java

package org.briarproject;
import org.briarproject.api.crypto.SecretKey;
import org.briarproject.api.db.DatabaseConfig;
import java.io.File;
public class TestDatabaseConfig implements DatabaseConfig {
private final File dir;
private final long maxSize;
private volatile SecretKey key = new SecretKey(new byte[SecretKey.LENGTH]);
public TestDatabaseConfig(File dir, long maxSize) {
this.dir = dir;
this.maxSize = maxSize;
}
@Override
public boolean databaseExists() {
if (!dir.isDirectory()) return false;
File[] files = dir.listFiles();
return files != null && files.length > 0;
}
@Override
public File getDatabaseDirectory() {
return dir;
}
@Override
public void setEncryptionKey(SecretKey key) {
this.key = key;
}
@Override
public SecretKey getEncryptionKey() {
return key;
}
@Override
public long getMaxSize() {
return maxSize;
}
}