Search in sources :

Example 16 with XMLDecoder

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XMLDecoder(java.beans.XMLDecoder) List(java.util.List) ConcurrentAccessException(javax.ejb.ConcurrentAccessException) MalformedURLException(java.net.MalformedURLException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ConcurrentAccessException(javax.ejb.ConcurrentAccessException) Test(org.junit.Test)

Example 17 with XMLDecoder

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();
}
Also used : XMLDecoder(java.beans.XMLDecoder)

Example 18 with XMLDecoder

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;
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) XMLDecoder(java.beans.XMLDecoder) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 19 with XMLDecoder

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;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) XMLDecoder(java.beans.XMLDecoder) IOException(java.io.IOException) LinkedList(java.util.LinkedList) IOException(java.io.IOException)

Example 20 with XMLDecoder

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;
    }
}
Also used : XMLEncoder(java.beans.XMLEncoder) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLDecoder(java.beans.XMLDecoder) ExceptionListener(java.beans.ExceptionListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AssertionFailedError(junit.framework.AssertionFailedError) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

XMLDecoder (java.beans.XMLDecoder)24 ByteArrayInputStream (java.io.ByteArrayInputStream)15 XMLEncoder (java.beans.XMLEncoder)7 IOException (java.io.IOException)7 ExceptionListener (java.beans.ExceptionListener)6 LinkedList (java.util.LinkedList)6 BufferedInputStream (java.io.BufferedInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Test (org.junit.Test)5 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 AssertionFailedError (junit.framework.AssertionFailedError)4 File (java.io.File)3 BufferedOutputStream (java.io.BufferedOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 MapNode (aimax.osm.data.entities.MapNode)1 MapViewEvent (aimax.osm.viewer.MapViewEvent)1