@Test public void jdkSerial() { Bean bean = new Bean("hello world", NUM_18); byte[] bs = SerializationUtil.jdkSerial(bean); String hexStr = DataUtil.byte2HexStr(bs); Assert.equals(hexStr, "ACED00057372002E636F6D2E6862617365736F66742E6672616D65776F726B2E636F6D6" + "D6F6E2E7574696C732E6265616E2E4265616E0D3AF53B8EBFF729020002490003616765" + "4C00046E616D657400124C6A6176612F6C616E672F537472696E673B78700000001274000B68656C6C6F20776F726C64", ErrorCodeDef.SYSTEM_ERROR_10001); }
public static byte[] jdkSerial(final Object obj) throws UtilException { byte[] bytes = null; ObjectOutputStream out = null; try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); out = new ObjectOutputStream(byteArrayOutputStream); out.writeObject(obj); out.flush(); bytes = byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UtilException(e, ErrorCodeDef.JDK_SERIALIZE_ERROR, obj); } finally { IOUtils.closeQuietly(out); } return bytes; }
SerializationUtil { public static byte[] jdkSerial(final Object obj) throws UtilException { byte[] bytes = null; ObjectOutputStream out = null; try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); out = new ObjectOutputStream(byteArrayOutputStream); out.writeObject(obj); out.flush(); bytes = byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UtilException(e, ErrorCodeDef.JDK_SERIALIZE_ERROR, obj); } finally { IOUtils.closeQuietly(out); } return bytes; } }
SerializationUtil { public static byte[] jdkSerial(final Object obj) throws UtilException { byte[] bytes = null; ObjectOutputStream out = null; try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); out = new ObjectOutputStream(byteArrayOutputStream); out.writeObject(obj); out.flush(); bytes = byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UtilException(e, ErrorCodeDef.JDK_SERIALIZE_ERROR, obj); } finally { IOUtils.closeQuietly(out); } return bytes; }  }
SerializationUtil { public static byte[] jdkSerial(final Object obj) throws UtilException { byte[] bytes = null; ObjectOutputStream out = null; try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); out = new ObjectOutputStream(byteArrayOutputStream); out.writeObject(obj); out.flush(); bytes = byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UtilException(e, ErrorCodeDef.JDK_SERIALIZE_ERROR, obj); } finally { IOUtils.closeQuietly(out); } return bytes; }  @SuppressWarnings("unchecked") static byte[] serial(final T obj); static byte[] jdkSerial(final Object obj); @SuppressWarnings("unchecked") static T unserial(final Class<T> clazz, final byte[] data); static Object jdkUnserial(final byte[] data); }
SerializationUtil { public static byte[] jdkSerial(final Object obj) throws UtilException { byte[] bytes = null; ObjectOutputStream out = null; try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); out = new ObjectOutputStream(byteArrayOutputStream); out.writeObject(obj); out.flush(); bytes = byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UtilException(e, ErrorCodeDef.JDK_SERIALIZE_ERROR, obj); } finally { IOUtils.closeQuietly(out); } return bytes; }  @SuppressWarnings("unchecked") static byte[] serial(final T obj); static byte[] jdkSerial(final Object obj); @SuppressWarnings("unchecked") static T unserial(final Class<T> clazz, final byte[] data); static Object jdkUnserial(final byte[] data);  }