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


Java MappedByteBuffer.slice方法代码示例

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


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

示例1: createBadBuffers

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
@DataProvider(name = "badBuffers")
static Object[][] createBadBuffers() throws Exception {
    FileChannel fc = FileChannel.open(bob);
    closeables.add(fc);
    MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, 0, 10);

    return new Object[][] {
            { ByteBuffer.allocate(0) },
            { ByteBuffer.allocate(10) },
            { ByteBuffer.allocate(10).duplicate() },
            { ByteBuffer.allocate(10).slice() },
            { ByteBuffer.allocateDirect(10).duplicate() },
            { ByteBuffer.allocateDirect(10).slice() },
            { ByteBuffer.allocateDirect(0).duplicate() },
            { ByteBuffer.allocateDirect(0).slice() },
            { mbb.duplicate() },
            { mbb.slice() }
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:InvokeCleaner.java

示例2: screenshot

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
/**
 * Takes a screenshot of the current frame. This method is
 * entirely copied from http://www.javagaming.org/forums/index.php?topic=8747.0
 * @param gl FengGUIs opengl interface
 * @param width the width of the screenshot
 * @param height the height of the screenhost
 * @param file the file where to store the screenshot
 */
private void screenshot(IOpenGL gl, int width, int height, File file)
{
	try
	{
		RandomAccessFile out = new RandomAccessFile(file, "rw");
		FileChannel ch = out.getChannel();
		int fileLength = TARGA_HEADER_SIZE + width * height * 3;
		out.setLength(fileLength);
		MappedByteBuffer image = ch.map(FileChannel.MapMode.READ_WRITE, 0, fileLength);

		// write the TARGA header
		image.put(0, (byte) 0).put(1, (byte) 0);
		image.put(2, (byte) 2); // uncompressed type
		image.put(12, (byte) (width & 0xFF)); // width
		image.put(13, (byte) (width >> 8)); // width
		image.put(14, (byte) (height & 0xFF));// height
		image.put(15, (byte) (height >> 8));// height
		image.put(16, (byte) 24); // pixel size

		// go to image data position
		image.position(TARGA_HEADER_SIZE);
		// jogl needs a sliced buffer
		ByteBuffer bgr = image.slice();

		// read the BGR values into the image buffer
		gl.readPixels(0, 0, width, height, bgr);

		// close the file channel
		ch.close();
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:44,代码来源:Display.java


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