java.io.FileDescriptor#sync ( )源码实例Demo

下面列出了java.io.FileDescriptor#sync ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

private void syncFileSystem(final FileDescriptor fd) throws SyncFailedException {
    // Simple retry a number of times; avoids Repeater to avoid complications of timeouts and separate threads
    int maxTries = 3;

    SyncFailedException sfe = null;
    for (int c = 0 ; c < maxTries ; c++) {
        try {
            fd.sync();
            sfe = null;
            break;
        } catch (SyncFailedException e) {
            sfe = e;
        }
    }
    if (sfe != null) {
        throw sfe;
    }
}
 
源代码2 项目: dttv-android   文件: FileUtils.java
/**
 * Copies bytes from the URL <code>source</code> to a file
 * <code>destination</code>. The directories up to <code>destination</code>
 * will be created if they don't already exist. <code>destination</code>
 * will be overwritten if it already exists.
 *
 * @param source  the <code>URL</code> to copy bytes from, must not be <code>null</code>
 * @param destination  the non-directory <code>File</code> to write bytes to
 *  (possibly overwriting), must not be <code>null</code>
 * @throws IOException if <code>source</code> URL cannot be opened
 * @throws IOException if <code>destination</code> is a directory
 * @throws IOException if <code>destination</code> cannot be written
 * @throws IOException if <code>destination</code> needs creating but can't be
 * @throws IOException if an IO error occurs during copying
 */
public static void copyURLToFile(URL source, File destination) throws IOException {
    InputStream input = source.openStream();
    try {
        FileOutputStream output = openOutputStream(destination);
        try {
            IOUtils.copy(input, output);
            FileDescriptor fd = output.getFD();
            if(fd.valid())
                fd.sync();
        } finally {
            IOUtils.closeQuietly(output);
        }
    } finally {
        IOUtils.closeQuietly(input);
    }
}
 
源代码3 项目: dttv-android   文件: FileUtils.java
/**
 * Copies bytes from the URL <code>source</code> to a file
 * <code>destination</code>. The directories up to <code>destination</code>
 * will be created if they don't already exist. <code>destination</code>
 * will be overwritten if it already exists.
 *
 * @param source  the <code>URL</code> to copy bytes from, must not be <code>null</code>
 * @param destination  the non-directory <code>File</code> to write bytes to
 *  (possibly overwriting), must not be <code>null</code>
 * @throws IOException if <code>source</code> URL cannot be opened
 * @throws IOException if <code>destination</code> is a directory
 * @throws IOException if <code>destination</code> cannot be written
 * @throws IOException if <code>destination</code> needs creating but can't be
 * @throws IOException if an IO error occurs during copying
 */
public static void copyURLToFile(URL source, File destination) throws IOException {
    InputStream input = source.openStream();
    try {
        FileOutputStream output = openOutputStream(destination);
        try {
            IOUtils.copy(input, output);
            FileDescriptor fd = output.getFD();
            if(fd.valid())
                fd.sync();
        } finally {
            IOUtils.closeQuietly(output);
        }
    } finally {
        IOUtils.closeQuietly(input);
    }
}
 
源代码4 项目: edslite   文件: StdFsFileIO.java
@Override
public void close() throws IOException
{
	try
	{
		FileDescriptor fd = getFD();
		if(fd!=null)
			fd.sync();
	}
	catch(SyncFailedException ignored) {}
	super.close();
}
 
源代码5 项目: vespa   文件: NativeIO.java
/**
 * Will hint the OS that data read so far will not be accessed again and should hence be dropped from the buffer cache.
 * @param fd The file descriptor to drop from buffer cache.
 */
public void dropPartialFileFromCache(FileDescriptor fd, long offset, long len, boolean sync) {
    if (sync) {
        try {
            fd.sync();
        } catch (SyncFailedException e) {
            logger.warning("Sync failed while dropping cache: " + e.getMessage());
        }
    }
    if (initialized) {
        posix_fadvise(getNativeFD(fd), offset, len, POSIX_FADV_DONTNEED);
    }
}
 
源代码6 项目: dttv-android   文件: FileUtils.java
/**
 * Internal copy file method.
 *
 * @param srcFile  the validated source file, must not be <code>null</code>
 * @param destFile  the validated destination file, must not be <code>null</code>
 * @param preserveFileDate  whether to preserve the file date
 * @throws IOException if an error occurs
 */
private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException {
    if (destFile.exists() && destFile.isDirectory()) {
        throw new IOException("Destination '" + destFile + "' exists but is a directory");
    }

    FileInputStream input = new FileInputStream(srcFile);
    try {
        FileOutputStream output = new FileOutputStream(destFile);
        try {
            IOUtils.copy(input, output);
            FileDescriptor fd = output.getFD();
            if(fd.valid())
                fd.sync();
        } finally {
            IOUtils.closeQuietly(output);
        }
    } finally {
        IOUtils.closeQuietly(input);
    }

    if (srcFile.length() != destFile.length()) {
        throw new IOException("Failed to copy full contents from '" +
                srcFile + "' to '" + destFile + "'");
    }
    if (preserveFileDate) {
        destFile.setLastModified(srcFile.lastModified());
    }
}
 
源代码7 项目: dttv-android   文件: FileUtils.java
/**
 * Internal copy file method.
 *
 * @param srcFile  the validated source file, must not be <code>null</code>
 * @param destFile  the validated destination file, must not be <code>null</code>
 * @param preserveFileDate  whether to preserve the file date
 * @throws IOException if an error occurs
 */
private static void doCopyFile(File srcFile, File destFile, boolean preserveFileDate) throws IOException {
    if (destFile.exists() && destFile.isDirectory()) {
        throw new IOException("Destination '" + destFile + "' exists but is a directory");
    }

    FileInputStream input = new FileInputStream(srcFile);
    try {
        FileOutputStream output = new FileOutputStream(destFile);
        try {
            IOUtils.copy(input, output);
            FileDescriptor fd = output.getFD();
            if(fd.valid())
                fd.sync();
        } finally {
            IOUtils.closeQuietly(output);
        }
    } finally {
        IOUtils.closeQuietly(input);
    }

    if (srcFile.length() != destFile.length()) {
        throw new IOException("Failed to copy full contents from '" +
                srcFile + "' to '" + destFile + "'");
    }
    if (preserveFileDate) {
        destFile.setLastModified(srcFile.lastModified());
    }
}
 
源代码8 项目: io   文件: BinaryDataAccessor.java
/**
 * ファイルディスクリプタの同期.
 * @param fd ファイルディスクリプタ
 * @exception SyncFailedException 同期に失敗
 */
public void sync(FileDescriptor fd) throws SyncFailedException {
    fd.sync();
}
 
源代码9 项目: io   文件: BarFileInstaller.java
/**
 * ファイルディスクリプタの同期.
 * @param fd ファイルディスクリプタ
 * @throws SyncFailedException 同期に失敗
 */
public void sync(FileDescriptor fd) throws SyncFailedException {
    fd.sync();
}