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


Java ObjectInput类代码示例

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


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

示例1: 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

示例2: 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());

    try {
        deserialize.readObject(long[].class);
        fail();
    } 
    catch (ArrayIndexOutOfBoundsException e) {} 
    // NOTE: Hessian2抛出了ArrayIndexOutOfBoundsException 而不是 IOException!!
    // 容忍这个问题!!
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:23,代码来源:Hessian2SerializationTest.java

示例3: 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

示例4: test_boolArray_withType

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

示例5: 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

示例6: 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 (IOException expected) {
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:21,代码来源:AbstractSerializationTest.java

示例7: test_Bytes

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入依赖的package包/类
@Test
public void test_Bytes() throws Exception {
    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeBytes("123中华人民共和国".getBytes());
    objectOutput.flushBuffer();

    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
            byteArrayOutputStream.toByteArray());
    ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);

    assertArrayEquals("123中华人民共和国".getBytes(), deserialize.readBytes());

    try {
        deserialize.readBytes();
        fail();
    } catch (IOException expected) {
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:19,代码来源:AbstractSerializationTest.java

示例8: 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:yunhaibin,项目名称:dubbox-hystrix,代码行数:24,代码来源:FastJsonSerializationTest.java

示例9: 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:flychao88,项目名称:dubbocloud,代码行数:23,代码来源:Hessian2SerializationTest.java

示例10: 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:yunhaibin,项目名称:dubbox-hystrix,代码行数:21,代码来源:AbstractSerializationTest.java

示例11: assertObjectArrayWithType

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入依赖的package包/类
<T> void assertObjectArrayWithType(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(clazz)));

    try {
        deserialize.readObject(clazz);
        fail();
    } catch (IOException expected) {
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:18,代码来源:AbstractSerializationTest.java

示例12: test_BytesRange

import com.alibaba.dubbo.common.serialize.ObjectInput; //导入依赖的package包/类
@Test
public void test_BytesRange() throws Exception {
    ObjectOutput objectOutput = serialization.serialize(url, byteArrayOutputStream);
    objectOutput.writeBytes("123中华人民共和国-新疆维吾尔自治区".getBytes(), 1, 9);
    objectOutput.flushBuffer();

    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
            byteArrayOutputStream.toByteArray());
    ObjectInput deserialize = serialization.deserialize(url, byteArrayInputStream);

    byte[] expectedArray = new byte[9];
    System.arraycopy("123中华人民共和国-新疆维吾尔自治区".getBytes(), 1, expectedArray, 0, expectedArray.length);
    assertArrayEquals(expectedArray, deserialize.readBytes());

    try {
        deserialize.readBytes();
        fail();
    } catch (IOException expected) {}
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:20,代码来源:AbstractSerializationTest.java

示例13: test_boolArray_withType

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

示例14: 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 (IOException expected) {
        System.out.println(expected);
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:24,代码来源:AbstractSerializationTest.java

示例15: test_intArray_withType

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


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