use of java.beans.XMLDecoder in project wildfly by wildfly.
the class SessionObjectReferenceTestCase method testEcho.
@Test
public void testEcho() throws Exception {
String result = performCall("simple", "Hello+world");
XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(result.getBytes()));
List<String> results = (List<String>) decoder.readObject();
List<Exception> exceptions = (List<Exception>) decoder.readObject();
String sharedContext = (String) decoder.readObject();
decoder.close();
assertEquals(1, results.size());
assertEquals("Echo Hello world", results.get(0));
assertEquals(1, exceptions.size());
assertTrue(exceptions.get(0) instanceof ConcurrentAccessException);
assertEquals("Shared context", sharedContext);
}
use of java.beans.XMLDecoder in project antlrworks by antlr.
the class XJDataXML method readData.
@Override
@SuppressWarnings("unchecked")
public void readData() throws IOException {
XMLDecoder d = new XMLDecoder(new BufferedInputStream(new FileInputStream(getFile())));
dictionary = (Map<String, Object>) d.readObject();
customReadData(d);
d.close();
}
use of java.beans.XMLDecoder in project OpenGrok by OpenGrok.
the class FileHistoryCache method readCache.
/**
* Read history from a file.
*/
private static History readCache(File file) throws IOException {
try {
FileInputStream in = new FileInputStream(file);
XMLDecoder d = new XMLDecoder(new BufferedInputStream(new GZIPInputStream(in)));
return (History) d.readObject();
} catch (IOException e) {
throw e;
}
}
use of java.beans.XMLDecoder in project OpenGrok by OpenGrok.
the class Message method decodeObject.
private static Message decodeObject(InputStream in) throws IOException {
final Object ret;
final LinkedList<Exception> exceptions = new LinkedList<>();
try (XMLDecoder d = new XMLDecoder(new BufferedInputStream(in))) {
ret = d.readObject();
}
if (!(ret instanceof Message)) {
throw new IOException("Not a valid message file");
}
Message conf = ((Message) ret);
return conf;
}
use of java.beans.XMLDecoder 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<Exception>();
ExceptionListener listener = new ExceptionListener() {
public void exceptionThrown(Exception e) {
exceptions.addLast(e);
}
};
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLEncoder enc = new XMLEncoder(out);
enc.setExceptionListener(listener);
Project p1 = new Project();
enc.writeObject(p1);
enc.close();
// verify that the write didn't fail
if (!exceptions.isEmpty()) {
AssertionFailedError afe = new AssertionFailedError("Got " + exceptions.size() + " exception(s)");
// Can only chain one of the exceptions. Take the first one.
afe.initCause(exceptions.getFirst());
throw afe;
}
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()) {
AssertionFailedError afe = new AssertionFailedError("Got " + exceptions.size() + " exception(s)");
// Can only chain one of the exceptions. Take the first one.
afe.initCause(exceptions.getFirst());
throw afe;
}
}
Aggregations