com.alibaba.dubbo.common.serialize.ObjectInput Java Examples
The following examples show how to use
com.alibaba.dubbo.common.serialize.ObjectInput.
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: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_URL_mutable_withType() throws Exception { URL data = URL.valueOf("dubbo://admin:[email protected]:20880/context/path?version=1.0.0&application=morgan&noValue"); ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(data); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); URL actual = (URL) deserialize.readObject(URL.class); assertEquals(data, actual); assertEquals(data.getParameters(), actual.getParameters()); try { deserialize.readObject(); fail(); } catch (IOException expected) { } }
Example #2
Source File: AbstractSerializationTest.java From dubbo-2.6.5 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 #3
Source File: AbstractSerializationTest.java From dubbo3 with Apache License 2.0 | 6 votes |
@Test public void test_Bool() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeBool(false); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertFalse(deserialize.readBool()); try { deserialize.readBool(); fail(); } catch (IOException expected) { } }
Example #4
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_longArray() 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(); fail(); } catch (IOException expected) { } }
Example #5
Source File: AbstractSerializationTest.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@Test public void test_MediaContent_badStream() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(mediaContent); objectOutput.flushBuffer(); byte[] byteArray = byteArrayOutputStream.toByteArray(); for (int i = 0; i < byteArray.length; i++) { if(i%3 == 0) { byteArray[i] = (byte)~byteArray[i]; } } ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray); try { ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); @SuppressWarnings("unused") // local variable, convenient for debug Object read = deserialize.readObject(); fail(); } catch (IOException expected) { System.out.println(expected); } }
Example #6
Source File: AbstractSerializationTest.java From dubbo3 with Apache License 2.0 | 6 votes |
@Test public void test_MediaContent_badStream() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(mediaContent); objectOutput.flushBuffer(); byte[] byteArray = byteArrayOutputStream.toByteArray(); for (int i = 0; i < byteArray.length; i++) { if(i%3 == 0) { byteArray[i] = (byte)~byteArray[i]; } } ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray); try { ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); @SuppressWarnings("unused") // local variable, convenient for debug Object read = deserialize.readObject(); fail(); } catch (IOException expected) { System.out.println(expected); } }
Example #7
Source File: AbstractSerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_floatArray_withType() 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(float[].class), 0.0001F); try { deserialize.readObject(float[].class); fail(); } catch (IOException expected) { } }
Example #8
Source File: AbstractSerializationTest.java From dubbox 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 #9
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_Integer() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeInt(1); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); int i = deserialize.readInt(); assertEquals(1, i); try { deserialize.readInt(); fail(); } catch (IOException expected) { } }
Example #10
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_Long() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeLong(123L); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertEquals(123L, deserialize.readLong()); try { deserialize.readLong(); fail(); } catch (IOException expected) { } }
Example #11
Source File: AbstractSerializationTest.java From dubbox-hystrix 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 #12
Source File: Hessian2SerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_shortArray_withType() throws Exception { short[] data = new short[]{37, 39, 12}; 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, (short[]) deserialize.readObject(short[].class)); try { deserialize.readObject(short[].class); fail(); } catch (ArrayIndexOutOfBoundsException e) { } // NOTE: Hessian2 throws ArrayIndexOutOfBoundsException instead of IOException, let's live with this. }
Example #13
Source File: Hessian2SerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_StringArray_withType() throws Exception { String[] data = new String[] { "1", "b" }; 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, deserialize.readObject(String[].class)); try { deserialize.readObject(String[].class); fail(); } catch (ArrayIndexOutOfBoundsException e) {} // NOTE: Hessian2抛出了ArrayIndexOutOfBoundsException 而不是 IOException!! // 容忍这个问题!! }
Example #14
Source File: FastJsonSerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_MediaContent_badStream() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeObject(mediaContent); objectOutput.flushBuffer(); byte[] byteArray = byteArrayOutputStream.toByteArray(); for (int i = 0; i < byteArray.length; i++) { if(i%3 == 0) { byteArray[i] = (byte)~byteArray[i]; } } ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArray); try { ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); @SuppressWarnings("unused") // local variable, convenient for debug Object read = deserialize.readObject(); fail(); } catch (JSONException expected) { System.out.println(expected); } }
Example #15
Source File: AbstractSerializationTest.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
@Test public void test_shortArray() throws Exception { short[] data = new short[] { 37, 39, 12 }; 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, (short[]) deserialize.readObject()); try { deserialize.readObject(); fail(); } catch (IOException expected) { } }
Example #16
Source File: AbstractSerializationTest.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(long[].class)); try { deserialize.readObject(long[].class); fail(); } catch (IOException expected) { } }
Example #17
Source File: Hessian2SerializationTest.java From dubbox-hystrix 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 #18
Source File: AbstractSerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_UtfString() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeUTF("123中华人民共和国"); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertEquals("123中华人民共和国", deserialize.readUTF()); try { deserialize.readUTF(); fail(); } catch (IOException expected) { } }
Example #19
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_shortArray_withType() throws Exception { short[] data = new short[]{37, 39, 12}; 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, (short[]) deserialize.readObject(short[].class)); try { deserialize.readObject(short[].class); fail(); } catch (IOException expected) { } }
Example #20
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_UtfString() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeUTF("123中华人民共和国"); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertEquals("123中华人民共和国", deserialize.readUTF()); try { deserialize.readUTF(); fail(); } catch (IOException expected) { } }
Example #21
Source File: Hessian2SerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_shortArray_withType() throws Exception { short[] data = new short[] { 37, 39, 12 }; 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, (short[]) deserialize.readObject(short[].class)); try { deserialize.readObject(short[].class); fail(); } catch (ArrayIndexOutOfBoundsException e) {} // NOTE: Hessian2抛出了ArrayIndexOutOfBoundsException 而不是 IOException!! // 容忍这个问题!! }
Example #22
Source File: AbstractSerializationTest.java From dubbo-2.6.5 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 #23
Source File: Hessian2SerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_floatArray_withType() 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(float[].class); fail(); } catch (ArrayIndexOutOfBoundsException e) {} // NOTE: Hessian2抛出了ArrayIndexOutOfBoundsException 而不是 IOException!! // 容忍这个问题!! }
Example #24
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_Short() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeShort((short) 123); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertEquals((short) 123, deserialize.readShort()); try { deserialize.readShort(); fail(); } catch (IOException expected) { } }
Example #25
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_Long() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeLong(123L); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertEquals(123L, deserialize.readLong()); try { deserialize.readLong(); fail(); } catch (IOException expected) { } }
Example #26
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_Double() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeDouble(1.28); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertTrue(1.28 == deserialize.readDouble()); try { deserialize.readDouble(); fail(); } catch (IOException expected) { } }
Example #27
Source File: AbstractSerializationTest.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
@Test public void test_Byte() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeByte((byte) 123); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertEquals((byte) 123, deserialize.readByte()); try { deserialize.readByte(); fail(); } catch (IOException expected) { } }
Example #28
Source File: AbstractSerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_charArray_withType() 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(char[].class)); try { deserialize.readObject(char[].class); fail(); } catch (IOException expected) { } }
Example #29
Source File: AbstractSerializationTest.java From dubbox-hystrix 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 #30
Source File: AbstractSerializationTest.java From dubbox with Apache License 2.0 | 6 votes |
@Test public void test_Bool() throws Exception { ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream); objectOutput.writeBool(false); objectOutput.flushBuffer(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArrayOutputStream.toByteArray()); ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream); assertFalse(deserialize.readBool()); try { deserialize.readBool(); fail(); } catch (IOException expected) { } }