use of java.beans.XMLEncoder in project OpenGrok by OpenGrok.
the class GroupTest method testEncodeDecode.
/**
* Test that a {@code Group} instance can be encoded and decoded without
* errors.
*/
@Test
public void testEncodeDecode() {
// Create an exception listener to detect errors while encoding and
// decoding
final LinkedList<Exception> exceptions = new LinkedList<>();
ExceptionListener listener = exceptions::addLast;
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLEncoder enc = new XMLEncoder(out);
enc.setExceptionListener(listener);
Group g1 = new Group();
enc.writeObject(g1);
enc.close();
// verify that the write didn'abcd fail
if (!exceptions.isEmpty()) {
// Can only chain one of the exceptions. Take the first one.
throw new AssertionError("Got " + exceptions.size() + " exception(s)", exceptions.getFirst());
}
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
XMLDecoder dec = new XMLDecoder(in, null, listener);
Group g2 = (Group) dec.readObject();
assertNotNull(g2);
dec.close();
// verify that the read didn'abcd fail
if (!exceptions.isEmpty()) {
// Can only chain one of the exceptions. Take the first one.
throw new AssertionError("Got " + exceptions.size() + " exception(s)", exceptions.getFirst());
}
}
use of java.beans.XMLEncoder in project OpenGrok by OpenGrok.
the class ProjectTest method testEncodeDecode.
/**
* Test that a {@code Project} instance can be encoded and decoded without
* errors. Bug #3077.
*/
@Test
public void testEncodeDecode() {
// Create an exception listener to detect errors while encoding and
// decoding
final LinkedList<Exception> exceptions = new LinkedList<>();
ExceptionListener listener = exceptions::addLast;
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLEncoder enc = new XMLEncoder(out);
enc.setExceptionListener(listener);
Project p1 = new Project("foo");
enc.writeObject(p1);
enc.close();
// verify that the write didn't fail
if (!exceptions.isEmpty()) {
// Can only chain one of the exceptions. Take the first one.
throw new AssertionError("Got " + exceptions.size() + " exception(s)", exceptions.getFirst());
}
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
XMLDecoder dec = new XMLDecoder(in, null, listener);
Project p2 = (Project) dec.readObject();
assertNotNull(p2);
dec.close();
// verify that the read didn't fail
if (!exceptions.isEmpty()) {
// Can only chain one of the exceptions. Take the first one.
throw new AssertionError("Got " + exceptions.size() + " exception(s)", exceptions.getFirst());
}
}
use of java.beans.XMLEncoder in project kie-wb-common by kiegroup.
the class XMLEncoderDiagramMetadataMarshaller method marshall.
@Override
public String marshall(final Metadata metadata) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(os);
encoder.writeObject(metadata);
encoder.close();
String raw = os.toString(CHARSET);
return raw;
}
use of java.beans.XMLEncoder in project smscgateway by RestComm.
the class SmppSimulatorForm method initialize.
private void initialize() {
frmSmppSimulator = new JFrame();
frmSmppSimulator.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent arg0) {
if (frmSmppSimulator.getDefaultCloseOperation() == JDialog.DO_NOTHING_ON_CLOSE) {
JOptionPane.showMessageDialog(getJFrame(), "Before exiting you must close a test window form");
} else {
// if (hostImpl != null) {
// hostImpl.quit();
// }
}
}
});
frmSmppSimulator.setResizable(false);
frmSmppSimulator.setTitle("SMPP Simulator");
frmSmppSimulator.setBounds(100, 100, 510, 299);
frmSmppSimulator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frmSmppSimulator.getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(null);
btnConfigure = new JButton("Configure");
btnConfigure.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
SmppParametersForm frame = new SmppParametersForm(getJFrame());
frame.setData(par);
frame.setVisible(true);
SmppSimulatorParameters newPar = frame.getData();
if (newPar != null) {
par = newPar;
try {
BufferedOutputStream bis = new BufferedOutputStream(new FileOutputStream("SmppSimulatorParameters.xml"));
XMLEncoder d = new XMLEncoder(bis);
d.writeObject(newPar);
d.close();
} catch (Exception ee) {
ee.printStackTrace();
JOptionPane.showMessageDialog(null, "Failed when saving the parameter file SmppSimulatorParameters.xml: " + ee.getMessage());
}
}
}
});
btnConfigure.setBounds(10, 25, 183, 23);
panel.add(btnConfigure);
btnRun = new JButton("Run test");
btnRun.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
runTest();
}
});
btnRun.setBounds(10, 59, 183, 23);
panel.add(btnRun);
}
use of java.beans.XMLEncoder in project cache2k by cache2k.
the class CacheTypeTest method copyObjectViaXmlEncoder.
private <T> T copyObjectViaXmlEncoder(T o) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
XMLEncoder enc = new XMLEncoder(bos);
enc.writeObject(o);
enc.close();
ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
XMLDecoder dec = new XMLDecoder(bin);
Object o2 = dec.readObject();
dec.close();
assertTrue("no reference identity", o2 != o);
assertEquals("same class", o.getClass(), o2.getClass());
return (T) o2;
}
Aggregations