本文整理匯總了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);
}
}
示例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;
}
示例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;
}