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

📄 opbyte.java

📁 设备资产管理源代码和 公共的函数
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   OpByte.java

package carven;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

// Referenced classes of package carven:
//			OpString

public class OpByte
{

	public OpByte()
	{
	}

	public static int StringToInt(String longStr)
	{
		long tmp = Long.parseLong(longStr);
		return LongToInt(tmp);
	}

	public static int LongToInt(long longInt)
	{
		byte byteLong[] = encodeLong(longInt);
		return decodeInt(byteLong, 4);
	}

	public static String GetByteString(byte theByte[])
	{
		String result = "";
		for (int i = 0; i < theByte.length; i++)
		{
			for (int j = 0; j < 8; j++)
				result = result + (theByte[i] >> 7 - j & 1);

			result = result + "\n";
		}

		return result;
	}

	public static String PrintByte2(byte theByte[])
	{
		String result = "";
		for (int i = 0; i < theByte.length; i++)
		{
			int iTmp = theByte[i];
			String sTmp = Integer.toBinaryString(iTmp);
			sTmp = "00000000" + sTmp;
			sTmp = sTmp.substring(sTmp.length() - 8);
			result = result + sTmp + "\n";
		}

		return result;
	}

	public static String PrintByte10(byte theByte[])
	{
		String result = "";
		for (int i = 0; i < theByte.length; i++)
		{
			int tmp = theByte[i];
			result = result + Integer.toString(tmp) + "\n";
		}

		return result;
	}

	public static String PrintByte16(byte theByte[])
	{
		String result = "";
		for (int i = 0; i < theByte.length; i++)
		{
			int tmp = theByte[i];
			result = result + Integer.toHexString(tmp) + "\n";
		}

		return result;
	}

	public static boolean EqualsByte(byte b1[], byte b2[])
	{
		if (b1.length != b2.length)
			return false;
		int len = b1.length;
		for (int i = 0; i < len; i++)
			if (b1[i] != b2[i])
				return false;

		return true;
	}

	public static byte[] SubBytes(byte oBytes[], int begin, int end)
	{
		int len = (end - begin) + 1;
		byte result[] = new byte[len];
		for (int i = 0; i < len; i++)
			result[i] = oBytes[begin + i];

		return result;
	}

	public static byte[] CutEmptyByte(byte oBytes[])
	{
		int len = oBytes.length;
		int i;
		for (i = len - 1; i > 0; i--)
			if (oBytes[i] != 0)
				break;

		return SubBytes(oBytes, 0, i);
	}

	public static String decodeString(byte codedData[], int index, int length)
		throws Exception
	{
		String result = new String(codedData, index, length);
		return result.trim();
	}

	public static String decodeString(byte codedData[], int index, int length, String charset)
		throws Exception
	{
		byte tmp[] = SubBytes(codedData, index, (index + length) - 1);
		if (charset.equals("unicode"))
		{
			return OpString.UnicodeByteToGBString(tmp);
		} else
		{
			String result = new String(codedData, index, length, charset);
			return result.trim();
		}
	}

	public static int decodeTinyInt(byte codedData[], int index)
	{
		int length = 1;
		int intValue = 0;
		for (int i = 0; i < length; i++)
		{
			intValue <<= 8;
			intValue |= codedData[index + i] & 0xff;
		}

		return intValue;
	}

	public static int decodeSmallInt(byte codedData[], int index)
	{
		int length = 2;
		int intValue = 0;
		for (int i = 0; i < length; i++)
		{
			intValue <<= 8;
			intValue |= codedData[index + i] & 0xff;
		}

		return intValue;
	}

	public static int decodeInt(byte codedData[], int index)
	{
		int length = 4;
		int intValue = 0;
		for (int i = 0; i < length; i++)
		{
			intValue <<= 8;
			intValue |= codedData[index + i] & 0xff;
		}

		return intValue;
	}

	public static long decodeLong(byte codedData[], int index)
	{
		int length = 8;
		long intValue = 0L;
		for (int i = 0; i < length; i++)
		{
			intValue <<= 8;
			intValue |= codedData[index + i] & 0xff;
		}

		return intValue;
	}

	public static byte[] encodeString(String value)
		throws Exception
	{
		return value.getBytes();
	}

	public static byte[] encodeString(String value, String charSetName)
		throws Exception
	{
		return value.getBytes(charSetName);
	}

	public static byte[] encodeString(String value, int byteLength)
		throws Exception
	{
		if (value == null)
			value = "";
		byte result[] = new byte[byteLength];
		byte tmp[] = value.getBytes();
		BytesCopy(tmp, result, 0);
		return result;
	}

	public static byte[] encodeString(String value, int byteLength, String charSetName)
		throws Exception
	{
		if (value == null)
			value = "";
		byte result[] = new byte[byteLength];
		byte tmp[] = value.getBytes(charSetName);
		BytesCopy(tmp, result, 0);
		return result;
	}

	public static byte[] encodeTinyInt(int value)
	{
		int length = 1;
		byte tmp[] = new byte[length];
		int shift = 0;
		for (int i = 0; i < length; i++)
		{
			shift = i * 8;
			tmp[length - i - 1] = (byte)((0xff & value) >> shift);
		}

		return tmp;
	}

	public static byte[] encodeSmallInt(int value)
	{
		int length = 2;
		byte tmp[] = new byte[length];
		int shift = 0;
		for (int i = 0; i < length; i++)
		{
			shift = i * 8;
			tmp[length - i - 1] = (byte)(0xff & value >> shift);
		}

		return tmp;
	}

	public static byte[] encodeInt(int value)
	{
		int length = 4;
		byte tmp[] = new byte[length];
		int shift = 0;
		for (int i = 0; i < length; i++)
		{
			shift = i * 8;
			tmp[length - i - 1] = (byte)(0xff & value >> shift);
		}

		return tmp;
	}

	public static byte[] encodeLong(long value)
	{
		int length = 8;
		byte tmp[] = new byte[length];
		int shift = 0;
		for (int i = 0; i < length; i++)
		{
			shift = i * 8;
			tmp[length - i - 1] = (byte)(int)(255L & value >> shift);
		}

		return tmp;
	}

	public static byte[] CombinByte(byte b1[], byte b2[])
	{
		if (b2 == null)
		{
			return b1;
		} else
		{
			int b1Len = b1.length;
			int b2Len = b2.length;
			byte result[] = new byte[b1Len + b2Len];
			BytesCopy(b1, result, 0);
			BytesCopy(b2, result, b1Len);
			
			return result;
		}
	}

	public static void BytesCopy(byte source[], byte dest[], int destbegin)
	{
		int sourceLen = source.length;
		int destLen = dest.length;
		for (int i = 0; i < sourceLen; i++)
		{
			int tmp = destbegin + i;
			if (tmp >= destLen)
				return;
			dest[tmp] = source[i];
		}
	}

	public static String Base64Encode(byte src[])
	{
		BASE64Encoder encoder = new BASE64Encoder();
		return encoder.encode(src);
	}

	public static byte[] Base64Decode(String src)
	{
		BASE64Decoder decoder = new BASE64Decoder();
		try
		{
			return decoder.decodeBuffer(src);
		}
		catch (Exception ex)
		{
			return null;
		}
	}

	public static String GetStringFromByte(String str)
	{
		String tmp[] = str.split(",");
		byte result[] = new byte[tmp.length];
		for (int i = 0; i < result.length; i++)
			result[i] = (byte)Integer.parseInt(tmp[i], 2);

		return new String(result);
	}
}

⌨️ 快捷键说明

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