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

📄 ioutilities.java

📁 Java Communicating Agents是一个用于开发网络反应式信息agent的框架
💻 JAVA
字号:
/* * $Source: /home/data/cvsroot/src/jacomma/icm/io/imp/IOUtilities.java,v $ * $Revision: 1.7 $ * $Date: 2000/10/28 20:09:07 $ * * This file is part of the jacomma framework * Copyright (c) 2000 	Dimitrios Vyzovitis *			mailto:dviz@egnatia.ee.auth.gr *			 * *			 *			 *			 * *	This library is free software; you can redistribute it and/or modify *	it under the terms of the GNU Library General Public License as published by *	the Free Software Foundation; either version 2 of the License, or *	(at your option) any later version. * *	This library is distributed in the hope that it will be useful, *	but WITHOUT ANY WARRANTY; without even the implied warranty of *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *	GNU Library General Public License for more details. * *	You should have received a copy of the GNU Library General Public License *	along with this library; if not, write to the Free Software *	Foundation, Inc., 59 Temple Place, Suite 330,  *	Boston, MA  02111-1307  USA */package jacomma.icm.io.imp;/** * TBA **/public final class IOUtilities {	static final double byte_h = Math.log( 2 ) * 8;	public static int decodeLength( byte[] array ) {		return new java.math.BigInteger( 1, array ).intValue();	}	public static int decodeInt( byte[] array ) {		return new java.math.BigInteger( array ).intValue();	}		public static long decodeLong( byte[] array ) {		return new java.math.BigInteger( array ).longValue();	}	public static byte[] encodeLength( byte code, int length ) {		return encodeLength( code, length, 							 (int)Math.ceil( Math.log( length + 1 ) / byte_h ) );	}	public static byte[] encodeLength( byte code, int length, int bytes ) {		byte[] res = new byte[bytes + 1];		res[0] = (byte)(code | bytes);		for ( int i = 1; i < res.length; i++ ) {			res[i] = (byte)((length >> (8 * (bytes - i))) & 0xff);		}				return res;	}	public static byte[] encodeLength( byte code, long length ) {		return encodeLength( code, length, 							 (int)Math.ceil( Math.log( length + 1 ) / byte_h ) );	}	public static byte[] encodeLength( byte code, long length, int bytes ) {		byte[] res = new byte[bytes + 1];		res[0] = (byte)(code | bytes);		for ( int i = 1; i < res.length; i++ ) {			res[i] = (byte)((length >> (8 * (bytes - i))) & 0xff);		}				return res;	}	public static String toHexString( byte b ) {		StringBuffer buf = new StringBuffer();		return toHexString( b, buf ).toString();	}		public static StringBuffer toHexString( byte b, StringBuffer buf ) {		buf.append( "0x" )			.append( _forDigit( (b >> 4) & 0xf ) )			.append( _forDigit( b & 0xf ) );		return buf;	}	static String _forDigit( int b ) {		switch ( b ) {		case 15: return "f";		case 14: return "e";		case 13: return "d";		case 12: return "c";		case 11: return "b";		case 10: return "a";		default: return String.valueOf( b );		}	}	public static String toHexString( byte[] ba ) {		StringBuffer buf = new StringBuffer();		for ( int i = 0; i < ba.length; i++ ) {			toHexString( ba[i], buf ).append( " " );		}				return buf.toString().trim();				}}

⌨️ 快捷键说明

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