use of java.io.ObjectInput in project stream-lib by addthis.
the class TestStreamSummary method testSerialization.
@SuppressWarnings("unchecked")
@Test
public void testSerialization() throws IOException, ClassNotFoundException {
StreamSummary<String> vs = new StreamSummary<String>(3);
String[] stream = { "X", "X", "Y", "Z", "A", "B", "C", "X", "X", "A", "C", "A", "A" };
for (String i : stream) {
vs.offer(i);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutput oo = new ObjectOutputStream(baos);
oo.writeObject(vs);
oo.close();
ObjectInput oi = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
StreamSummary<String> clone = (StreamSummary<String>) oi.readObject();
assertEquals(vs.toString(), clone.toString());
}
use of java.io.ObjectInput in project imcache by Cetsoft.
the class Serializer method deserialize.
/**
* Deserialize.
*
* @param <C> the generic type
* @param bytes the bytes
* @return the c
*/
@SuppressWarnings("unchecked")
public static <C> C deserialize(byte[] bytes) {
Object object = null;
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
try {
ObjectInput in = new ObjectInputStream(bis);
object = in.readObject();
bis.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return (C) object;
}
use of java.io.ObjectInput in project azure-tools-for-java by Microsoft.
the class ApplicationInsightsPreferences method loadPreferences.
/**
* Read and load preference file data.
* Converts byte array format data to list of application insights resources.
*/
private void loadPreferences() {
Preferences prefs = PluginUtil.getPrefs(PREF_FILE);
try {
byte[] data = prefs.getByteArray(PREF_KEY, null);
if (data != null) {
ByteArrayInputStream buffer = new ByteArrayInputStream(data);
ObjectInput input = new ObjectInputStream(buffer);
try {
ApplicationInsightsResource[] resources = (ApplicationInsightsResource[]) input.readObject();
for (ApplicationInsightsResource resource : resources) {
if (!ApplicationInsightsResourceRegistry.getAppInsightsResrcList().contains(resource)) {
ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resource);
}
}
} finally {
input.close();
}
}
} catch (IOException e) {
Activator.getDefault().log(e.getMessage(), e);
} catch (ClassNotFoundException e) {
Activator.getDefault().log(e.getMessage(), e);
}
}
use of java.io.ObjectInput in project motan by weibocom.
the class CompressRpcCodec method decodeRequest.
private Object decodeRequest(byte[] body, long requestId, String remoteIp, Serialization serialization) throws IOException, ClassNotFoundException {
ObjectInput input = createInput(getInputStream(body));
String interfaceName = null;
String methodName = null;
String paramtersDesc = null;
String group = null;
String version = null;
String flag = input.readUTF();
if (SIGN_FLAG.equals(flag)) {
// 方法签名方式
String sign = input.readUTF();
MethodInfo mInfo = SIGN_METHOD_MAP.get(sign);
if (mInfo == null) {
throw new MotanFrameworkException("decode error: invalid method sign: " + sign, MotanErrorMsgConstant.FRAMEWORK_DECODE_ERROR);
}
interfaceName = mInfo.getInterfaceName();
methodName = mInfo.getMethodName();
paramtersDesc = mInfo.getParamtersDesc();
group = mInfo.getGroup();
version = mInfo.getVersion();
} else {
interfaceName = flag;
methodName = input.readUTF();
paramtersDesc = input.readUTF();
}
DefaultRequest rpcRequest = new DefaultRequest();
rpcRequest.setRequestId(requestId);
rpcRequest.setInterfaceName(interfaceName);
rpcRequest.setMethodName(methodName);
rpcRequest.setParamtersDesc(paramtersDesc);
rpcRequest.setArguments(decodeRequestParameter(input, paramtersDesc, serialization));
rpcRequest.setAttachments(decodeRequestAttachments(input));
rpcRequest.setRpcProtocolVersion(RpcProtocolVersion.VERSION_2.getVersion());
input.close();
Map<String, String> attachments = rpcRequest.getAttachments();
// 根据签名添加client固定参数。
putSignedAttachment(attachments, remoteIp);
if (attachments.get(URLParamType.group.name()) == null) {
// 如果attachment sign失效时,需要使用methodsign中的group信息。
attachments.put(URLParamType.group.name(), group);
attachments.put(URLParamType.version.name(), version);
}
return rpcRequest;
}
use of java.io.ObjectInput in project motan by weibocom.
the class DefaultRpcCodec method decodeRequest.
private Object decodeRequest(byte[] body, long requestId, Serialization serialization) throws IOException, ClassNotFoundException {
ByteArrayInputStream inputStream = new ByteArrayInputStream(body);
ObjectInput input = createInput(inputStream);
String interfaceName = input.readUTF();
String methodName = input.readUTF();
String paramtersDesc = input.readUTF();
DefaultRequest rpcRequest = new DefaultRequest();
rpcRequest.setRequestId(requestId);
rpcRequest.setInterfaceName(interfaceName);
rpcRequest.setMethodName(methodName);
rpcRequest.setParamtersDesc(paramtersDesc);
rpcRequest.setArguments(decodeRequestParameter(input, paramtersDesc, serialization));
rpcRequest.setAttachments(decodeRequestAttachments(input));
input.close();
return rpcRequest;
}
Aggregations