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


Java OSCBundle.TIMESTAMP_IMMEDIATE属性代码示例

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


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

示例1: readTimeTag

/**
 * Reads the time tag and convert it to a Java Date object.
 * A timestamp is a 64 bit number representing the time in NTP format.
 * The first 32 bits are seconds since 1900, the second 32 bits are
 * fractions of a second.
 * @return a {@link Date}
 */
private Date readTimeTag() {
	byte[] secondBytes = new byte[8];
	byte[] fractionBytes = new byte[8];
	for (int i = 0; i < 4; i++) {
		// clear the higher order 4 bytes
		secondBytes[i] = 0; fractionBytes[i] = 0;
	}
		// while reading in the seconds & fraction, check if
		// this timetag has immediate semantics
	boolean isImmediate = true;
	for (int i = 4; i < 8; i++) {
		secondBytes[i] = bytes[streamPosition++];
		if (secondBytes[i] > 0) {
			isImmediate = false;
		}
	}
	for (int i = 4; i < 8; i++) {
		fractionBytes[i] = bytes[streamPosition++];
		if (i < 7) {
			if (fractionBytes[i] > 0) {
				isImmediate = false;
			}
		} else {
			if (fractionBytes[i] > 1) {
				isImmediate = false;
			}
		}
	}

	if (isImmediate) {
		return OSCBundle.TIMESTAMP_IMMEDIATE;
	}

	BigInteger secsSince1900 = new BigInteger(secondBytes);
	long secsSince1970 =  secsSince1900.longValue()
			- OSCBundle.SECONDS_FROM_1900_TO_1970.longValue();

	// no point maintaining times in the distant past
	if (secsSince1970 < 0) {
		secsSince1970 = 0;
	}
	long fraction = (new BigInteger(fractionBytes).longValue());

	// this line was cribbed from jakarta commons-net's NTP TimeStamp code
	fraction = (fraction * 1000) / 0x100000000L;

	// I do not know where, but I'm losing 1ms somewhere...
	fraction = (fraction > 0) ? fraction + 1 : 0;
	long millisecs = (secsSince1970 * 1000) + fraction;
	return new Date(millisecs);
}
 
开发者ID:gutugutu3030,项目名称:gprintMode,代码行数:58,代码来源:OSCByteArrayToJavaConverter.java

示例2: readTimeTag

/**
 * Reads the time tag and convert it to a Java Date object.
 * A timestamp is a 64 bit number representing the time in NTP format.
 * The first 32 bits are seconds since 1900, the second 32 bits are
 * fractions of a second.
 * @return a {@link Date}
 */
private Date readTimeTag() {
	byte[] secondBytes = new byte[8];
	byte[] fractionBytes = new byte[8];
	for (int i = 0; i < 4; i++) {
		// clear the higher order 4 bytes
		secondBytes[i] = 0;
		fractionBytes[i] = 0;
	}
	// while reading in the seconds & fraction, check if
	// this timetag has immediate semantics
	boolean isImmediate = true;
	for (int i = 4; i < 8; i++) {
		secondBytes[i] = bytes[streamPosition++];
		if (secondBytes[i] > 0) {
			isImmediate = false;
		}
	}
	for (int i = 4; i < 8; i++) {
		fractionBytes[i] = bytes[streamPosition++];
		if (i < 7) {
			if (fractionBytes[i] > 0) {
				isImmediate = false;
			}
		} else {
			if (fractionBytes[i] > 1) {
				isImmediate = false;
			}
		}
	}

	if (isImmediate) {
		return OSCBundle.TIMESTAMP_IMMEDIATE;
	}

	final long secsSince1900 = new BigInteger(secondBytes).longValue();
	long secsSince1970 = secsSince1900 - OSCBundle.SECONDS_FROM_1900_TO_1970;

	// no point maintaining times in the distant past
	if (secsSince1970 < 0) {
		secsSince1970 = 0;
	}
	long fraction = (new BigInteger(fractionBytes).longValue());

	// this line was cribbed from jakarta commons-net's NTP TimeStamp code
	fraction = (fraction * 1000) / 0x100000000L;

	// I do not know where, but I'm losing 1ms somewhere...
	fraction = (fraction > 0) ? fraction + 1 : 0;
	long millisecs = (secsSince1970 * 1000) + fraction;
	return new Date(millisecs);
}
 
开发者ID:JanKoehnlein,项目名称:XRobot,代码行数:58,代码来源:OSCByteArrayToJavaConverter.java


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