📄 utils.java
字号:
/*Copyright (C) 2004 Juho Vähä-HerttuaThis program is free software; you can redistribute it and/ormodify it under the terms of the GNU General Public Licenseas published by the Free Software Foundation; either version 2of the License, or (at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*/package jmirc;import java.io.*;import java.util.Vector;public class Utils { public static byte[] readLine(InputStream is) throws IOException { byte[] ret, buf; int i; buf = new byte[512]; for(i=0; i<512; i++) { buf[i] = (byte) is.read(); if (buf[i] == '\n') break; if (buf[i] == -1) throw new EOFException(); } if (i==512) return null; if (i>0 && buf[i-1] == '\r') i--; ret = new byte[i]; System.arraycopy(buf, 0, ret, 0, i); return ret; } public static String[] splitString(String str, String delims) { if (str == null || str.equals("") || delims == null || delims.length() == 0) return null; String[] s; Vector v = new Vector(); int pos, newpos; pos = 0; newpos = str.indexOf(delims, pos); while(newpos !=-1) { v.addElement(str.substring(pos, newpos)); pos = newpos + delims.length(); newpos = str.indexOf(delims, pos); } v.addElement(str.substring(pos)); s = new String[v.size()]; for(int i=0; i<s.length; i++) { s[i] = (String) v.elementAt(i); } return s; } public static boolean hasNoValue(String s) { return (s == null || s.equals("") || s.getBytes().length ==0); } public static String URLEncode(String inp, String enc) { byte[] input; StringBuffer ret; int i, temp; if (inp==null) return null; try { input = inp.getBytes(enc); } catch (UnsupportedEncodingException uee) { input = inp.getBytes(); // fallback to default encoding } ret = new StringBuffer(); for (i=0; i<input.length; i++) { temp = input[i] & 0xff; if ((temp >= 0x30 && temp <= 0x39) || // 0-9 (temp >= 0x41 && temp <= 0x5a) || // A-Z (temp >= 0x61 && temp <= 0x7a) || // a-z temp == 0x2e || temp == 0x2d || // . and - temp == 0x2a || temp == 0x5f) { // * and _ ret.append((char) temp); } else if (temp == 0x20) { ret.append('+'); } else { ret.append('%'); if (temp < 16) ret.append('0'); ret.append(Integer.toHexString(temp)); } } return ret.toString(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -