本文整理汇总了Java中java.io.FileDescriptor.sync方法的典型用法代码示例。如果您正苦于以下问题:Java FileDescriptor.sync方法的具体用法?Java FileDescriptor.sync怎么用?Java FileDescriptor.sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.FileDescriptor
的用法示例。
在下文中一共展示了FileDescriptor.sync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sync
import java.io.FileDescriptor; //导入方法依赖的package包/类
private void sync(BufferedOutputStream outputStream, FileDescriptor fileDescriptor) {
boolean success;
try {
outputStream.flush();
fileDescriptor.sync();
success = true;
} catch (IOException e) {
success = false;
e.printStackTrace();
}
if (success && isResumeSupported) {
ComponentHolder.getInstance().getDbHelper()
.updateProgress(request.getDownloadId(),
request.getDownloadedBytes(),
System.currentTimeMillis());
}
}
示例2: updateProgress
import java.io.FileDescriptor; //导入方法依赖的package包/类
/**
* Report download progress through the database if necessary.
*/
private void updateProgress(FileDescriptor outFd) throws IOException, StopRequestException {
final long now = SystemClock.elapsedRealtime();
final long currentBytes = mInfoDelta.mCurrentBytes;
final long sampleDelta = now - mSpeedSampleStart;
if (sampleDelta > 500) {
final long sampleSpeed = ((currentBytes - mSpeedSampleBytes) * 1000)
/ sampleDelta;
if (mSpeed == 0) {
mSpeed = sampleSpeed;
} else {
mSpeed = ((mSpeed * 3) + sampleSpeed) / 4;
}
// Only notify once we have a full sample window
if (mSpeedSampleStart != 0) {
mNotifier.notifyDownloadSpeed(mId, mSpeed);
}
mSpeedSampleStart = now;
mSpeedSampleBytes = currentBytes;
}
final long bytesDelta = currentBytes - mLastUpdateBytes;
final long timeDelta = now - mLastUpdateTime;
if (bytesDelta > Constants.MIN_PROGRESS_STEP && timeDelta > Constants.MIN_PROGRESS_TIME) {
// fsync() to ensure that current progress has been flushed to disk,
// so we can always resume based on latest database information.
outFd.sync();
mInfoDelta.writeToDatabaseOrThrow();
mLastUpdateBytes = currentBytes;
mLastUpdateTime = now;
}
}
示例3: sync
import java.io.FileDescriptor; //导入方法依赖的package包/类
/**
* ファイルディスクリプタの同期.
* @param fd ファイルディスクリプタ
* @throws SyncFailedException 同期に失敗
*/
public void sync(FileDescriptor fd) throws SyncFailedException {
fd.sync();
}