Search in sources :

Example 86 with ObjectOutput

use of com.alibaba.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.

the class AbstractSerializationTest method test_boolArray.

@Test
public void test_boolArray() 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()));
    try {
        deserialize.readObject();
        fail();
    } catch (IOException expected) {
    }
}
Also used : ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(com.alibaba.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) Test(org.junit.Test)

Example 87 with ObjectOutput

use of com.alibaba.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.

the class AbstractSerializationTest method test_doubleArray.

@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) {
    }
}
Also used : ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(com.alibaba.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) Test(org.junit.Test)

Example 88 with ObjectOutput

use of com.alibaba.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.

the class AbstractSerializationTest method test_UtfString.

@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) {
    }
}
Also used : ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(com.alibaba.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) Test(org.junit.Test)

Example 89 with ObjectOutput

use of com.alibaba.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.

the class AbstractSerializationTest method test_floatArray.

@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) {
    }
}
Also used : ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(com.alibaba.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) Test(org.junit.Test)

Example 90 with ObjectOutput

use of com.alibaba.dubbo.common.serialize.ObjectOutput in project dubbo by alibaba.

the class AbstractSerializationTest method test_floatArray_withType.

@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) {
    }
}
Also used : ObjectOutput(com.alibaba.dubbo.common.serialize.ObjectOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInput(com.alibaba.dubbo.common.serialize.ObjectInput) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)106 ObjectInput (com.alibaba.dubbo.common.serialize.ObjectInput)92 ByteArrayInputStream (java.io.ByteArrayInputStream)92 Test (org.junit.Test)90 IOException (java.io.IOException)59 Person (com.alibaba.dubbo.common.model.Person)7 NotSerializableException (java.io.NotSerializableException)7 HashMap (java.util.HashMap)5 BizException (com.alibaba.dubbo.common.model.BizException)4 BizExceptionNoDefaultConstructor (com.alibaba.dubbo.common.model.BizExceptionNoDefaultConstructor)4 Serialization (com.alibaba.dubbo.common.serialize.Serialization)4 LinkedHashMap (java.util.LinkedHashMap)4 UnsafeByteArrayOutputStream (com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream)3 Cleanable (com.alibaba.dubbo.common.serialize.Cleanable)3 ChannelBufferOutputStream (com.alibaba.dubbo.remoting.buffer.ChannelBufferOutputStream)3 ArrayList (java.util.ArrayList)3 URL (com.alibaba.dubbo.common.URL)2 MediaContent (com.alibaba.dubbo.common.model.media.MediaContent)2 BigPerson (com.alibaba.dubbo.common.model.person.BigPerson)2 RemotingException (com.alibaba.dubbo.remoting.RemotingException)2