Module: Java
- Defined in:
- lib/javaobs.rb
Overview
Java Objects namespace to read and write Java serialized objects to streams. Any Java serialized object can be read from a stream. To write a Java object, the meta class must be primed with a sample input serialized object. The is required because Java uses a UUID to identify classes and it is generated using a complex hashing scheme of data and method signatures. Since this system does not have access to that information, it needs to get it from a serialized object.
Objects that have custom serialization methods can be read and written by creating a class as we have for the Date class:
class Date < SimpleDelegator
extend JavaObject
def initialize
super(Time)
end
def time=(time)
case time
when Time
__setobj__(time)
when String
t, = time.unpack("Q")
__setobj__(Time.at(t / 1000, (t % 1000) * 1000))
end
end
def data
t = __getobj__.tv_sec * 1000 + __getobj__.tv_usec / 1000
[t].pack("Q")
end
end
The important methods are the data method that is used for writing the the object to a stream.
All other classes will be auto-generated when the stream is read and persisted. A Java Meta Class is added to the Ruby Class that contains all the Java field information needed to serialize the objects.
Defined Under Namespace
Modules: JavaObject, ObjectStream Classes: Date, JavaArray, JavaClass, JavaField, ObjectInputStream, ObjectOutputStream, SerializationError