Idea中雙擊SHIFT能夠搜索[Eclipse中也有],這個很重要,能夠找到當前的項目中能夠引擎的已有的類,不要再次本身發明輪子java
各類Util先在基礎庫和開源庫中找web
guava:com.google.common.io.BaseEncoding算法
commons-codec:org.apache.commons.codec.binary.Base64apache
各類摘要等算法都有了centos
[WARNING] /opt/work/2014/work/centos2017/webman/webman/src/main/java/cn/csbit/util/License.java:[370,41] sun.misc.BASE64Encoder是內部專用 API, 可能會在將來發行版中刪除數組
[WARNING] /opt/work/2014/work/centos2017/webman/webman/src/main/java/cn/csbit/core/report/vo/ReportVo.javaui
commons-langgoogle
org.apache.commons.lang.SerializationUtils編碼
org.apache.commons.lang.timespa
DateFormatUtils DateUtils
cn.csbit.core.util.DateUtil
org.apache.commons.codec.binary
org.apache.commons.lang StringUtils
JDK新的版本才加的方便文件操做的類已經都有了
commons-io
org.apache.commons.io FilenameUtils 文件名的各類處理
FileSystemUtils 磁盤空間的情況
Ints Longs Shorts UnsignedInts
com.google.common.primitives
@GwtIncompatible("doesn\'t work")
public static byte[] toByteArray(int value) {
return new byte[]{(byte)(value >> 24), (byte)(value >> 16), (byte)(value >> 8), (byte)value};
}
@GwtIncompatible("doesn\'t work")
public static int fromByteArray(byte[] bytes) {
Preconditions.checkArgument(bytes.length >= 4, "array too small: %s < %s", new Object[]{Integer.valueOf(bytes.length), Integer.valueOf(4)});
return fromBytes(bytes[0], bytes[1], bytes[2], bytes[3]);
}
public static byte[] shortToBytes(short number) {
int temp = number;
byte[] b = new byte[2];
for (int i = 0; i < b.length; i++) {
b[i] = new Integer(temp & 0xff).byteValue();// 將最低位保存在最低位
temp = temp >> 8; // 向右移8位
}
return b;
}
public static byte[] toByteArray(int value) {
byte[] array = new byte[4];
for (int i = 0; i < 4; i++) {
array[i] = (byte) ((value >> (8 * i)) & 0XFF);
}
return array;
}
NumberUtil common-lang也有相似
#include <arpa/inet.h>
uint32_t htonl(uint32_t hostlong);
uint16_t htons(uint16_t hostshort);
uint32_t ntohl(uint32_t netlong);
uint16_t ntohs(uint16_t netshort);
ByteBuffer b = ByteBuffer.allocate(4);
b.order(ByteBuffer.LITTEN_ENDIAN);
b.putIn(100);
b.array();//能夠獲取字節數組
com.google.common.net.InetAddresses