package decode;
import java.util.base64;
import java.io.inputstream;
import java.io.bytearrayinputstream;
import java.io.objectinputstream;
import java.io.optionaldataexception;
import java.io.streamcorruptedexception;
import java.util.arrays;
public class decodeobject{
public static void main(string args[]) throws exception{
int skip=0;
int remainder = 0;
string b64 = args[0];
byte[] bytes = base64.getdecoder().decode(b64);
bytearrayinputstream bis = new bytearrayinputstream(bytes);
int origsize = bis.available();
system.out.println("data length: "+origsize);
object o = null;
while(o == null){
try{
bis.reset();
bis.skip(skip);
objectinputstream ois = new objectinputstream(bis);
o = ois.readobject();
system.out.println("object found...");
system.out.println(o.getclass().getname());
system.out.println("bytes skipped: "+skip);
system.out.println("bytes left: "+bis.available());
skip = origsize - bis.available();
}
catch (streamcorruptedexception ode){
skip = skip+1;
bis.skip(1);
catch (optionaldataexception ode){
catch (classnotfoundexception cnf)
{
system.out.println("object found..."+cnf.getmessage());
}
}
}
转载:http://blog.csdn.net/chaoyu168/article/details/49868247