Hi,
I have to use Java version 1.4.1 and I need to use enum. (Not really
need to, but it would make my life easier later on).
We all know that enum is not supported in pre-1.4.2 versions, and
there is a realy nice example of how to implement it at
http://www.javaworld.com/javaworld/javatips/jw-javatip133.html.
The problem is that, even though I can get this method to work with
writing and reading to the disk, it fails abysmally when trying to use
it with sockets at .getInputStream().
Has anyone tried creating something like this and sending it via a
socket?
What I am trying to do:
Send a class Class1 from one PC to another.
class structure is:
enum A1
Hashtable H1
Hashtable H2
Can someone give me a pointer on how to get it working?
Thanks!
Piotr Kobzda - 17 Apr 2007 09:59 GMT
> I have to use Java version 1.4.1 and I need to use enum.
[...]
> Can someone give me a pointer on how to get it working?
Check out what Retrotranslator
(http://retrotranslator.sourceforge.net/), or Retroweaver
(http://retroweaver.sourceforge.net/news.html) can do for you.
piotr
Lew - 17 Apr 2007 13:06 GMT
> The problem is that, even though I can get this method to work with
> writing and reading to the disk, it fails abysmally when trying to use
[quoted text clipped - 11 lines]
> Hashtable H1
> Hashtable H2
I am curious, what exactly do you mean by "send a class" - send its bytecode?
What advantage does "sending a class" provide that sending a parameter wouldn't?
Are you serializing and deserializing objects (not classes) between JVMs? If
so, be aware that that is always risky.

Signature
Lew
Tom Hawtin - 17 Apr 2007 13:57 GMT
> We all know that enum is not supported in pre-1.4.2 versions, and
> there is a realy nice example of how to implement it at
[quoted text clipped - 3 lines]
> writing and reading to the disk, it fails abysmally when trying to use
> it with sockets at .getInputStream().
One sequence of octets is much like another. What exactly was the
result, and do you have a small, complete, compilable example thing?
There's a few things that obviously wrong with the JavaWorld code.
* No explicit serialVersionUID is declared (both classes). Are you
sure your classes are in sync?
* readObject doesn't start with either defaultReadObject or readFields
(and equivalent for writeObject).
* writeObject use getDeclaredFields (but readObject does not...). This
means if any of your constants is defined as a subclass (probably an
anonymous inner class), it will fail. Also there may be security problems.
* readResolve should be protected at worst.
* If you do use subclasses within the enum, serialisation will be
messed up. Better to use writeReplace in AbstractConstant to substitute
an enum-neutral object with field name and enum class.
* toString should be overriden.
Tom Hawtin
Esmond Pitt - 18 Apr 2007 03:22 GMT
> The problem is that, even though I can get this method to work with
> writing and reading to the disk, it fails abysmally when trying to use
> it with sockets at .getInputStream().
Fails abysmally *how*? That particular method can only fail if the
socket is already closed, and it has nothing to do with sending. Not
that much to do with receiving either, except that calling it is a
precondition.