com.caucho.hessian.io.HessianOutput Java Examples
The following examples show how to use
com.caucho.hessian.io.HessianOutput.
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: TransactionServiceFilter.java From ByteJTA with GNU Lesser General Public License v3.0 | 6 votes |
private void beforeConsumerInvokeForSVC(Invocation invocation, TransactionRequestImpl request, TransactionResponseImpl response) { TransactionBeanRegistry beanRegistry = TransactionBeanRegistry.getInstance(); TransactionBeanFactory beanFactory = beanRegistry.getBeanFactory(); TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor(); RemoteCoordinator transactionCoordinator = (RemoteCoordinator) beanFactory.getNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), transactionCoordinator.getIdentifier()); transactionInterceptor.beforeSendRequest(request); if (request.getTransactionContext() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); HessianOutput output = new HessianOutput(baos); try { output.writeObject(request.getTransactionContext()); } catch (IOException ex) { logger.error("Error occurred in remote call!", ex); throw new RpcException("Error occurred in remote call!", ex); } String transactionContextContent = ByteUtils.byteArrayToString(baos.toByteArray()); attachments.put(TransactionContext.class.getName(), transactionContextContent); } }
Example #2
Source File: Hessian1BlackListTest.java From sofa-hessian with Apache License 2.0 | 6 votes |
@Test public void testBeanSerialize() throws IOException { TestBlackBean blackBean = new TestBlackBean().setString("sss"); ByteArrayOutputStream output = new ByteArrayOutputStream(); HessianOutput hout = new HessianOutput(output); hout.setSerializerFactory(serializerFactory); try { hout.writeObject(blackBean); hout.flush(); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof IOException); } }
Example #3
Source File: Hessian1BlackListTest.java From sofa-hessian with Apache License 2.0 | 6 votes |
@Test public void testListSerialize() throws IOException { TestBlackBean blackBean = new TestBlackBean().setString("sss"); List list = new ArrayList<TestBlackBean>(); list.add(blackBean); ByteArrayOutputStream output = new ByteArrayOutputStream(); HessianOutput hout = new HessianOutput(output); hout.setSerializerFactory(serializerFactory); try { hout.writeObject(list); hout.flush(); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof IOException); } }
Example #4
Source File: Hessian1BlackListTest.java From sofa-hessian with Apache License 2.0 | 6 votes |
@Test public void testArraySerialize() throws IOException { TestBlackBean blackBean = new TestBlackBean().setString("sss"); Object[] array = new Object[] { blackBean }; ByteArrayOutputStream output = new ByteArrayOutputStream(); HessianOutput hout = new HessianOutput(output); hout.setSerializerFactory(serializerFactory); try { hout.writeObject(array); hout.flush(); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof IOException); } }
Example #5
Source File: Hessian1BlackListTest.java From sofa-hessian with Apache License 2.0 | 6 votes |
@Test public void testMapSerialize() throws IOException { TestBlackBean blackBean = new TestBlackBean().setString("sss"); Map<TestBlackBean, TestBlackBean> map = new HashMap<TestBlackBean, TestBlackBean>(); map.put(blackBean, blackBean); ByteArrayOutputStream output = new ByteArrayOutputStream(); HessianOutput hout = new HessianOutput(output); hout.setSerializerFactory(serializerFactory); try { hout.writeObject(map); hout.flush(); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof IOException); } }
Example #6
Source File: CompensableSecondaryFilter.java From ByteTCC with GNU Lesser General Public License v3.0 | 6 votes |
private void beforeConsumerInvokeForSVC(Invocation invocation, TransactionRequestImpl request, TransactionResponseImpl response) { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor(); RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier()); transactionInterceptor.beforeSendRequest(request); if (request.getTransactionContext() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); HessianOutput output = new HessianOutput(baos); try { output.writeObject(request.getTransactionContext()); } catch (IOException ex) { logger.error("Error occurred in remote call!", ex); throw new RemotingException(ex.getMessage()); } String transactionContextContent = ByteUtils.byteArrayToString(baos.toByteArray()); attachments.put(TransactionContext.class.getName(), transactionContextContent); } }
Example #7
Source File: CompensablePrimaryFilter.java From ByteTCC with GNU Lesser General Public License v3.0 | 6 votes |
private void beforeConsumerInvokeForSVC(Invocation invocation, TransactionRequestImpl request, TransactionResponseImpl response) { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor(); RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier()); transactionInterceptor.beforeSendRequest(request); if (request.getTransactionContext() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); HessianOutput output = new HessianOutput(baos); try { output.writeObject(request.getTransactionContext()); } catch (IOException ex) { logger.error("Error occurred in remote call!", ex); throw new RemotingException(ex.getMessage()); } String transactionContextContent = ByteUtils.byteArrayToString(baos.toByteArray()); attachments.put(TransactionContext.class.getName(), transactionContextContent); } }
Example #8
Source File: HessianUtils.java From rpcx-java with Apache License 2.0 | 6 votes |
public static byte[] write(Object obj) { ByteArrayOutputStream os = new ByteArrayOutputStream(); HessianOutput ho = new HessianOutput(os); try { ho.writeObject(obj); return os.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } finally { try { ho.close(); os.close(); } catch (Exception ex) { } } }
Example #9
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object4() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); NoWriteReplaceSerializerFactory sf = new NoWriteReplaceSerializerFactory(); sf.setAllowNonSerializable(true); out.setSerializerFactory(sf); out.writeObject(new HessianSerialization()); out.close(); return bos.toByteArray(); }
Example #10
Source File: SerializeUtils.java From ByteJTA with GNU Lesser General Public License v3.0 | 5 votes |
public static byte[] hessianSerialize(Serializable obj) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); HessianOutput ho = new HessianOutput(baos); try { ho.writeObject(obj); return baos.toByteArray(); } finally { CommonUtils.closeQuietly(baos); } }
Example #11
Source File: HessianSerializeCoder.java From hasor with Apache License 2.0 | 5 votes |
@Override public byte[] encode(Object object) throws IOException { ByteArrayOutputStream binary = new ByteArrayOutputStream(); HessianOutput hout = new HessianOutput(binary); hout.setSerializerFactory(this.serializerFactory); hout.writeObject(object); return binary.toByteArray(); }
Example #12
Source File: HessianUtil.java From krpc with MIT License | 5 votes |
public static byte[] serialize(Object obj) throws IOException { if (obj == null) throw new NullPointerException(); ByteArrayOutputStream os = new ByteArrayOutputStream(); HessianOutput ho = new HessianOutput(os); ho.writeObject(obj); return os.toByteArray(); }
Example #13
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object6_() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); Map<String, String> map = new HashMap<>(); map.put("test", "test"); out.writeObject(map); out.close(); return bos.toByteArray(); }
Example #14
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object6() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); NoWriteReplaceSerializerFactory sf = new NoWriteReplaceSerializerFactory(); sf.setAllowNonSerializable(true); out.setSerializerFactory(sf); Map<String, String> map = new HashMap<>(); map.put("test", "test"); out.writeObject(map); out.close(); return bos.toByteArray(); }
Example #15
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object5_() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); Map<String, String> map = new HashMap<>(); map.put("test", "test"); map.put("foo", "foo"); out.writeObject(map); out.close(); return bos.toByteArray(); }
Example #16
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object5() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); NoWriteReplaceSerializerFactory sf = new NoWriteReplaceSerializerFactory(); sf.setAllowNonSerializable(true); out.setSerializerFactory(sf); Map<String, String> map = new HashMap<>(); map.put("test", "test"); map.put("foo", "foo"); out.writeObject(map); out.close(); return bos.toByteArray(); }
Example #17
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object4_() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); out.writeObject(new HessianSerialization()); out.close(); return bos.toByteArray(); }
Example #18
Source File: HessianSerializer.java From open-capacity-platform with Apache License 2.0 | 5 votes |
public static <T> byte[] serialize(T obj){ ByteArrayOutputStream os = new ByteArrayOutputStream(); HessianOutput ho = new HessianOutput(os); try { ho.writeObject(obj); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } return os.toByteArray(); }
Example #19
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object3_() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); out.writeObject(new B(new A())); out.close(); return bos.toByteArray(); }
Example #20
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object3() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); NoWriteReplaceSerializerFactory sf = new NoWriteReplaceSerializerFactory(); sf.setAllowNonSerializable(true); out.setSerializerFactory(sf); out.writeObject(new B(new A())); out.close(); return bos.toByteArray(); }
Example #21
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object2_() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); out.writeObject(new A()); out.close(); return bos.toByteArray(); }
Example #22
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object2() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); NoWriteReplaceSerializerFactory sf = new NoWriteReplaceSerializerFactory(); sf.setAllowNonSerializable(true); out.setSerializerFactory(sf); out.writeObject(new A()); out.close(); return bos.toByteArray(); }
Example #23
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object1_2() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); out.writeString("threedr3am"); out.close(); return bos.toByteArray(); }
Example #24
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object1_() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); out.writeString("test"); out.close(); return bos.toByteArray(); }
Example #25
Source File: HessianSerialization.java From learnjavabug with MIT License | 5 votes |
private static byte[] object1() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); AbstractHessianOutput out = new HessianOutput(bos); NoWriteReplaceSerializerFactory sf = new NoWriteReplaceSerializerFactory(); sf.setAllowNonSerializable(true); out.setSerializerFactory(sf); out.writeString("test"); out.close(); return bos.toByteArray(); }
Example #26
Source File: HessianRowSerializationSchema.java From alchemy with Apache License 2.0 | 5 votes |
@Override public byte[] serialize(Row row) { outputStream.reset(); try { Object object = clazz.newInstance(); ConvertRowUtil.convertFromRow(object, ((RowTypeInfo)typeInfo).getFieldNames(), row); HessianOutput ho = new HessianOutput(outputStream); ho.writeObject(outputStream); return outputStream.toByteArray(); } catch (Exception e) { throw new RuntimeException( "Could not serialize row '" + row + "'. " + "Make sure that the schema matches the input.", e); } }
Example #27
Source File: Lesson2_4.java From java-interview with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException, ClassNotFoundException { // 对象赋值 User user = new User(); user.setName("老王"); user.setAge(30); System.out.println(user); // -------------------------- Java 原生序列化 ---------------------------- // 创建输出流(序列化内容到磁盘) ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("test.out")); // 序列化对象 oos.writeObject(user); oos.flush(); oos.close(); // 创建输入流(从磁盘反序列化) ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.out")); // 反序列化 User user2 = (User) ois.readObject(); ois.close(); System.out.println(user2); // -------------------------- JSON 序列化(fastjson) ---------------------------- String jsonSerialize = JSON.toJSONString(user); User user3 = (User) JSON.parseObject(jsonSerialize, User.class); System.out.println(user3); // -------------------------- Hessian 序列化 ---------------------------- // 序列化 ByteArrayOutputStream bo = new ByteArrayOutputStream(); HessianOutput hessianOutput = new HessianOutput(bo); hessianOutput.writeObject(user); byte[] hessianBytes = bo.toByteArray(); // 反序列化 ByteArrayInputStream bi = new ByteArrayInputStream(hessianBytes); HessianInput hessianInput = new HessianInput(bi); User user4 = (User) hessianInput.readObject(); System.out.println(user4); }
Example #28
Source File: Hessian.java From marshalsec with MIT License | 2 votes |
/** * {@inheritDoc} * * @see marshalsec.AbstractHessianBase#createOutput(java.io.ByteArrayOutputStream) */ @Override protected AbstractHessianOutput createOutput ( ByteArrayOutputStream bos ) { return new HessianOutput(bos); }