本文整理汇总了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!!
// 容忍这个问题!!
}
示例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!!
// 容忍这个问题!!
}
示例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) {
}
}
示例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) {
}
}
示例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) {
}
}
示例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);
}
}
示例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);
}
}
示例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) {
}
}
示例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) {
}
}
示例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) {
}
}
示例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());
}
示例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));
}
}
示例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));
}
}
示例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));
}
}
示例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());
}