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

📄 util.java

📁 JASML is a java byte code compiler, providing yet another approach to view, write and edit java clas
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		while (token.hasMoreTokens() == true) {
			buf.append(toInnerType(token.nextToken()));
		}
		return buf.toString();
	}

	public static String getInnerMethodDescriptor(String retType, String paras) {
		StringBuffer buf = new StringBuffer();
		buf.append('(');
		buf.append(toInnerParameterTypes(paras));
		buf.append(')');
		buf.append(toInnerType(retType));
		return buf.toString();
	}

	public static boolean isDigit(String s) {
		char c;
		for (int i = 0; i < s.length(); i++) {
			c = s.charAt(i);
			if (Character.isDigit(c) == false) {
				return false;
			}
		}
		return true;
	}

	/**
	 * given an integer number, parse it in byte array, the highest values at
	 * front
	 * 
	 * @param num
	 * @param dim
	 * @return byte[]
	 */
	public static byte[] getBytes(int num, int dim) {
		byte[] ret = new byte[dim];
		if (dim == 1) {
			ret[0] = (byte) num;
		} else if (dim == 2) {
			ret[0] = (byte) ((num >> 8) & 0xFF);
			ret[1] = (byte) (num & 0xFF);
		} else if (dim == 4) {
			ret[0] = (byte) ((num >> 24) & 0xFF);
			ret[1] = (byte) ((num >> 16) & 0xFF);
			ret[2] = (byte) ((num >> 8) & 0xFF);
			ret[3] = (byte) (num & 0xFF);
		}
		return ret;
	}

	/**
	 * A constant class object contains inner representation of a class, like
	 * java/lang/Object, or inner representation of a class array, like
	 * Ljava/lang/Object; , or that of a primitive type array, like [[I
	 * 
	 * @param s
	 * @return String
	 */
	public static String constantClassToString(String s) {
		int i = s.indexOf('[');
		if (i == -1) {
			// not an array
			return s.replace('/', '.');
		} else {
			return descriptorToString(s);
		}
	}

	public static byte getPrimitiveTypeCode(String primitiveType) {
		int i;
		for (i = 0; i < Constants.TYPE_NAMES.length; i++) {
			if (Constants.TYPE_NAMES[i].equals(primitiveType) == true) {
				return (byte) i;
			}
		}
		// TODO:, throws exception
		return (byte) 0;
	}

	/**
	 * replaces any \b \t \n \f \r \" \' \\ chars to a viewable string.
	 * 
	 * @param s
	 * @return string
	 */
	public static String toViewableString(String s) {
		StringBuffer buf = new StringBuffer(s.length() + 10);
		char c;
		buf.append('"');
		int len = s.length();
		for (int i = 0; i < len; i++) {
			c = s.charAt(i);
			switch (c) {
			case '\b':
				buf.append("\\b");
				break;
			case '\t':
				buf.append("\\t");
				break;
			case '\n':
				buf.append("\\n");
				break;
			case '\f':
				buf.append("\\f");
				break;
			case '\r':
				buf.append("\\r");
				break;
			case '\\':
				buf.append("\\\\");
				break;
			case '"':
				buf.append("\\\"");
				break;
			case '!':
			case '\'':
			case '#':
			case '$':
			case '%':
			case '&':
			case '(':
			case ')':
			case '*':
			case '+':
			case ',':
			case '-':
			case '.':
			case '/':
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
			case ':':
			case ';':
			case '<':
			case '=':
			case '>':
			case '?':
			case '@':
			case 'A':
			case 'B':
			case 'C':
			case 'D':
			case 'E':
			case 'F':
			case 'G':
			case 'H':
			case 'I':
			case 'J':
			case 'K':
			case 'L':
			case 'M':
			case 'N':
			case 'O':
			case 'P':
			case 'Q':
			case 'R':
			case 'S':
			case 'T':
			case 'U':
			case 'V':
			case 'W':
			case 'X':
			case 'Y':
			case 'Z':
			case '[':
			case ']':
			case '^':
			case '_':
			case '`':
			case 'a':
			case 'b':
			case 'c':
			case 'd':
			case 'e':
			case 'f':
			case 'g':
			case 'h':
			case 'i':
			case 'j':
			case 'k':
			case 'l':
			case 'm':
			case 'n':
			case 'o':
			case 'p':
			case 'q':
			case 'r':
			case 's':
			case 't':
			case 'u':
			case 'v':
			case 'w':
			case 'x':
			case 'y':
			case 'z':
			case '{':
			case '|':
			case '}':
			case '~':
			case ' ':
				buf.append(c);
				break;
			default:
				buf.append(getUnicodeChar(c));
			}

		}
		buf.append('"');
		return buf.toString();
	}

	public static String getUnicodeChar(char c) {
		return "\\u" + Digits[(c & 0xF000) >> 12] + Digits[(c & 0x0F00) >> 8] + Digits[(c & 0x00F0) >> 4] + Digits[(c & 0x000F)];
	}

	public final static char[] Digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

	public final static int[] Numbers = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0/*'0'*/, 1/*'1'*/, 2/*'2'*/, 3/*'3'*/, 4/*'4'*/, 5/*'5'*/, 6/*'6'*/, 7/*'7'*/, 8/*'8'*/,
			9/*'9'*/, 0, 0, 0, 0, 0, 0, 0, 10/*'A'*/, 11/*'B'*/, 12/*'C'*/, 13/*'D'*/, 14/*'E'*/, 15/*'F'*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10/*'a'*/, 11/*'b'*/, 12/*'c'*/, 13/*'d'*/, 14/*'e'*/, 15 /*'f'*/};

	// \b \t \n \f \r \"  \\ chars to a viewable string
	public static String parseViewableString(String s) {
		int len = s.length();
		StringBuffer buf = new StringBuffer(len);
		char c;
		int ti;
		for (int i = 0; i < len; i++) {
			c = s.charAt(i);
			if (c == '\\') {
				i++;
				if (i < len) {
					switch (s.charAt((i))) {
					case 'b':
						buf.append('\b');
						break;
					case 't':
						buf.append('\t');
						break;
					case 'n':
						buf.append('\n');
						break;
					case 'f':
						buf.append('\f');
						break;
					case 'r':
						buf.append('\r');
						break;
					case '"':
						buf.append('\"');
						break;
					case '\\':
						buf.append('\\');
						break;
					case 'u':
						//four digits
						ti = 0;
						i++;
						c = s.charAt(i);
						ti = Numbers[(int) c] << 12;
						i++;
						c = s.charAt(i);
						ti = ti | (Numbers[(int) c] << 8);
						i++;
						c = s.charAt(i);
						ti = ti | (Numbers[(int) c] << 4);
						i++;
						c = s.charAt(i);
						ti = ti | Numbers[(int) c];
						buf.append((char) ti);
					}
				}
			} else {
				buf.append(c);
			}
		}
		return buf.toString();
	}

	public static String padChar(String s, int len, char padChar) {
		if (s.length() >= len) {
			return s;
		}
		StringBuffer buf = new StringBuffer(len);
		buf.append(s);
		for (int i = 0; i < len - s.length(); i++) {
			buf.append(padChar);
		}
		return buf.toString();
	}

	public static int getNum(byte[] bytes) {
		if (bytes.length == 1) {
			return bytes[0] & 0xFF;
		} else if (bytes.length == 2) {
			return ((bytes[0] & 0xff) << 8) + (bytes[1] & 0xff);
		} else if (bytes.length == 4) {
			return (((bytes[0] & 0xff) << 24) + ((bytes[1] & 0xff) << 16) + ((bytes[2] & 0xff) << 8) + (bytes[3] & 0xff));
		}
		return -1;
	}

	public static int getSignedNum(byte[] bytes) {
		if (bytes.length == 1) {
			return bytes[0];
		} else if (bytes.length == 2) {
			return ((bytes[0]) << 8) | ((bytes[1]) & 0xFF);
		} else if (bytes.length == 4) {
			return (bytes[0] << 24) | ((bytes[1] << 16) & 0xFF0000) | ((bytes[2] << 8) & 0xFF00) + (bytes[3] & 0xFF);
		}
		return -1;
	}

	public static void main(String[] args) {
		int i = 0;
		switch (i) {
		case 0:
			System.out.println(i++);
		case 1:
			System.out.println(i++);
		case 2:
			System.out.println(i);
		case 3:
			System.out.println(i);
		case 4:
			System.out.println(i);
		}

	}

}

⌨️ 快捷键说明

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