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


Java MappedByteBuffer.getInt方法代码示例

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


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

示例1: processTupleArgument

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
private static void processTupleArgument(FileChannel channel, ArgumentReferencer argReferencer, Tuple t, int tRef) throws IOException {
	int arity = t.getArity();
	int argSz = 4 + (4 + 4) * arity;
	MappedByteBuffer buf = channel.map(MapMode.READ_WRITE, tRef, argSz);
	int checkArity = buf.getInt();
	if (arity != checkArity) {
		throw new RuntimeException();
	}
	for (Element arg : t.getAllArguments()) {
		buf.getInt(); // skip role
		int argRef = argReferencer.getReference(arg);
		buf.putInt(argRef);
	}
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:15,代码来源:CorpusDumper.java

示例2: unpackBundleRaw

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
/**
 * unpack a xxx.lvbundle
 *
 * @param file
 * @param url
 * @return
 */
public static ScriptBundle unpackBundleRaw(boolean isBytecode, final String url, final File file) throws IOException {
    DebugUtil.tsi("luaviewp-unpackBundle-raw");

    if (file == null || url == null) {
        return null;
    }

    final ScriptBundle scriptBundle = new ScriptBundle();
    final FileInputStream inputStream = new FileInputStream(file);
    final MappedByteBuffer buffer = inputStream.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, file.length());
    final String scriptBundleFolderPath = LuaScriptManager.buildScriptBundleFolderPath(url);

    scriptBundle.setUrl(url);
    scriptBundle.setBytecode(isBytecode);
    scriptBundle.setBaseFilePath(scriptBundleFolderPath);

    int fileNameLen = 0;
    int fileLen = 0;
    String fileNameStr = null;

    byte[] fileName, fileData, signData;
    int count = buffer.getInt();
    for (int i = 0; i < count; i++) {//all files
        fileNameLen = buffer.getInt();// get file name
        fileName = new byte[fileNameLen];
        buffer.get(fileName);

        fileLen = buffer.getInt();// get file data
        fileData = new byte[fileLen];
        buffer.get(fileData);

        if (!isBytecode) {//非二进制的还有sign的data
            fileLen = buffer.getInt();
            signData = new byte[fileLen];
            buffer.get(signData);
        } else {
            signData = null;
        }

        fileNameStr = new String(fileName);
        if (fileNameStr == null || fileNameStr.indexOf("../") != -1) {
            return null;
        }

        scriptBundle.addScript(new ScriptFile(url, scriptBundleFolderPath, fileNameStr, fileData, signData));
    }

    if (inputStream != null) {
        try {
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    DebugUtil.tei("luaviewp-unpackBundle-raw");

    return scriptBundle;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:67,代码来源:ScriptBundleUnpackDelegate.java

示例3: LoadBIN

import java.nio.MappedByteBuffer; //导入方法依赖的package包/类
private boolean LoadBIN() throws IOException {
	boolean LoadOK = false;
	RandomAccessFile RF = null;
	
	try {
		if (_IPDatabasePath.length() > 0) {
			RF = new RandomAccessFile(_IPDatabasePath, "r");
			final FileChannel InChannel = RF.getChannel();
			final MappedByteBuffer _HeaderBuffer = InChannel.map(FileChannel.MapMode.READ_ONLY, 0, 64); // 64 bytes header
			
			_HeaderBuffer.order(ByteOrder.LITTLE_ENDIAN);
			
			_DBType = _HeaderBuffer.get(0);
			_DBColumn = _HeaderBuffer.get(1);
			_DBYear = _HeaderBuffer.get(2);
			_DBMonth = _HeaderBuffer.get(3);
			_DBDay = _HeaderBuffer.get(4);
			_DBCount = _HeaderBuffer.getInt(5); // 4 bytes
			_BaseAddr = _HeaderBuffer.getInt(9); // 4 bytes
			_DBCountIPv6 = _HeaderBuffer.getInt(13); // 4 bytes
			_BaseAddrIPv6 = _HeaderBuffer.getInt(17); // 4 bytes
			_IndexBaseAddr = _HeaderBuffer.getInt(21); //4 bytes
			_IndexBaseAddrIPv6 = _HeaderBuffer.getInt(25); //4 bytes
			
			_IPv4ColumnSize = _DBColumn << 2; // 4 bytes each column
			_IPv6ColumnSize = 16 + ((_DBColumn - 1) << 2); // 4 bytes each column, except IPFrom column which is 16 bytes
			
			// since both IPv4 and IPv6 use 4 bytes for the below columns, can just do it once here
			COUNTRY_POSITION_OFFSET = (COUNTRY_POSITION[_DBType] != 0) ? (COUNTRY_POSITION[_DBType] - 1) << 2 : 0;
			REGION_POSITION_OFFSET = (REGION_POSITION[_DBType] != 0) ? (REGION_POSITION[_DBType] - 1) << 2 : 0;
			CITY_POSITION_OFFSET = (CITY_POSITION[_DBType] != 0) ? (CITY_POSITION[_DBType] - 1) << 2 : 0;
			ISP_POSITION_OFFSET = (ISP_POSITION[_DBType] != 0) ? (ISP_POSITION[_DBType] - 1) << 2 : 0;
			PROXYTYPE_POSITION_OFFSET = (PROXYTYPE_POSITION[_DBType] != 0) ? (PROXYTYPE_POSITION[_DBType] - 1) << 2 : 0;
			
			COUNTRY_ENABLED = (COUNTRY_POSITION[_DBType] != 0) ? true : false;
			REGION_ENABLED = (REGION_POSITION[_DBType] != 0) ? true : false;
			CITY_ENABLED = (CITY_POSITION[_DBType] != 0) ? true : false;
			ISP_ENABLED = (ISP_POSITION[_DBType] != 0) ? true : false;
			PROXYTYPE_ENABLED = (PROXYTYPE_POSITION[_DBType] != 0) ? true : false;
			
			final MappedByteBuffer _IndexBuffer = InChannel.map(FileChannel.MapMode.READ_ONLY, _IndexBaseAddr - 1, _BaseAddr - _IndexBaseAddr); // reading indexes
			_IndexBuffer.order(ByteOrder.LITTLE_ENDIAN);
			int Pointer = 0;
			
			// read IPv4 index
			for (int x = 0; x < _IndexArrayIPv4.length; x++) {
				_IndexArrayIPv4[x][0] = _IndexBuffer.getInt(Pointer); // 4 bytes for from row
				_IndexArrayIPv4[x][1] = _IndexBuffer.getInt(Pointer + 4); // 4 bytes for to row
				Pointer += 8;
			}
			
			if (_IndexBaseAddrIPv6 > 0) {
				// read IPv6 index
				for (int x = 0; x < _IndexArrayIPv6.length; x++) {
					_IndexArrayIPv6[x][0] = _IndexBuffer.getInt(Pointer); // 4 bytes for from row
					_IndexArrayIPv6[x][1] = _IndexBuffer.getInt(Pointer + 4); // 4 bytes for to row
					Pointer += 8;
				}
			}
			
			if (_UseMemoryMappedFile) {
				CreateMappedBytes(InChannel);
			}
			else {
				DestroyMappedBytes();
			}
			LoadOK = true;
		}
	}
	catch(IOException Ex) {
		throw Ex;
	}
	finally {
		if (RF != null) {
			RF.close();
			RF = null;
		}
	}
	return LoadOK;
}
 
开发者ID:ip2location,项目名称:ip2proxy-java,代码行数:81,代码来源:IP2Proxy.java


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