use of java.beans.ExceptionListener in project whole by wholeplatform.
the class BeansPersistenceKit method doReadModel.
protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
// TODO cannot use getEncoding()
XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(pp.getInputStream()) {
@Override
public void close() throws IOException {
}
}, null, new ExceptionListener() {
public void exceptionThrown(Exception e) {
// do nothing
}
}, ReflectionFactory.getPlatformClassLoader());
IEntity model = (IEntity) decoder.readObject();
decoder.close();
return model;
}
use of java.beans.ExceptionListener in project OpenGrok by OpenGrok.
the class ConfigurationTest method testEncodeDecode.
@Test
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);
Configuration configuration1 = new Configuration();
configuration1.setInterval(500);
configuration1.setSearchTimeout(1000);
configuration1.setConnectTimeout(42);
configuration1.setCountLimit(10);
configuration1.setServers(new ArrayList<>(List.of(new LdapServer("http://server.com"))));
WebHooks webHooks = new WebHooks();
WebHook hook = new WebHook();
hook.setContent("foo");
hook.setURI("http://localhost:8080/source/api/v1/messages");
webHooks.setFail(hook);
configuration1.setWebHooks(webHooks);
enc.writeObject(configuration1);
enc.close();
// verify that the write didn't fail
if (!exceptions.isEmpty()) {
throw new AssertionError("Got " + exceptions.size() + " exception(s)", exceptions.getFirst());
}
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
XMLDecoder dec = new XMLDecoder(in, null, listener);
Configuration configuration2 = (Configuration) dec.readObject();
assertNotNull(configuration2);
assertEquals(configuration1.getXMLRepresentationAsString(), configuration2.getXMLRepresentationAsString());
dec.close();
// verify that the read didn't fail
if (!exceptions.isEmpty()) {
throw new AssertionError("Got " + exceptions.size() + " exception(s)", exceptions.getFirst());
}
}
use of java.beans.ExceptionListener in project OpenGrok by OpenGrok.
the class IgnoredNamesTest method testEncodeDecode.
/**
* Make sure that encoding and decoding IgnoredNames object is 1:1 operation.
*/
@Test
void testEncodeDecode() throws IOException {
IgnoredNames in = new IgnoredNames();
// Add file and directory to list of ignored items.
in.add("f:foo.txt");
in.add("d:bar");
// Create an exception listener to detect errors while encoding and decoding
final LinkedList<Exception> exceptions = new LinkedList<>();
ExceptionListener listener = exceptions::addLast;
// Actually create the file and directory for much better test coverage.
File tmpdir = Files.createTempDirectory("ignoredNames").toFile();
File foo = new File(tmpdir, "foo.txt");
foo.createNewFile();
assertTrue(foo.isFile());
File bar = new File(tmpdir, "bar");
bar.mkdir();
assertTrue(bar.isDirectory());
// Store the IgnoredNames object as XML file.
File testXML = new File(tmpdir, "Test.xml");
XMLEncoder e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(testXML)));
e.setExceptionListener(listener);
e.writeObject(in);
e.close();
// Restore the IgnoredNames object from XML file.
XMLDecoder d = new XMLDecoder(new FileInputStream(testXML));
IgnoredNames in2 = (IgnoredNames) d.readObject();
d.close();
// Verify that the XML encoding/decoding did not 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());
}
// Make sure the complete list of items is equal after decoding.
// This will is a simple casual test that cannot verify that sub-classes
// are intact. For that there are the following tests.
assertTrue(in.getItems().containsAll(in2.getItems()));
// Use the restored object to test the matching of file and directory.
assertTrue(in2.ignore("foo.txt"));
assertTrue(in2.ignore("bar"));
assertTrue(in2.ignore(foo));
assertTrue(in2.ignore(bar));
// Cleanup.
IOUtils.removeRecursive(tmpdir.toPath());
}
use of java.beans.ExceptionListener in project omegat by omegat-org.
the class MappingRulesModel method fireException.
public void fireException(Exception e) {
for (int i = listeners.size() - 1; i >= 0; i--) {
ExceptionListener l = listeners.get(i);
l.exceptionThrown(e);
}
}
use of java.beans.ExceptionListener in project omegat by omegat-org.
the class SegmentationRulesModel method fireException.
public void fireException(Exception e) {
for (int i = listeners.size() - 1; i >= 0; i--) {
ExceptionListener l = listeners.get(i);
l.exceptionThrown(e);
}
}
Aggregations