James Wilson wrote:
> Hey Craig,
>
> A few months ago I asked the questions below. Does
> your response imply that there is no way to get the
> vector's size -- only the size of what's in it? I was
> hoping that the applet of the client side could read
> in a vector and not individual bytes. How would I go
> about reconstructing these bytes into the objects I
> need?
>
> Thanks,
>
> James Wilson
We might be using the term "size" in different senses here.
* If you are after the number of elements currently stored
in the Vector, just call the size() method to ask. Vectors
have no predefined limit like arrays do -- they expand as
necessary.
* If you care what to set the content length to in servlet
to applet messaging, you need to follow the advice that
I gave you. What you are after is the total byte length of
everything you are going to send, and there's no way to
know what that is ahead of time.
If your servlet serializes a Vector to a byte stream, the stream will also
contain the contents of the Vector. All your applet has to do is deserialize
the byte stream, and it gets a Vector with the same contents, no matter how
many elements there are, and no matter how big any individual element is.
One might try to serialize and send just the contents of each object in the
Vector, but how is the receiving applet supposed to know how many elements
there are? You'd have to serialize either an element count at the beginning,
or some sort of special marker object at the end, to let the receiver know
when to stop reading. Serializing the Vector itself is much simpler, and
(depending on the actual objects in the Vector) might actually be fewer bytes
and thus download faster. See the serialization examples in one of the
servlet books that covers this topic, or in the Java Language Tutorial
(http://java.sun.com/docs/books/tutorial) for more information.
NOTE: For serialization to work, the objects stored in the Vector have to
implement the java.lang.Serializable interface. If they don't, you will have
to use some other representation like XML, comma-delimited ASCII, or some
other approach suitable for your data.
Craig
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html