当前位置: 首页>>代码示例>>Java>>正文


Java MappedByteBuffer.force方法代码示例

本文整理汇总了Java中java.nio.MappedByteBuffer.force方法的典型用法代码示例。如果您正苦于以下问题:Java MappedByteBuffer.force方法的具体用法?Java MappedByteBuffer.force怎么用?Java MappedByteBuffer.force使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.MappedByteBuffer的用法示例。


在下文中一共展示了MappedByteBuffer.force方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeFileFromBytesByMap

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
/**
 * 将字节数组写入文件
 *
 * @param file    文件
 * @param bytes   字节数组
 * @param append  是否追加在文件末
 * @param isForce 是否写入文件
 * @return {@code true}: 写入成功<br>{@code false}: 写入失败
 */
public static boolean writeFileFromBytesByMap(final File file, final byte[] bytes, final boolean append, final boolean isForce) {
    if (bytes == null || !createOrExistsFile(file)) return false;
    FileChannel fc = null;
    try {
        fc = new FileOutputStream(file, append).getChannel();
        MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, fc.size(), bytes.length);
        mbb.put(bytes);
        if (isForce) mbb.force();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } finally {
        CloseUtils.closeIO(fc);
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:FileIOUtils.java

示例2: writeFileFromBytesByMap

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
/**
 * 将字节数组写入文件
 *
 * @param file    文件
 * @param bytes   字节数组
 * @param append  是否追加在文件末
 * @param isForce 是否写入文件
 * @return {@code true}: 写入成功<br>{@code false}: 写入失败
 */
public static boolean writeFileFromBytesByMap(File file, final byte[] bytes, boolean append, boolean isForce) {
    if (bytes == null || !FileUtils.createOrExistsFile(file)) return false;
    if (!append && !FileUtils.createFileByDeleteOldFile(file)) return false;
    FileChannel fc = null;
    try {
        fc = new RandomAccessFile(file, "rw").getChannel();
        MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, fc.size(), bytes.length);
        mbb.put(bytes);
        if (isForce) mbb.force();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } finally {
        CloseUtils.closeIO(fc);
    }
}
 
开发者ID:hoangkien0705,项目名称:Android-UtilCode,代码行数:27,代码来源:FileIOUtils.java

示例3: writeFileFromBytesByMap

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
/**
 * 将字节数组写入文件
 *
 * @param file    文件
 * @param bytes   字节数组
 * @param append  是否追加在文件末
 * @param isForce 是否写入文件
 * @return {@code true}: 写入成功<br>{@code false}: 写入失败
 */
public static boolean writeFileFromBytesByMap(File file, final byte[] bytes, boolean append, boolean isForce) {
    if (bytes == null || !FileUtils.createOrExistsFile(file)) return false;
    FileChannel fc = null;
    try {
        fc = new FileOutputStream(file, append).getChannel();
        MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, fc.size(), bytes.length);
        mbb.put(bytes);
        if (isForce) mbb.force();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } finally {
        CloseUtils.closeIO(fc);
    }
}
 
开发者ID:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:26,代码来源:FileIOUtils.java

示例4: writeFileFromBytesByMap

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
/**
 * 将字节数组写入文件
 *
 * @param file    文件
 * @param bytes   字节数组
 * @param append  是否追加在文件末
 * @param isForce 是否写入文件
 * @return {@code true}: 写入成功<br>{@code false}: 写入失败
 */
public static boolean writeFileFromBytesByMap(final File file, final byte[] bytes, final boolean append, final boolean isForce) {
	if (bytes == null || !createOrExistsFile(file)) {
		return false;
	}
	FileChannel fc = null;
	try {
		fc = new FileOutputStream(file, append).getChannel();
		MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, fc.size(), bytes.length);
		mbb.put(bytes);
		if (isForce) {
			mbb.force();
		}
		return true;
	} catch (IOException e) {
		e.printStackTrace();
		return false;
	} finally {
		CloseUtils.closeIO(fc);
	}
}
 
开发者ID:MobClub,项目名称:BBSSDK-for-Android,代码行数:30,代码来源:FileIOUtils.java

示例5: force

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
public static MappedByteBuffer force(MappedByteBuffer buf)
{
    Preconditions.checkNotNull(buf);
    if (SKIP_SYNC)
    {
        Object fd = null;
        try
        {
            if (mbbFDField != null)
            {
                fd = mbbFDField.get(buf);
            }
        }
        catch (Exception e)
        {
            throw new RuntimeException(e);
        }
        //This is what MappedByteBuffer.force() throws if a you call force() on an umapped buffer
        if (mbbFDField != null && fd == null)
            throw new UnsupportedOperationException();
        return buf;
    }
    else
    {
        return buf.force();
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:28,代码来源:SyncUtil.java

示例6: wipeFile

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
public static void wipeFile(String file2wipe) throws IOException, FileNotFoundException
{
	File f2w = new File(file2wipe);
	
	 if (f2w.exists())
	 {
		
		SecureRandom sr = new SecureRandom();
		RandomAccessFile raf = new RandomAccessFile(f2w, "rw");
		FileChannel channel = raf.getChannel();
		MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, raf.length());
		
		while (buffer.hasRemaining())
		{
			buffer.put((byte) 0);
		}
		buffer.force();
		buffer.rewind();
		
		while (buffer.hasRemaining())
		{
		    buffer.put((byte) 0xFF);
		}
		buffer.force();
		buffer.rewind();
		
		byte[] data = new byte[1];
		while (buffer.hasRemaining())
		{
		    sr.nextBytes(data);
		    buffer.put(data[0]);
		}
		buffer.force();
	    raf.close();
		f2w.delete(); 
	 }
}
 
开发者ID:MonroCoury,项目名称:CryptoKnight,代码行数:38,代码来源:FileEncrypt.java

示例7: close

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
private void close(RandomAccessFile file, Channel channel, MappedByteBuffer mappedFile) {
    if (mappedFile == null) {
        return;
    }
    // sync to disk
    mappedFile.force();
    try {
        // close mappedFile
        AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
            Method cleaner = mappedFile.getClass().getMethod("cleaner");
            cleaner.setAccessible(true);
            ((Cleaner) cleaner.invoke(mappedFile)).clean();
            return null;
        });
        // close channel
        if (channel != null && channel.isOpen()) {
            channel.close();
        }
        // close file
        if (file != null) {
            file.close();
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
        e.printStackTrace();
    }
}
 
开发者ID:ZhangJiupeng,项目名称:Gospy,代码行数:28,代码来源:FileMappedQueue.java


注:本文中的java.nio.MappedByteBuffer.force方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。