java - Working with ObjectOutputStream and ObjectInputStream -
java - Working with ObjectOutputStream and ObjectInputStream -
assume these:
objectoutputstream out = new objectoutputstream(new bufferedoutputstream(remote.getoutputstream())); objectinputstream in = new objectinputstream(new bufferedinputstream(remote.getinputstream()));
after sending "initiate file send" message , size , reading string , long number on other end (you can assume handled them) want able write whole file without having instance new outputstream. i've done far is:
inputstream buf = new bufferedinputstream(new fileinputstream(file)); out.writeunshared(new peerprotocol(peerprotocol.type.file, file.getname(), file.length())); int sum = 0, len; byte[] buffer = new byte[remote.getsendbuffersize()]; out.flush(); out.reset(); while ((len = buf.read(buffer)) > 0) { out.write(buffer, 0, len); sum += len; sendfiledialogcontroller.updatepercentage((double) sum / file.length() * 100); } // system.out.println("done sending"); //out.flush(); didnt work neither sendfiledialogcontroller.updatepercentage(100); buf.close();
problem i'm missing lastly few bytes file corrupt , can't used. how prepare this?
java objectinputstream objectoutputstream bufferedinputstream
Comments
Post a Comment