⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utilities.java

📁 JRed is a 100% Java implementation of the IrDA infrared communications protocols. JRed lets you beam
💻 JAVA
字号:
/*
**************************************************************************
** $Header: /cvsroot/jred/jred/src/com/synchrona/util/Utilities.java,v 1.1.1.1 2000/07/05 04:41:53 mpatters Exp $
**
** Copyright (C) 2000 Synchrona, Inc. All rights reserved.
**
** This file is part of JRed, a 100% Java implementation of the IrDA
** infrared communications protocols.
**
** This file may be distributed under the terms of the Synchrona Public
** License as defined by Synchrona, Inc. and appearing in the file
** LICENSE included in the packaging of this file. The Synchrona Public
** License is based on the Q Public License as defined by Troll Tech AS
** of Norway; it differs only in its use of the courts of Florida, USA
** rather than those of Oslo, Norway.
**************************************************************************
*/
package com.synchrona.util;

public class Utilities {
	public static String bytesToString(byte [] bytes, int offset, int length) {
		if ( null == bytes ) {
			return "(null)";
		} else {
			StringBuffer buffer = new StringBuffer();

			for ( int i = offset; i < (offset + length); i++ ) {
				buffer.append(byteToString(bytes[i]));			
				if ( Character.isLetterOrDigit((char) bytes[i]) ) {
					buffer.append(" (" + (char) bytes[i] + ")");
				}
				if ( i < (bytes.length - 1) ) {
					buffer.append(" ");
				}
			}
			return new String(buffer);
		}
	}

	public static String bytesToString(byte [] bytes) {
		String strReturn = "(null)";

		if ( (null != bytes) && (bytes.length > 0) ) {
			strReturn = bytesToString(bytes, 0, bytes.length);
		}
		return strReturn;
	}

	public static String byteToString(byte b) {
		byte hi_nibble = (byte) ((b & 0xF0) >> 4);
		byte lo_nibble = (byte)  (b & 0x0F);

		return "0x" + nibbleToString(hi_nibble) + nibbleToString(lo_nibble);
		//return Byte.toString(b);
	}

	private static String nibbleToString(byte nibble) {
		switch ( nibble ) {
			case 10: return "A";
			case 11: return "B";
			case 12: return "C";
			case 13: return "D";
			case 14: return "E";
			case 15: return "F";
			default: return Byte.toString(nibble);
		}
	}
}

⌨️ 快捷键说明

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