tousleutil.java
来自「mywork是rcp开发的很好的例子」· Java 代码 · 共 50 行
JAVA
50 行
package net.sf.util;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
public final class TousleUtil {
//拷贝输入输出
public static void copyIntput2Output(InputStream is, OutputStream os) throws IOException {
byte[] buffer = new byte[1024];
int bytesRead = 0;
try {
if (is == null || os == null) {
throw new IllegalArgumentException("Specified resource does not exist: " + is + "or" + os + ".");
}
do {
bytesRead = is.read(buffer);
if (bytesRead > 0) {
os.write(buffer, 0, bytesRead);
}
} while (bytesRead > 0);
} finally {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
}
}
//获取某个对象的私有属性,设置class参数是为了使用父类
public static Object getPrivateProperty(Object obj,String propertyName){
return getPrivateProperty(obj,propertyName,obj.getClass());
}
public static Object getPrivateProperty(Object obj,String propertyName,Class clazz){
try {
Field declaredField = clazz.getDeclaredField(propertyName);
declaredField.setAccessible(true);
return declaredField.get(obj);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?