Search in sources :

Example 11 with XMLDecoder

use of java.beans.XMLDecoder in project jdk8u_jdk by JetBrains.

the class AbstractTest method test.

/**
     * This is entry point to start testing.
     *
     * @param security  use {@code true} to start
     *                  second pass in secure context
     */
final void test(boolean security) {
    // NON-NLS: the field name
    byte[] array = getFieldValue("XML").getBytes();
    ByteArrayInputStream input = new ByteArrayInputStream(array);
    XMLDecoder decoder = new XMLDecoder(input);
    decoder.setExceptionListener(this);
    validate(decoder);
    try {
        throw new Error("unexpected object" + decoder.readObject());
    } catch (ArrayIndexOutOfBoundsException exception) {
    // expected exception
    }
    decoder.close();
    if (security) {
        System.setSecurityManager(new SecurityManager());
        test(false);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XMLDecoder(java.beans.XMLDecoder)

Example 12 with XMLDecoder

use of java.beans.XMLDecoder in project jdk8u_jdk by JetBrains.

the class AbstractTest method test.

static void test(AbstractTest object) {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(output);
    encoder.setPersistenceDelegate(object.getClass(), new DefaultPersistenceDelegate(new String[] { "value" }));
    encoder.writeObject(object);
    encoder.close();
    System.out.print(output);
    ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
    XMLDecoder decoder = new XMLDecoder(input);
    AbstractTest result = (AbstractTest) decoder.readObject();
    decoder.close();
    if (object.getValue() != result.getValue())
        throw new Error("Should be " + object);
}
Also used : XMLEncoder(java.beans.XMLEncoder) DefaultPersistenceDelegate(java.beans.DefaultPersistenceDelegate) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLDecoder(java.beans.XMLDecoder) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 13 with XMLDecoder

use of java.beans.XMLDecoder in project jdk8u_jdk by JetBrains.

the class AbstractTest method readObject.

private Object readObject(byte[] array) {
    ByteArrayInputStream input = new ByteArrayInputStream(array);
    XMLDecoder decoder = new XMLDecoder(input);
    decoder.setExceptionListener(this);
    initialize(decoder);
    Object object = decoder.readObject();
    decoder.close();
    return object;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XMLDecoder(java.beans.XMLDecoder)

Example 14 with XMLDecoder

use of java.beans.XMLDecoder in project jdk8u_jdk by JetBrains.

the class Test4822050 method parse.

private void parse() {
    XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(this.buffer));
    decoder.readObject();
    decoder.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XMLDecoder(java.beans.XMLDecoder)

Example 15 with XMLDecoder

use of java.beans.XMLDecoder in project jdk8u_jdk by JetBrains.

the class Test6338070 method main.

public static void main(String[] args) {
    Test6338070 test = new Test6338070();
    InputStream stream = new ByteArrayInputStream(DATA.getBytes());
    new XMLDecoder(stream, test).close();
    if (test.message == null) {
        throw new Error("owner's method is not called");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XMLDecoder(java.beans.XMLDecoder)

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