use of java.io.ObjectInputStream in project pinot by linkedin.
the class GenericResultSetMapper method main.
public static void main(String[] args) throws Exception {
ModelMapper mapper = new ModelMapper();
Map<String, Object> result = new HashMap<>();
//[{jobName=Test_Anomaly_Task, jobId=1, workerId=1, taskType=MONITOR, id=1, taskInfo=clob2: '{"jobExecutionId":1,"monitorType":"UPDATE","expireDaysAgo":0}', lastModified=2016-08-24 17:25:53.258, version=0, taskStartTime=1470356753227, status=RUNNING, taskEndTime=1471220753227}]
result.put("jobName", "Test_Anomaly_Task");
result.put("jobId", 1L);
result.put("taskType", "MONITOR");
result.put("id", 1L);
result.put("taskInfo", "clob2: '{\"jobExecutionId\":1,\"monitorType\":\"UPDATE\",\"expireDaysAgo\":0}'");
result.put("taskType", "MONITOR");
result.put("lastModified", "2016-08-24 17:25:53.258");
result.put("status", "RUNNING");
result.put("lastModified", "2016-08-24 17:25:53.258");
TaskDTO taskSpec1 = mapper.map(result, TaskDTO.class);
System.out.println(taskSpec1);
//INPUT 2
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("/tmp/map.out.1472093046128")));
Map<String, Object> inputMap = (Map<String, Object>) ois.readObject();
TaskDTO taskSpec2 = mapper.map(inputMap, TaskDTO.class);
System.out.println(taskSpec2);
}
use of java.io.ObjectInputStream in project hibernate-orm by hibernate.
the class CacheKeySerializationTest method testId.
private void testId(CacheKeysFactory cacheKeysFactory, String entityName, Object id) throws Exception {
final SessionFactoryImplementor sessionFactory = getSessionFactory(cacheKeysFactory.getClass().getName());
final EntityPersister persister = sessionFactory.getEntityPersister(entityName);
final Object key = cacheKeysFactory.createEntityKey(id, persister, sessionFactory, null);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(key);
final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
final Object keyClone = ois.readObject();
try {
assertEquals(key, keyClone);
assertEquals(keyClone, key);
assertEquals(key.hashCode(), keyClone.hashCode());
final Object idClone = cacheKeysFactory.getEntityId(keyClone);
assertEquals(id.hashCode(), idClone.hashCode());
assertEquals(id, idClone);
assertEquals(idClone, id);
assertTrue(persister.getIdentifierType().isEqual(id, idClone, sessionFactory));
assertTrue(persister.getIdentifierType().isEqual(idClone, id, sessionFactory));
sessionFactory.close();
} finally {
sessionFactory.close();
}
}
use of java.io.ObjectInputStream in project Smack by igniterealtime.
the class JivePropertiesExtensionProvider method parse.
/**
* Parse a properties sub-packet. If any errors occur while de-serializing Java object
* properties, an exception will be printed and not thrown since a thrown exception will shut
* down the entire connection. ClassCastExceptions will occur when both the sender and receiver
* of the stanza(/packet) don't have identical versions of the same class.
* <p>
* Note that you have to explicitly enabled Java object deserialization with @{link
* {@link JivePropertiesManager#setJavaObjectEnabled(boolean)}
*
* @param parser the XML parser, positioned at the start of a properties sub-packet.
* @return a map of the properties.
* @throws IOException
* @throws XmlPullParserException
*/
@Override
public JivePropertiesExtension parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
Map<String, Object> properties = new HashMap<String, Object>();
while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("property")) {
// Parse a property
boolean done = false;
String name = null;
String type = null;
String valueText = null;
Object value = null;
while (!done) {
eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
String elementName = parser.getName();
if (elementName.equals("name")) {
name = parser.nextText();
} else if (elementName.equals("value")) {
type = parser.getAttributeValue("", "type");
valueText = parser.nextText();
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("property")) {
if ("integer".equals(type)) {
value = Integer.valueOf(valueText);
} else if ("long".equals(type)) {
value = Long.valueOf(valueText);
} else if ("float".equals(type)) {
value = Float.valueOf(valueText);
} else if ("double".equals(type)) {
value = Double.valueOf(valueText);
} else if ("boolean".equals(type)) {
value = Boolean.valueOf(valueText);
} else if ("string".equals(type)) {
value = valueText;
} else if ("java-object".equals(type)) {
if (JivePropertiesManager.isJavaObjectEnabled()) {
try {
byte[] bytes = Base64.decode(valueText);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
value = in.readObject();
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error parsing java object", e);
}
} else {
LOGGER.severe("JavaObject is not enabled. Enable with JivePropertiesManager.setJavaObjectEnabled(true)");
}
}
if (name != null && value != null) {
properties.put(name, value);
}
done = true;
}
}
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals(JivePropertiesExtension.ELEMENT)) {
break;
}
}
}
return new JivePropertiesExtension(properties);
}
use of java.io.ObjectInputStream in project java-design-patterns by iluwatar.
the class RainbowFishSerializer method readV1.
/**
* Read V1 RainbowFish from file
*/
public static RainbowFish readV1(String filename) throws IOException, ClassNotFoundException {
FileInputStream fileIn = new FileInputStream(filename);
ObjectInputStream objIn = new ObjectInputStream(fileIn);
Map<String, String> map = (Map<String, String>) objIn.readObject();
objIn.close();
fileIn.close();
return new RainbowFish(map.get("name"), Integer.parseInt(map.get("age")), Integer.parseInt(map.get("lengthMeters")), Integer.parseInt(map.get("weightTons")));
}
use of java.io.ObjectInputStream in project mapdb by jankotek.
the class JSR166Test method serialClone.
@SuppressWarnings("unchecked")
<T> T serialClone(T o) {
try {
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(serialBytes(o)));
T clone = (T) ois.readObject();
return clone;
} catch (Throwable fail) {
threadUnexpectedException(fail);
return null;
}
}
Aggregations