修改eclipse项目为as项目
This commit is contained in:
102
app/src/main/java/com/util/IoUtil.java
Normal file
102
app/src/main/java/com/util/IoUtil.java
Normal file
@ -0,0 +1,102 @@
|
||||
package com.util;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.StreamCorruptedException;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import org.kobjects.base64.Base64;
|
||||
|
||||
public class IoUtil {
|
||||
/*zip解压缩*/
|
||||
public static Object byte_obj(byte[] b) throws StreamCorruptedException,
|
||||
IOException, ClassNotFoundException {
|
||||
ByteArrayInputStream bin = null;
|
||||
GZIPInputStream gzip = null;
|
||||
ObjectInputStream oin = null;
|
||||
try {
|
||||
bin = new ByteArrayInputStream(b);
|
||||
gzip = new GZIPInputStream(bin);
|
||||
oin = new ObjectInputStream(gzip);
|
||||
return oin.readObject();
|
||||
} finally {
|
||||
if (oin != null) {
|
||||
oin.close();
|
||||
}
|
||||
if (gzip != null) {
|
||||
gzip.close();
|
||||
}
|
||||
if (bin != null) {
|
||||
bin.close();
|
||||
}
|
||||
System.out.println("留关闭---");
|
||||
}
|
||||
}
|
||||
|
||||
public static Object byte_obj2(byte[] b) throws StreamCorruptedException,
|
||||
IOException, ClassNotFoundException {
|
||||
ByteArrayInputStream bin = null;
|
||||
ObjectInputStream oin = null;
|
||||
try {
|
||||
bin = new ByteArrayInputStream(b);
|
||||
oin = new ObjectInputStream(bin);
|
||||
return oin.readObject();
|
||||
} finally {
|
||||
if (oin != null) {
|
||||
oin.close();
|
||||
}
|
||||
if (bin != null) {
|
||||
bin.close();
|
||||
}
|
||||
System.out.println("留关闭");
|
||||
}
|
||||
}
|
||||
/*gzip压缩*/
|
||||
public static byte[] getbyte(Object ob) throws Exception {
|
||||
ByteArrayOutputStream byteOut = null;
|
||||
GZIPOutputStream gziOut = null;
|
||||
ObjectOutputStream objectOut = null;
|
||||
try {
|
||||
byteOut = new ByteArrayOutputStream();
|
||||
gziOut = new GZIPOutputStream(byteOut);
|
||||
objectOut = new ObjectOutputStream(gziOut);
|
||||
objectOut.writeObject(ob);
|
||||
objectOut.flush();
|
||||
objectOut.close();
|
||||
gziOut.close();
|
||||
byteOut.close();
|
||||
return byteOut.toByteArray();
|
||||
} finally {
|
||||
// if(objectOut!=null){
|
||||
// objectOut.close();
|
||||
// }
|
||||
// if(gziOut!=null){
|
||||
//// gziOut.finish();
|
||||
// gziOut.close();
|
||||
// }
|
||||
// if(byteOut!=null){
|
||||
// byteOut.close();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
public static String ob_base64(Object ob) throws IOException {
|
||||
ByteArrayOutputStream bOut = null;
|
||||
ObjectOutputStream objOut = null;
|
||||
try {
|
||||
bOut = new ByteArrayOutputStream();
|
||||
objOut = new ObjectOutputStream(bOut);
|
||||
objOut.writeObject(ob);
|
||||
return Base64.encode(bOut.toByteArray());
|
||||
} finally {
|
||||
objOut.flush();
|
||||
objOut.close();
|
||||
bOut.flush();
|
||||
bOut.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user