littleendianstreamtest.java

来自「java 调用windows的api」· Java 代码 · 共 42 行

JAVA
42
字号
/*
 * LittleEndianStreamTest.java -
 *
 * This file is part of the Jawin Project: http://jawinproject.sourceforge.net/
 * 
 * Please consult the LICENSE file in the project root directory,
 * or at the project site before using this software.
 */

/* $Id: LittleEndianStreamTest.java,v 1.1 2004/06/14 19:24:56 arosii_moa Exp $ */

package org.jawin.io;

import java.io.ByteArrayInputStream;

import junit.framework.TestCase;

/**
 * Testcases for different boundary values on the LittleEndianStreams.
 *
 * @version     $Revision: 1.1 $
 * @author      Morten Andersen, arosii_moa (at) users.sourceforge.net
 */
public class LittleEndianStreamTest extends TestCase {

	public void testUnsignedSigned() throws Exception {
		NakedByteStream nbs = new NakedByteStream();
		LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
		leos.writeByte(255);
		leos.writeByte(255);
		leos.writeShort(65535);
		leos.writeShort(65535);
		
		LittleEndianInputStream leis = new LittleEndianInputStream(new ByteArrayInputStream(nbs.getInternalBuffer(), 0, nbs.size()));
		assertEquals(255, leis.readUnsignedByte());
		assertEquals((byte)255, leis.readByte()); // signed (byte)255 = -1
		assertEquals(65535, leis.readUnsignedShort());
		assertEquals((short)65535, leis.readShort()); // signed (short)65535 = -1
		
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?