本文整理匯總了Java中com.trollworks.toolkit.io.SafeFileUpdater類的典型用法代碼示例。如果您正苦於以下問題:Java SafeFileUpdater類的具體用法?Java SafeFileUpdater怎麽用?Java SafeFileUpdater使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SafeFileUpdater類屬於com.trollworks.toolkit.io包,在下文中一共展示了SafeFileUpdater類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: save
import com.trollworks.toolkit.io.SafeFileUpdater; //導入依賴的package包/類
/**
* Saves the data out to the specified file. Does not affect the result of {@link #getFile()}.
*
* @param file The file to write to.
* @return <code>true</code> on success.
*/
public boolean save(File file) {
SafeFileUpdater transaction = new SafeFileUpdater();
boolean success = false;
transaction.begin();
try {
File transactionFile = transaction.getTransactionFile(file);
try (XMLWriter out = new XMLWriter(new BufferedOutputStream(new FileOutputStream(transactionFile)))) {
out.writeHeader();
save(out, true, false);
success = !out.checkError();
}
if (success) {
success = false;
transaction.commit();
setModified(false);
success = true;
} else {
transaction.abort();
}
} catch (Exception exception) {
Log.error(exception);
transaction.abort();
}
return success;
}
示例2: save
import com.trollworks.toolkit.io.SafeFileUpdater; //導入依賴的package包/類
/**
* Saves the preference information to disk.
*
* @return Whether the save was successful or not.
*/
public boolean save() {
if (mDirty) {
try {
SafeFileUpdater trans = new SafeFileUpdater();
trans.begin();
try {
File file = trans.getTransactionFile(mFile);
try (OutputStream out = new FileOutputStream(file)) {
mPrefs.storeToXML(out, BundleInfo.getDefault().getName());
}
} catch (IOException ioe) {
trans.abort();
throw ioe;
}
trans.commit();
mDirty = false;
} catch (Exception exception) {
return false;
}
}
return true;
}