use of org.jboss.marshalling.InputStreamByteInput in project eap-additional-testsuite by jboss-set.
the class MarshallingTestCase method deserializationTest.
@ATTest({ "modules/testcases/jdkAll/Wildfly/core/src/main/java#10.0.0.Final*11.0.0.Beta1" })
public void deserializationTest() throws Exception {
RiverMarshallerFactory factory = new RiverMarshallerFactory();
MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(2);
// Create a marshaller on some stream we have
RiverMarshaller marshaller = (RiverMarshaller) factory.createMarshaller(configuration);
final ByteArrayOutputStream fileOutputStream = new ByteArrayOutputStream();
marshaller.start(new OutputStreamByteOutput(fileOutputStream));
Bar bar = new Bar("Hello");
Foo foo = new Foo(bar);
// Write lots of stuff
marshaller.writeObject(foo);
// Done
marshaller.finish();
RiverUnmarshaller unmarshaller = (RiverUnmarshaller) factory.createUnmarshaller(configuration);
ByteArrayInputStream fileInputStream = new ByteArrayInputStream(fileOutputStream.toByteArray());
unmarshaller.start(new InputStreamByteInput(fileInputStream));
try {
Foo f = unmarshaller.readObject(Foo.class);
Assert.assertEquals(f.bar.aString, "Hello");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
unmarshaller.finish();
}
use of org.jboss.marshalling.InputStreamByteInput in project wildfly by wildfly.
the class LegacyFileStore method loadTimersFromFile.
static Map<String, TimerImpl> loadTimersFromFile(final String timedObjectId, final TimerServiceImpl timerService, String directory, MarshallerFactory factory, MarshallingConfiguration configuration) {
final Map<String, TimerImpl> timers = new HashMap<String, TimerImpl>();
Unmarshaller unmarshaller = null;
try {
final File file = new File(directory);
if (!file.exists()) {
// no timers exist yet
return timers;
} else if (!file.isDirectory()) {
EJB3_TIMER_LOGGER.failToRestoreTimers(file);
return timers;
}
File marker = new File(file, MIGRATION_MARKER);
if (marker.exists()) {
return timers;
}
unmarshaller = factory.createUnmarshaller(configuration);
for (File timerFile : file.listFiles()) {
if (timerFile.getName().endsWith(".xml")) {
continue;
}
FileInputStream in = null;
try {
in = new FileInputStream(timerFile);
unmarshaller.start(new InputStreamByteInput(in));
final TimerEntity entity = unmarshaller.readObject(TimerEntity.class);
// we load the legacy timer entity class, and turn it into a timer state
TimerImpl.Builder builder;
if (entity instanceof CalendarTimerEntity) {
CalendarTimerEntity c = (CalendarTimerEntity) entity;
final ScheduleExpression scheduleExpression = new ScheduleExpression();
scheduleExpression.second(c.getSecond()).minute(c.getMinute()).hour(c.getHour()).dayOfWeek(c.getDayOfWeek()).dayOfMonth(c.getDayOfMonth()).month(c.getMonth()).year(c.getYear()).start(c.getStartDate()).end(c.getEndDate()).timezone(c.getTimezone());
builder = CalendarTimer.builder().setScheduleExpression(scheduleExpression).setAutoTimer(c.isAutoTimer()).setTimeoutMethod(CalendarTimer.getTimeoutMethod(c.getTimeoutMethod(), timerService.getTimedObjectInvoker().getValue().getClassLoader()));
} else {
builder = TimerImpl.builder();
}
builder.setId(entity.getId()).setTimedObjectId(entity.getTimedObjectId()).setInitialDate(entity.getInitialDate()).setRepeatInterval(entity.getInterval()).setNextDate(entity.getNextDate()).setPreviousRun(entity.getPreviousRun()).setInfo(entity.getInfo()).setTimerState(entity.getTimerState()).setPersistent(true);
timers.put(entity.getId(), builder.build(timerService));
unmarshaller.finish();
} catch (Exception e) {
EJB3_TIMER_LOGGER.failToRestoreTimersFromFile(timerFile, e);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
EJB3_TIMER_LOGGER.failToCloseFile(e);
}
}
}
}
if (!timers.isEmpty()) {
Files.write(marker.toPath(), new Date().toString().getBytes(StandardCharsets.UTF_8));
}
} catch (Exception e) {
EJB3_TIMER_LOGGER.failToRestoreTimersForObjectId(timedObjectId, e);
} finally {
VFSUtils.safeClose(unmarshaller);
}
return timers;
}
use of org.jboss.marshalling.InputStreamByteInput in project wildfly by wildfly.
the class DatabaseTimerPersistence method deSerialize.
public Object deSerialize(final String data) throws SQLException {
if (data == null) {
return null;
}
InputStream in = new ByteArrayInputStream(Base64.getDecoder().decode(data));
try {
final Unmarshaller unmarshaller = factory.createUnmarshaller(configuration);
unmarshaller.start(new InputStreamByteInput(in));
Object ret = unmarshaller.readObject();
unmarshaller.finish();
return ret;
} catch (IOException | ClassNotFoundException e) {
throw new RuntimeException(e);
} finally {
safeClose(in);
}
}
use of org.jboss.marshalling.InputStreamByteInput in project wildfly by wildfly.
the class EjbCorbaServant method unmarshalIdentifier.
private Object unmarshalIdentifier() throws IOException, ClassNotFoundException {
final Object id;
try (final Unmarshaller unmarshaller = factory.createUnmarshaller(configuration)) {
final byte[] idData = poaCurrent.get_object_id();
unmarshaller.start(new InputStreamByteInput(new ByteArrayInputStream(idData)));
id = unmarshaller.readObject();
} catch (NoContext noContext) {
throw new RuntimeException(noContext);
}
return id;
}
use of org.jboss.marshalling.InputStreamByteInput in project wildfly by wildfly.
the class DiskBasedModularPersistentSessionManager method loadSerializedSessions.
@Override
protected Map<String, SessionEntry> loadSerializedSessions(String deploymentName) throws IOException {
File file = new File(baseDir, deploymentName);
if (!file.exists()) {
return null;
}
FileInputStream in = new FileInputStream(file);
try {
Unmarshaller unMarshaller = createUnmarshaller();
try {
try {
unMarshaller.start(new InputStreamByteInput(in));
return (Map<String, SessionEntry>) unMarshaller.readObject();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} finally {
unMarshaller.finish();
}
} finally {
unMarshaller.close();
}
} finally {
IoUtils.safeClose(in);
}
}
Aggregations