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


Java MappedByteBuffer.remaining方法代码示例

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


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

示例1: readFile2BytesByMap

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
/**
 * 读取文件到字符数组中
 *
 * @param file 文件
 * @return 字符数组
 */
public static byte[] readFile2BytesByMap(File file) {
    if (file == null) return null;
    FileChannel fc = null;
    try {
        fc = new RandomAccessFile(file, "r").getChannel();
        MappedByteBuffer byteBuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()).load();
        byte[] result = new byte[(int) fc.size()];
        if (byteBuffer.remaining() > 0) {
            byteBuffer.get(result, 0, byteBuffer.remaining());
        }
        return result;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    } finally {
        CloseUtils.closeIO(fc);
    }
}
 
开发者ID:penghongru,项目名称:Coder,代码行数:25,代码来源:FileUtils.java

示例2: put

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
public final void put(ByteBuffer byteBuffer) throws IOException {
  try {
    int index = getIndex();
    long length = byteBuffer.limit() - byteBuffer.position();
    this.position += length;
    MappedByteBuffer mappedBuffer = bufferList.get(index);
    if (mappedBuffer.remaining() < length) {
      byte[] temp = new byte[mappedBuffer.remaining()];
      byteBuffer.get(temp);
      bufferList.get(index).put(temp);
      bufferList.get(index + 1).put(byteBuffer);
    } else {
      bufferList.get(index).put(byteBuffer);
    }
  } catch (Exception e) {
    throw new IOException("LargeMappedByteBuffer put rawPosition-"+rawPosition+" size-"+size, e);
  }
}
 
开发者ID:monkeyWie,项目名称:proxyee-down,代码行数:19,代码来源:LargeMappedByteBuffer.java

示例3: mapFileIn

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
/**
 * Converts the file into a byte[].
 * @param infile The File you want to specify
 * @return a byte array
 * @throws IOException if something goes wrong reading the file.
 */
private byte[] mapFileIn(File infile) throws IOException{
	FileInputStream fis = new FileInputStream(infile);
	try{
		FileChannel fc = fis.getChannel(); // Get the file's size and then map it into memory
		int sz = (int)fc.size();
		MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
		byte[] data2 = new byte[bb.remaining()];
		bb.get(data2);
		return data2;
	}
	finally{//Ensures resources are closed regardless of whether the action suceeded
		fis.close();
	}
}
 
开发者ID:goxr3plus,项目名称:java-google-speech-api,代码行数:21,代码来源:RecognizerChunked.java

示例4: toByteArray

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
/**
 * 将文件转换为字节数组,
 * 使用MappedByteBuffer,可以在处理大文件时,提升性能
 *
 * @param file 文件
 * @return 二维码图片的字节数组
 */
private static byte[] toByteArray(File file) {
  try (FileChannel fc = new RandomAccessFile(file, "r").getChannel();) {
    MappedByteBuffer byteBuffer = fc.map(MapMode.READ_ONLY, 0, fc.size()).load();
    byte[] result = new byte[(int) fc.size()];
    if (byteBuffer.remaining() > 0) {
      byteBuffer.get(result, 0, byteBuffer.remaining());
    }
    return result;
  } catch (Exception e) {
    logger.warn("文件转换成byte[]发生异常!", e);
    return null;
  }
}
 
开发者ID:binarywang,项目名称:qrcode-utils,代码行数:21,代码来源:QrcodeUtils.java


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