java - ObjectInputStream.read() returning -1, but readObject returns the object -
am serialize object , deserialize object get:
0 available() -1 read()eofexception readbyte()
public static element getcacheobject(string key, string cachename, string server) throws ioexception, classnotfoundexception, connectexception { string url = stringutils.join(new string[] { server, cachename, key}, "/"); getmethod getmethod = new getmethod(url); objectinputstream oin = null; inputstream in = null; int status = -1; element element = null; seek { status = httpclient.executemethod(getmethod); if (status == httpstatus.sc_not_found) { // if content deleted homecoming null; } in = getmethod.getresponsebodyasstream(); oin = new objectinputstream(in); system.out.println("oin.available():" + oin.available()); // returns 0 system.out.println("oin.read():" + oin.read()); // returns -1 element = (element) oin.readobject(); // returns object } grab (exception except) { except.printstacktrace(); throw except; } { seek { oin.close(); in.close(); } grab (exception except) { except.printstacktrace(); } } homecoming element; }
what missing here?
i think see behaviour because first create objectinputstream
inputstream
, check available
on inputstream
. if check constructor of objectinputstream
can see following:
public objectinputstream(inputstream in) throws ioexception { verifysubclass(); bin = new blockdatainputstream(in); handles = new handletable(10); vlist = new validationlist(); enableoverride = false; readstreamheader(); bin.setblockdatamode(true); }
there method readstreamheader
reads header input stream. possible info read inputstream
during construction of objectinputstream
.
java serialization deserialization ehcache objectinputstream
No comments:
Post a Comment