आप ObjectOutputStream
पर एक नज़र हो सकता है।
पहले, आप अपने वस्तु के लिए एक ड्रॉप में प्रतिस्थापन बनाना होगा:
public class SerializableLatLng implements Serializable {
//use whatever you need from LatLng
public SerializableLatLng(LatLng latLng) {
//construct your object from base class
}
//this is where the translation happens
private Object readResolve() throws ObjectStreamException {
return new LatLng(...);
}
}
फिर एक उपयुक्त ObjectOutputSTream
public class SerializableLatLngOutputStream extends ObjectOutputStream {
public SerializableLatLngOutputStream(OutputStream out) throws IOException {
super(out);
enableReplaceObject(true);
}
protected SerializableLatLngOutputStream() throws IOException, SecurityException {
super();
enableReplaceObject(true);
}
@Override
protected Object replaceObject(Object obj) throws IOException {
if (obj instanceof LatLng) {
return new SerializableLatLng((LatLng) obj);
} else return super.replaceObject(obj);
}
}
तब बनाते हैं तो आप इन धाराओं जब का उपयोग करना होगा serializing
private static byte[] serialize(Object o) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new SerializableLatLngOutputStream(baos);
oos.writeObject(o);
oos.flush();
oos.close();
return baos.toByteArray();
}
कुछ कामकाज के लिए देखो – UDPLover