Java Code Examples for com.alibaba.dubbo.common.serialize.ObjectOutput#writeObject()
The following examples show how to use
com.alibaba.dubbo.common.serialize.ObjectOutput#writeObject() .
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: Hessian2SerializationTest.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@Test public void test_longArray_withType() throws Exception { long[] data = new long[] { 234, 0, -1}; ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertArrayEquals(data, (long[]) deserialize.readObject()); try { deserialize.readObject(long[].class); fail(); } catch (ArrayIndexOutOfBoundsException e) {} // NOTE: Hessian2抛出了ArrayIndexOutOfBoundsException 而不是 IOException!! // 容忍这个问题!! }
Example 2
Source File: AbstractSerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_boolArray_withType() throws Exception { boolean[] data = new boolean[] { true, false, true}; ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertTrue(Arrays.equals(data, (boolean[]) deserialize.readObject(boolean[].class))); try { deserialize.readObject(boolean[].class); fail(); } catch (IOException expected) { } }
Example 3
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_doubleArray() throws Exception { double[] data = new double[]{37D, -3.14D, 123456.7D}; ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertArrayEquals(data, (double[]) deserialize.readObject(), 0.0001); try { deserialize.readObject(); fail(); } catch (IOException expected) { } }
Example 4
Source File: AbstractSerializationTest.java From dubbo3 with Apache License 2.0 | 6 votes |
<T> void assertObjectWithType(T data, Class<T> clazz) throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertEquals(data, (T) deserialize.readObject(clazz)); try { deserialize.readObject(clazz); fail(); } catch (IOException expected) { } }
Example 5
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_floatArray() throws Exception { float[] data = new float[]{37F, -3.14F, 123456.7F}; ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertArrayEquals(data, (float[]) deserialize.readObject(), 0.0001F); try { deserialize.readObject(); fail(); } catch (IOException expected) { } }
Example 6
Source File: AbstractSerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_intArray_withType() throws Exception { int[] data = new int[] { 234, 0, -1}; ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertArrayEquals(data, (int[]) deserialize.readObject(int[].class)); try { deserialize.readObject(int[].class); fail(); } catch (IOException expected) { } }
Example 7
Source File: AbstractSerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_charArray() throws Exception { char[] data = new char[] { 'a', '中', '无' }; ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertArrayEquals(data, (char[]) deserialize.readObject()); try { deserialize.readObject(); fail(); } catch (IOException expected) { } }
Example 8
Source File: Hessian2SerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_boolArray_withType() throws Exception { boolean[] data = new boolean[] { true, false, true}; ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertTrue(Arrays.equals(data, (boolean[]) deserialize.readObject(boolean[].class))); try { deserialize.readObject(boolean[].class); fail(); } catch (ArrayIndexOutOfBoundsException e) {} // NOTE: Hessian2抛出了ArrayIndexOutOfBoundsException 而不是 IOException!! // 容忍这个问题!! }
Example 9
Source File: AbstractSerializationTest.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@Test public void test_longArray_withType() throws Exception { long[] data = new long[] { 234, 0, -1}; ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertArrayEquals(data, (long[]) deserialize.readObject(long[].class)); try { deserialize.readObject(long[].class); fail(); } catch (IOException expected) { } }
Example 10
Source File: Hessian2SerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_boolArray_withType() throws Exception { boolean[] data = new boolean[] { true, false, true}; ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertTrue(Arrays.equals(data, (boolean[]) deserialize.readObject(boolean[].class))); try { deserialize.readObject(boolean[].class); fail(); } catch (ArrayIndexOutOfBoundsException e) {} // NOTE: Hessian2抛出了ArrayIndexOutOfBoundsException 而不是 IOException!! // 容忍这个问题!! }
Example 11
Source File: AbstractSerializationTest.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@Test public void test_floatArray() throws Exception { float[] data = new float[] { 37F, -3.14F, 123456.7F }; ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertArrayEquals(data, (float[]) deserialize.readObject(), 0.0001F); try { deserialize.readObject(); fail(); } catch (IOException expected) { } }
Example 12
Source File: Hessian2SerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_longArray_withType() throws Exception { long[] data = new long[] { 234, 0, -1}; ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertArrayEquals(data, (long[]) deserialize.readObject()); try { deserialize.readObject(long[].class); fail(); } catch (ArrayIndexOutOfBoundsException e) {} // NOTE: Hessian2抛出了ArrayIndexOutOfBoundsException 而不是 IOException!! // 容忍这个问题!! }
Example 13
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_intArray() throws Exception { int[] data = new int[]{234, 0, -1}; ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertArrayEquals(data, (int[]) deserialize.readObject()); try { deserialize.readObject(); fail(); } catch (IOException expected) { } }
Example 14
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
<T> void assertObjectArray(T[] data, Class<T[]> clazz) throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertArrayEquals(data, clazz.cast(deserialize.readObject())); try { deserialize.readObject(); fail(); } catch (IOException expected) { } }
Example 15
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test(timeout = 3000) public void test_LoopReference() throws Exception { Map<String, Object> map = new HashMap<String, Object>(); map.put("k1", "v1"); map.put("self", map); ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(map); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); @SuppressWarnings("unchecked") Map<String, Object> output = (Map<String, Object>) deserialize.readObject(); assertEquals("v1", output.get("k1")); assertSame(output, output.get("self")); }
Example 16
Source File: AbstractSerializationTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test public void test_BizException_WithType() throws Exception { BizException e = new BizException("Hello"); ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(e); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); Object read = deserialize.readObject(BizException.class); assertEquals("Hello", ((BizException) read).getMessage()); }
Example 17
Source File: AbstractSerializationTest.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
@Test public void test_BizExceptionNoDefaultConstructor_WithType() throws Exception { BizExceptionNoDefaultConstructor e = new BizExceptionNoDefaultConstructor("Hello"); ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(e); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); Object read = deserialize.readObject(BizExceptionNoDefaultConstructor.class); assertEquals("Hello", ((BizExceptionNoDefaultConstructor) read).getMessage()); }
Example 18
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Test public void test_LinkedHashMap() throws Exception { LinkedHashMap<String, String> data = new LinkedHashMap<String, String>(); data.put("1", "a"); data.put("2", "b"); ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); Object read = deserialize.readObject(); assertTrue(read instanceof LinkedHashMap); @SuppressWarnings("unchecked") String key1 = ((LinkedHashMap<String, String>) read).entrySet().iterator().next().getKey(); assertEquals("1", key1); assertEquals(data, read); try { deserialize.readObject(); fail(); } catch (IOException expected) { } }
Example 19
Source File: DeprecatedExchangeCodec.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
protected void encodeRequestData(ObjectOutput out, Object data) throws IOException { out.writeObject(data); }
Example 20
Source File: ExchangeCodec.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
protected void encodeResponseData(ObjectOutput out, Object data) throws IOException { out.writeObject(data); }