当前位置: 首页>>代码示例>>Java>>正文


Java ObjectInput.readObject方法代码示例

本文整理汇总了Java中com.alibaba.dubbo.common.serialize.ObjectInput.readObject方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectInput.readObject方法的具体用法?Java ObjectInput.readObject怎么用?Java ObjectInput.readObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.dubbo.common.serialize.ObjectInput的用法示例。


在下文中一共展示了ObjectInput.readObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_StringArray_withType

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
@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!!
    // 容忍这个问题!!
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:25,代码来源:Hessian2SerializationTest.java

示例2: test_doubleArray_withType

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
@Test
public void test_doubleArray_withType() 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(double[].class), 0.0001);
    
    try {
        deserialize.readObject(double[].class);
        fail();
    } 
    catch (ArrayIndexOutOfBoundsException e) {} 
    // NOTE: Hessian2抛出了ArrayIndexOutOfBoundsException 而不是 IOException!!
    // 容忍这个问题!!
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:23,代码来源:Hessian2SerializationTest.java

示例3: assertObjectArray

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
<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) {
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:18,代码来源:AbstractSerializationTest.java

示例4: test_longArray_withType

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
@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) {
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:21,代码来源:AbstractSerializationTest.java

示例5: test_longArray

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
@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) {
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:21,代码来源:AbstractSerializationTest.java

示例6: test_MediaContent_badStream

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:24,代码来源:FastJsonSerializationTest.java

示例7: test_MediaContent_WithType_badStream

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
@Test
public void test_MediaContent_WithType_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(MediaContent.class);
        fail();
    } catch (JSONException expected) {
        System.out.println(expected);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:24,代码来源:FastJsonSerializationTest.java

示例8: test_boolArray

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
@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) {
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:21,代码来源:AbstractSerializationTest.java

示例9: test_intArray

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
@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) {
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:21,代码来源:AbstractSerializationTest.java

示例10: test_floatArray_withType

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
@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) {
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:21,代码来源:AbstractSerializationTest.java

示例11: test_BizExceptionNoDefaultConstructor

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
@Test
public void test_BizExceptionNoDefaultConstructor() 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();
    assertEquals("Hello", ((BizExceptionNoDefaultConstructor) read).getMessage());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:16,代码来源:AbstractSerializationTest.java

示例12: decodeResponseData

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
protected Object decodeResponseData(ObjectInput in) throws IOException {
    try {
        return in.readObject();
    } catch (ClassNotFoundException e) {
        throw new IOException(StringUtils.toString("Read object failed.", e));
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:8,代码来源:DeprecatedExchangeCodec.java

示例13: decodeHeartbeatData

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
@Deprecated
protected Object decodeHeartbeatData(Channel channel, ObjectInput in) throws IOException {
    try {
        return in.readObject();
    } catch (ClassNotFoundException e) {
        throw new IOException(StringUtils.toString("Read object failed.", e));
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:9,代码来源:ExchangeCodec.java

示例14: decodeData

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
protected Object decodeData(ObjectInput input) throws IOException {
    try {
        return input.readObject();
    } catch (ClassNotFoundException e) {
        throw new IOException("ClassNotFoundException: " + StringUtils.toString(e));
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:8,代码来源:TransportCodec.java

示例15: test_BizException

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入方法依赖的package包/类
@Test
public void test_BizException() 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();
    assertEquals("Hello", ((BizException) read).getMessage());
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:16,代码来源:AbstractSerializationTest.java


注:本文中的com.alibaba.dubbo.common.serialize.ObjectInput.readObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。