本文整理汇总了Java中java.nio.MappedByteBuffer.hasRemaining方法的典型用法代码示例。如果您正苦于以下问题:Java MappedByteBuffer.hasRemaining方法的具体用法?Java MappedByteBuffer.hasRemaining怎么用?Java MappedByteBuffer.hasRemaining使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.MappedByteBuffer
的用法示例。
在下文中一共展示了MappedByteBuffer.hasRemaining方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: getBytesFromFile
import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
private byte[] getBytesFromFile(String path) throws Throwable {
FileChannel channel = new RandomAccessFile(path, "r").getChannel();
MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()).load();
byte[] bytes = new byte[(int) channel.size()];
if (buffer.hasRemaining()) {
buffer.get(bytes, 0, buffer.remaining());
}
channel.close();
return bytes;
}
示例3: main
import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
RandomAccessFile f = new RandomAccessFile("/Users/zhuam/git/feeyo/feeyoredis/test.txt", "rw");
FileChannel fc = f.getChannel();
MappedByteBuffer buf = fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size());
while (buf.hasRemaining()) {
System.out.print((char)buf.get());
}
System.out.println();
fc.close();
f.close();
}