| 281 | } |
| 282 | |
| 283 | public void writeObject(Object o) throws IOException { |
| 284 | if (o == null) { |
| 285 | rawByte(TC_NULL); |
| 286 | return; |
| 287 | } |
| 288 | if (o instanceof String) { |
| 289 | byte[] bytes = ((String)o).getBytes("UTF-8"); |
| 290 | rawByte(TC_STRING); |
| 291 | rawShort(bytes.length); |
| 292 | write(bytes); |
| 293 | return; |
| 294 | } |
| 295 | rawByte(TC_OBJECT); |
| 296 | Method writeObject = getReadOrWriteMethod(o, "writeObject"); |
| 297 | if (writeObject == null) { |
| 298 | classDesc(o.getClass(), 0); |
| 299 | defaultWriteObject(o); |
| 300 | } else try { |
| 301 | classDesc(o.getClass(), SC_WRITE_METHOD); |
| 302 | current = o; |
| 303 | writeObject.invoke(o, this); |
| 304 | current = null; |
| 305 | rawByte(TC_ENDBLOCKDATA); |
| 306 | } catch (Exception e) { |
| 307 | throw new IOException(e); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | static Method getReadOrWriteMethod(Object o, String methodName) { |
| 312 | try { |