下面列出了android.util.AtomicFile#exists ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void readEvents() {
synchronized (mEventsLock) {
// Read might prune events so mark as dirty.
mEventsDirty = true;
mEvents.clear();
final AtomicFile readFrom = mInjector.getFile(EVENTS_FILE);
if (readFrom != null && readFrom.exists()) {
FileInputStream input = null;
try {
input = readFrom.openRead();
readEventsLocked(input);
} catch (IOException e) {
readFrom.delete();
Slog.e(TAG, "Failed to read change mEvents.", e);
} finally {
IoUtils.closeQuietly(input);
}
}
}
}
private void readAmbientBrightnessStats() {
mAmbientBrightnessStatsTracker = new AmbientBrightnessStatsTracker(mUserManager, null);
final AtomicFile readFrom = mInjector.getFile(AMBIENT_BRIGHTNESS_STATS_FILE);
if (readFrom != null && readFrom.exists()) {
FileInputStream input = null;
try {
input = readFrom.openRead();
mAmbientBrightnessStatsTracker.readStats(input);
} catch (IOException e) {
readFrom.delete();
Slog.e(TAG, "Failed to read ambient brightness stats.", e);
} finally {
IoUtils.closeQuietly(input);
}
}
}
private void writeEvents() {
synchronized (mEventsLock) {
if (!mEventsDirty) {
// Nothing to write
return;
}
final AtomicFile writeTo = mInjector.getFile(EVENTS_FILE);
if (writeTo == null) {
return;
}
if (mEvents.isEmpty()) {
if (writeTo.exists()) {
writeTo.delete();
}
mEventsDirty = false;
} else {
FileOutputStream output = null;
try {
output = writeTo.startWrite();
writeEventsLocked(output);
writeTo.finishWrite(output);
mEventsDirty = false;
} catch (IOException e) {
writeTo.failWrite(output);
Slog.e(TAG, "Failed to write change mEvents.", e);
}
}
}
}