本文整理汇总了Java中org.h2.store.fs.FileUtils.exists方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.exists方法的具体用法?Java FileUtils.exists怎么用?Java FileUtils.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.store.fs.FileUtils
的用法示例。
在下文中一共展示了FileUtils.exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMoveTo
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private static void testMoveTo(String fsBase) {
final String fileName = fsBase + "/testFile";
final String fileName2 = fsBase + "/testFile2";
if (FileUtils.exists(fileName)) {
FileUtils.delete(fileName);
}
if (FileUtils.createFile(fileName)) {
FileUtils.move(fileName, fileName2);
FileUtils.createFile(fileName);
new AssertThrows(DbException.class) {
@Override
public void test() {
FileUtils.move(fileName2, fileName);
}};
FileUtils.delete(fileName);
FileUtils.delete(fileName2);
new AssertThrows(DbException.class) {
@Override
public void test() {
FileUtils.move(fileName, fileName2);
}};
}
}
示例2: openWriter
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private boolean openWriter() {
if (printWriter == null) {
try {
FileUtils.createDirectories(FileUtils.getParent(fileName));
if (FileUtils.exists(fileName) && !FileUtils.canWrite(fileName)) {
// read only database: don't log error if the trace file
// can't be opened
return false;
}
fileWriter = IOUtils.getBufferedWriter(
FileUtils.newOutputStream(fileName, true));
printWriter = new PrintWriter(fileWriter, true);
} catch (Exception e) {
logWritingError(e);
return false;
}
}
return true;
}
示例3: openFile
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
@Override
public FileStore openFile(String name, String mode, boolean mustExist) {
if (mustExist && !FileUtils.exists(name)) {
throw DbException.get(ErrorCode.FILE_NOT_FOUND_1, name);
}
FileStore store;
if (cipher == null) {
store = FileStore.open(this, name, mode);
} else {
store = FileStore.open(this, name, mode, cipher, fileEncryptionKey, 0);
}
store.setCheckedWriting(false);
try {
store.init();
} catch (DbException e) {
store.closeSilently();
throw e;
}
return store;
}
示例4: loadProperties
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
* Load a properties object from a file.
*
* @param fileName the name of the properties file
* @return the properties object
*/
public static synchronized SortedProperties loadProperties(String fileName)
throws IOException {
SortedProperties prop = new SortedProperties();
if (FileUtils.exists(fileName)) {
InputStream in = null;
try {
in = FileUtils.newInputStream(fileName);
prop.load(in);
} finally {
if (in != null) {
in.close();
}
}
}
return prop;
}
示例5: deleteFile
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
* Delete the given file now. This will remove the reference from the list.
*
* @param ref the reference as returned by addFile
* @param fileName the file name
*/
public synchronized void deleteFile(Reference<?> ref, String fileName) {
if (ref != null) {
String f2 = refMap.remove(ref);
if (f2 != null) {
if (SysProperties.CHECK) {
if (fileName != null && !f2.equals(fileName)) {
DbException.throwInternalError("f2:" + f2 + " f:" + fileName);
}
}
fileName = f2;
}
}
if (fileName != null && FileUtils.exists(fileName)) {
try {
IOUtils.trace("TempFileDeleter.deleteFile", fileName, null);
FileUtils.tryDelete(fileName);
} catch (Exception e) {
// TODO log such errors?
}
}
}
示例6: FileStore
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
* Create a new file using the given settings.
*
* @param handler the callback object
* @param name the file name
* @param mode the access mode ("r", "rw", "rws", "rwd")
*/
protected FileStore(DataHandler handler, String name, String mode) {
this.handler = handler;
this.name = name;
try {
boolean exists = FileUtils.exists(name);
if (exists && !FileUtils.canWrite(name)) {
mode = "r";
} else {
FileUtils.createDirectories(FileUtils.getParent(name));
}
file = FileUtils.open(name, mode);
if (exists) {
fileLength = file.size();
}
} catch (IOException e) {
throw DbException.convertIOException(
e, "name: " + name + " mode: " + mode);
}
this.mode = mode;
}
示例7: open
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
* Open the file and read the header.
*/
public synchronized void open() {
try {
metaRootPageId.put(META_TABLE_ID, PAGE_ID_META_ROOT);
if (FileUtils.exists(fileName)) {
long length = FileUtils.size(fileName);
if (length < MIN_PAGE_COUNT * PAGE_SIZE_MIN) {
if (database.isReadOnly()) {
throw DbException.get(
ErrorCode.FILE_CORRUPTED_1, fileName + " length: " + length);
}
// the database was not fully created
openNew();
} else {
openExisting();
}
} else {
openNew();
}
} catch (DbException e) {
close();
throw e;
}
}
示例8: cat
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private void cat(String fileName, long length) {
if (!FileUtils.exists(fileName)) {
print("No such file: " + fileName);
}
if (FileUtils.isDirectory(fileName)) {
print("Is a directory: " + fileName);
}
InputStream inFile = null;
try {
inFile = FileUtils.newInputStream(fileName);
IOUtils.copy(inFile, out, length);
} catch (IOException e) {
error(e);
} finally {
IOUtils.closeSilently(inFile);
}
println("");
}
示例9: readFileList
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private int readFileList(String[] list, int i, ArrayList<String> target,
boolean recursive) throws IOException {
while (i < list.length) {
String c = list[i++];
if (";".equals(c)) {
break;
}
c = getFile(c);
if (!FileUtils.exists(c)) {
throw new IOException("File not found: " + c);
}
if (recursive) {
addFilesRecursive(c, target);
} else {
target.add(c);
}
}
return i;
}
示例10: testDirectories
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
private static void testDirectories(String fsBase) {
final String fileName = fsBase + "/testFile";
if (FileUtils.exists(fileName)) {
FileUtils.delete(fileName);
}
if (FileUtils.createFile(fileName)) {
new AssertThrows(DbException.class) {
@Override
public void test() {
FileUtils.createDirectory(fileName);
}};
new AssertThrows(DbException.class) {
@Override
public void test() {
FileUtils.createDirectories(fileName + "/test");
}};
FileUtils.delete(fileName);
}
}
示例11: compactCleanUp
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
* Clean up if needed, in a case a compact operation was interrupted due to
* killing the process or a power failure. This will delete temporary files
* (if any), and in case atomic file replacements were not used, rename the
* new file.
*
* @param fileName the file name
*/
public static void compactCleanUp(String fileName) {
String tempName = fileName + Constants.SUFFIX_MV_STORE_TEMP_FILE;
if (FileUtils.exists(tempName)) {
FileUtils.delete(tempName);
}
String newName = fileName + Constants.SUFFIX_MV_STORE_NEW_FILE;
if (FileUtils.exists(newName)) {
if (FileUtils.exists(fileName)) {
FileUtils.delete(newName);
} else {
FileUtils.move(newName, fileName);
}
}
}
示例12: close
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
* Close the store. Pending changes are persisted. Chunks with a low
* fill rate are compacted, but old chunks are kept for some time, so
* most likely the database file will not shrink.
*
* @param maxCompactTime the maximum time in milliseconds to compact
*/
public void close(long maxCompactTime) {
try {
if (!store.isClosed() && store.getFileStore() != null) {
boolean compactFully = false;
if (!store.getFileStore().isReadOnly()) {
transactionStore.close();
if (maxCompactTime == Long.MAX_VALUE) {
compactFully = true;
}
}
String fileName = store.getFileStore().getFileName();
store.close();
if (compactFully && FileUtils.exists(fileName)) {
// the file could have been deleted concurrently,
// so only compact if the file still exists
MVStoreTool.compact(fileName, true);
}
}
} catch (IllegalStateException e) {
int errorCode = DataUtils.getErrorCode(e.getMessage());
if (errorCode == DataUtils.ERROR_WRITING_FAILED) {
// disk full - ok
} else if (errorCode == DataUtils.ERROR_FILE_CORRUPT) {
// wrong encryption key - ok
}
store.closeImmediately();
throw DbException.get(ErrorCode.IO_EXCEPTION_1, e, "Closing");
}
}
示例13: connectOrUpgrade
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
* If the upgrade classes are present, upgrade the database, or connect
* using the old version (if the parameter NO_UPGRADE is set to true). If
* the database is upgraded, or if no upgrade is possible or needed, this
* methods returns null.
*
* @param url the database URL
* @param info the properties
* @return the connection if connected with the old version (NO_UPGRADE)
*/
public static Connection connectOrUpgrade(String url, Properties info)
throws SQLException {
if (!UPGRADE_CLASSES_PRESENT) {
return null;
}
Properties i2 = new Properties();
i2.putAll(info);
// clone so that the password (if set as a char array) is not cleared
Object o = info.get("password");
if (o instanceof char[]) {
i2.put("password", StringUtils.cloneCharArray((char[]) o));
}
info = i2;
ConnectionInfo ci = new ConnectionInfo(url, info);
if (ci.isRemote() || !ci.isPersistent()) {
return null;
}
String name = ci.getName();
if (FileUtils.exists(name + Constants.SUFFIX_PAGE_FILE)) {
return null;
}
if (!FileUtils.exists(name + Constants.SUFFIX_OLD_DATABASE_FILE)) {
return null;
}
if (ci.removeProperty("NO_UPGRADE", false)) {
return connectWithOldVersion(url, info);
}
synchronized (DbUpgrade.class) {
upgrade(ci, info);
return null;
}
}
示例14: getName
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
* Get the unique and normalized database name (excluding settings).
*
* @return the database name
*/
public String getName() {
if (persistent) {
if (nameNormalized == null) {
if (!SysProperties.IMPLICIT_RELATIVE_PATH) {
if (!FileUtils.isAbsolute(name)) {
if (name.indexOf("./") < 0 &&
name.indexOf(".\\") < 0 &&
name.indexOf(":/") < 0 &&
name.indexOf(":\\") < 0) {
// the name could start with "./", or
// it could start with a prefix such as "nio:./"
// for Windows, the path "\test" is not considered
// absolute as the drive letter is missing,
// but we consider it absolute
throw DbException.get(
ErrorCode.URL_RELATIVE_TO_CWD,
originalURL);
}
}
}
String suffix = Constants.SUFFIX_PAGE_FILE;
String n;
if (FileUtils.exists(name + suffix)) {
n = FileUtils.toRealPath(name + suffix);
} else {
suffix = Constants.SUFFIX_MV_FILE;
n = FileUtils.toRealPath(name + suffix);
}
String fileName = FileUtils.getName(n);
if (fileName.length() < suffix.length() + 1) {
throw DbException.get(ErrorCode.INVALID_DATABASE_NAME_1, name);
}
nameNormalized = n.substring(0, n.length() - suffix.length());
}
return nameNormalized;
}
return name;
}
示例15: exists
import org.h2.store.fs.FileUtils; //导入方法依赖的package包/类
/**
* Check if a database with the given name exists.
*
* @param name the name of the database (including path)
* @return true if one exists
*/
static boolean exists(String name) {
if (FileUtils.exists(name + Constants.SUFFIX_PAGE_FILE)) {
return true;
}
return FileUtils.exists(name + Constants.SUFFIX_MV_FILE);
}