Java Code Examples for com.caucho.hessian.io.AbstractHessianOutput#writeInt()
The following examples show how to use
com.caucho.hessian.io.AbstractHessianOutput#writeInt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericClassSerializer.java From sofa-hessian with Apache License 2.0 | 6 votes |
public void writeObject(Object obj, AbstractHessianOutput out) throws IOException { GenericClass genericClass = (GenericClass) obj; if (genericClass == null) { out.writeNull(); } else if (out.addRef(obj)) { return; } else { int ref = out.writeObjectBegin("java.lang.Class"); if (ref < -1) { out.writeString("name"); out.writeString(genericClass.getClazzName()); out.writeMapEnd(); } else { if (ref == -1) { out.writeInt(1); out.writeString("name"); out.writeObjectBegin("java.lang.Class"); } out.writeString(genericClass.getClazzName()); } } }
Example 2
Source File: SoftReferenceSerializer.java From AutoLoadCache with Apache License 2.0 | 6 votes |
@Override public void writeObject(Object obj, AbstractHessianOutput out) throws IOException { if (out.addRef(obj)) { return; } @SuppressWarnings("unchecked") SoftReference<Object> data = (SoftReference<Object>) obj; int refV = out.writeObjectBegin(SoftReference.class.getName()); if (refV == -1) { out.writeInt(1); out.writeString("ref"); out.writeObjectBegin(SoftReference.class.getName()); } if (data != null) { Object ref = data.get(); if (null != ref) { out.writeObject(ref); } else { out.writeNull(); } } else { out.writeNull(); } }
Example 3
Source File: WeakReferenceSerializer.java From AutoLoadCache with Apache License 2.0 | 6 votes |
@Override public void writeObject(Object obj, AbstractHessianOutput out) throws IOException { if (out.addRef(obj)) { return; } @SuppressWarnings("unchecked") WeakReference<Object> data = (WeakReference<Object>) obj; int refV = out.writeObjectBegin(WeakReference.class.getName()); if (refV == -1) { out.writeInt(1); out.writeString("ref"); out.writeObjectBegin(WeakReference.class.getName()); } if (data != null) { Object ref = data.get(); if (null != ref) { out.writeObject(ref); } else { out.writeNull(); } } else { out.writeNull(); } }
Example 4
Source File: LocalDateTimeSerializer.java From jvm-sandbox-repeater with Apache License 2.0 | 5 votes |
@Override public void writeObject(Object obj, AbstractHessianOutput out) throws IOException { if (obj == null) { out.writeNull(); } else { Class cl = obj.getClass(); if (out.addRef(obj)) { return; } // ref 返回-2 便是开始写Map int ref = out.writeObjectBegin(cl.getName()); if (ref < -1) { out.writeString("value"); out.writeUTCDate(((LocalDateTime) obj).toInstant(ZoneOffset.of("+8")).toEpochMilli()); out.writeMapEnd(); } else { if (ref == -1) { out.writeInt(1); out.writeString("value"); out.writeObjectBegin(cl.getName()); } out.writeUTCDate(((LocalDateTime) obj).toInstant(ZoneOffset.of("+8")).toEpochMilli()); } } }
Example 5
Source File: TranscribableSerialiser.java From cougar with Apache License 2.0 | 5 votes |
@Override public void writeObject(Object obj, final AbstractHessianOutput out) throws IOException { try { if (out.addRef(obj)) { return; } Transcribable transcribable = (Transcribable) obj; ServiceVersion serviceVersion = transcribable.getServiceVersion(); Class clazz = obj.getClass(); String classNameToWrite = clazz.getName(); // if we're talking to an older version we need to migrate vMajor to vMajor_Minor if (!transcriptionParams.contains(TranscribableParams.MajorOnlyPackageNaming)) { // look for vMajor classNameToWrite = ClassnameCompatibilityMapper.toMajorMinorPackaging(clazz, serviceVersion); } int ref = out.writeObjectBegin(classNameToWrite); // true if the object has already been defined if (ref >= 0) { transcribe(out,transcribable, client); } else { Parameter[] parameters = transcribable.getParameters(); out.writeInt(parameters.length); for (int i=0; i < parameters.length; i++) { out.writeString(parameters[i].getName()); } out.writeObjectBegin(classNameToWrite); transcribe(out,transcribable, client); } } catch (Exception e) { throw new IOException(e); } }
Example 6
Source File: GenericObjectSerializer.java From sofa-hessian with Apache License 2.0 | 4 votes |
void serialize(AbstractHessianOutput out, GenericObject obj, String field) throws IOException { int value = ((Number) obj.getField(field)).intValue(); out.writeInt(value); }