O
OtisUsenet
Hi,
I'm passing a list of Externalized objects over HTTP. On the other end
of that HTTP connection I get the ObjectInputStream, but I am having
trouble reading objects from it.
That is, on the sending side I send N objects, but on the receiving end
I can read only 1.
On the sending side, I do this:
HttpURLConnection conn = null;
ObjectOutputStream oos = null;
try {
conn = (HttpURLConnection) url.openConnection();
conn.setAllowUserInteraction(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-type", "....my stuff here
....");
conn.setRequestMethod("POST");
// send POST output
oos = new ObjectOutputStream(conn.getOutputStream());
for (Iterator it = goodies.iterator(); it.hasNext(); ) {
Goodies g = (Goodie) it.next();
g.writeExternal(oos);
}
}
... catch block + finally block that calls oos.close()
On the receiving end I have:
InputStream is = null;
ObjectInputStream ois = null;
try {
is = request.getInputStream();
ois = new ObjectInputStream(is);
Goodie g = null;
do {
g = (Goodie) ois.readObject();
} while (g != null);
... catch + finally block
The problem is, this do-while loop reads the first Goodie off of OIS,
but the second loop iteration causes this:
java.i
ptionalDataException
at
java.i
bjectInputStream.readObject0(ObjectInputStream.java:1285)
at
java.i
bjectInputStream.readObject(ObjectInputStream.java:324)
It looks as if there is only 1 Goodie in the stream!
I have been searching and searching for some examples that show how to
read MULTIPLE objects from ObjectInputStream, but all examples I was
able to find show cases with a single Foo foo = (Foo) ois.readObject();
call.
That's the easy case!
How does one read _multiple_ objects?
Any help would be very appreciated.
Thanks!
I'm passing a list of Externalized objects over HTTP. On the other end
of that HTTP connection I get the ObjectInputStream, but I am having
trouble reading objects from it.
That is, on the sending side I send N objects, but on the receiving end
I can read only 1.
On the sending side, I do this:
HttpURLConnection conn = null;
ObjectOutputStream oos = null;
try {
conn = (HttpURLConnection) url.openConnection();
conn.setAllowUserInteraction(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-type", "....my stuff here
....");
conn.setRequestMethod("POST");
// send POST output
oos = new ObjectOutputStream(conn.getOutputStream());
for (Iterator it = goodies.iterator(); it.hasNext(); ) {
Goodies g = (Goodie) it.next();
g.writeExternal(oos);
}
}
... catch block + finally block that calls oos.close()
On the receiving end I have:
InputStream is = null;
ObjectInputStream ois = null;
try {
is = request.getInputStream();
ois = new ObjectInputStream(is);
Goodie g = null;
do {
g = (Goodie) ois.readObject();
} while (g != null);
... catch + finally block
The problem is, this do-while loop reads the first Goodie off of OIS,
but the second loop iteration causes this:
java.i
at
java.i
at
java.i
It looks as if there is only 1 Goodie in the stream!
I have been searching and searching for some examples that show how to
read MULTIPLE objects from ObjectInputStream, but all examples I was
able to find show cases with a single Foo foo = (Foo) ois.readObject();
call.
That's the easy case!
How does one read _multiple_ objects?
Any help would be very appreciated.
Thanks!