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


Java Unsafe类代码示例

本文整理汇总了Java中com.sun.squawk.Unsafe的典型用法代码示例。如果您正苦于以下问题:Java Unsafe类的具体用法?Java Unsafe怎么用?Java Unsafe使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: NativeUnsafeGetString

import com.sun.squawk.Unsafe; //导入依赖的package包/类
/**
 * Create a Java string from a C string pointer
 * @param cstr 
 * @return a java string
 */
public static String NativeUnsafeGetString(Address cstr) {
    int len = 0;
    while (Unsafe.getByte(cstr, len) != 0) {
        len++;
    }
    byte[] data = new byte[len];
    Unsafe.getBytes(cstr, 0, data, 0, len);
    return new String(data);
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:15,代码来源:Pointer.java

示例2: getSuiteVerifiedFlag

import com.sun.squawk.Unsafe; //导入依赖的package包/类
public static boolean getSuiteVerifiedFlag(int suiteAddress) throws IllegalArgumentException {
/*if[FLASH_MEMORY]*/
        int suiteVerifiedFlagAddress=getSuiteVerifiedFlagAddress(suiteAddress);
        int suiteVerifiedFlag =
            (Unsafe.getByte(Address.zero().add(suiteVerifiedFlagAddress), 0)) & (0xff);
        return (0x01!=(suiteVerifiedFlag & (0x01))); //LSB bit is suite verified flag.
/*else[FLASH_MEMORY]*/
//	    return false;
/*end[FLASH_MEMORY]*/
    }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:11,代码来源:SignatureVerifier.java

示例3: setSuiteVerifiedFlag

import com.sun.squawk.Unsafe; //导入依赖的package包/类
private static void setSuiteVerifiedFlag(int suiteAddress) throws IllegalArgumentException {
	int verifiedFlagAddress = getSuiteVerifiedFlagAddress(suiteAddress);
	
//	if (SignatureVerifier.DEBUG)
//		System.out
//			.println("Setting suiteVerifiedFlag.\n\tCurrent value"
//				+ suiteVerifiedFlag + "\n\tShould be"
//				+ suiteVerifiedFlag + "\n\tSet to "
//				+ SUITE_VERIFIED + "\n\tsuiteaddress:"
//				+ suiteAddress + "\n\tverifiedFlagAddress:"
//				+ (verifiedFlagAddress));
    
	    // Set the suiteVerifiedFlag to verified.
	    byte[] tb = new byte[2];
	    // Ensure to flash at an even address.
	    // Not doing so just hangs the SPOT.
	    if (verifiedFlagAddress % 2 == 0) {
			tb[0] = (byte) SUITE_VERIFIED;
			tb[1] = (byte) (Unsafe.getByte(Address.zero().add(verifiedFlagAddress + 1), 0) & (0xff));
			if (SignatureVerifier.DEBUG) {
			    System.out.println("Address even. writing: "
				    + HexEncoding.hexEncode(tb) + " to "
				    + verifiedFlagAddress);
            }
			VM.execSyncIO(ChannelConstants.FLASH_WRITE, verifiedFlagAddress, 2, 0, 0, 0, 0, tb, null);
	    } else {
			tb[0] = (byte) (Unsafe.getByte(Address.zero().add(verifiedFlagAddress - 1), 0) & (0xff));
			tb[1] = (byte) SUITE_VERIFIED;
			if (SignatureVerifier.DEBUG) {
			    System.out.println("Address uneven. writing: "
				    + HexEncoding.hexEncode(tb) + " to "
				    + (verifiedFlagAddress - 1));
            }
			VM.execSyncIO(ChannelConstants.FLASH_WRITE, verifiedFlagAddress - 1, 2, 0, 0, 0, 0, tb, null);
	    }
	    if (!getSuiteVerifiedFlag(suiteAddress)) {
	    	System.out.println("Warning: Setting suite verified flag failed.");
        }
    }
 
开发者ID:tomatsu,项目名称:squawk,代码行数:40,代码来源:SignatureVerifier.java


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