Java Code Examples for java.beans.XMLDecoder#close()

The following examples show how to use java.beans.XMLDecoder#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: AbstractTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This is entry point to start testing.
 *
 * @param security  use {@code true} to start
 *                  second pass in secure context
 */
final void test(boolean security) {
    byte[] array = getFieldValue("XML").getBytes(); // NON-NLS: the field name
    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);
    }
}
 
Example 3
Source File: AbstractTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This is entry point to start testing.
 *
 * @param security  use {@code true} to start
 *                  second pass in secure context
 */
final void test(boolean security) {
    byte[] array = getFieldValue("XML").getBytes(); // NON-NLS: the field name
    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);
    }
}
 
Example 4
Source File: AbstractTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This is entry point to start testing.
 *
 * @param security  use {@code true} to start
 *                  second pass in secure context
 */
final void test(boolean security) {
    byte[] array = getFieldValue("XML").getBytes(); // NON-NLS: the field name
    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);
    }
}
 
Example 5
Source File: AbstractTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 6
Source File: AbstractTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
}
 
Example 7
Source File: Test4676532.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example 8
Source File: Test6341798.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(Locale locale, byte[] data) {
    Locale.setDefault(locale);
    System.out.println("locale = " + locale);

    XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(data));
    System.out.println("object = " + decoder.readObject());
    decoder.close();
}
 
Example 9
Source File: Test4676532.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example 10
Source File: AbstractTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 11
Source File: Test6329581.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private Object decode(byte[] array) {
    ByteArrayInputStream in = new ByteArrayInputStream(array);
    XMLDecoder decoder = new XMLDecoder(in, null, this, this);
    Object object = decoder.readObject();
    validate(object);
    decoder.close();
    return object;
}
 
Example 12
Source File: Test6341798.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void test(Locale locale, byte[] data) {
    Locale.setDefault(locale);
    System.out.println("locale = " + locale);

    XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(data));
    System.out.println("object = " + decoder.readObject());
    decoder.close();
}
 
Example 13
Source File: Test4676532.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    StringBuilder sb = new StringBuilder(256);
    sb.append("file:");
    sb.append(System.getProperty("test.src", "."));
    sb.append(File.separatorChar);
    sb.append("test.jar");

    URL[] url = {new URL(sb.toString())};
    URLClassLoader cl = new URLClassLoader(url);

    Class type = cl.loadClass("test.Test");
    if (type == null) {
        throw new Error("could not find class test.Test");
    }


    InputStream stream = new ByteArrayInputStream(DATA.getBytes());

    ExceptionListener el = new ExceptionListener() {
        public void exceptionThrown(Exception exception) {
            throw new Error("unexpected exception", exception);
        }
    };

    XMLDecoder decoder = new XMLDecoder(stream, null, el, cl);
    Object object = decoder.readObject();
    decoder.close();

    if (!type.equals(object.getClass())) {
        throw new Error("unexpected " + object.getClass());
    }
}
 
Example 14
Source File: Test6329581.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private Object decode(byte[] array) {
    ByteArrayInputStream in = new ByteArrayInputStream(array);
    XMLDecoder decoder = new XMLDecoder(in, null, this, this);
    Object object = decoder.readObject();
    validate(object);
    decoder.close();
    return object;
}
 
Example 15
Source File: Test6329581.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private Object decode(byte[] array) {
    ByteArrayInputStream in = new ByteArrayInputStream(array);
    XMLDecoder decoder = new XMLDecoder(in, null, this, this);
    Object object = decoder.readObject();
    validate(object);
    decoder.close();
    return object;
}
 
Example 16
Source File: MainFrame.java    From procamtracker with GNU General Public License v2.0 5 votes vote down vote up
void loadSettings(File file) throws IOException, IntrospectionException, PropertyVetoException {
    if (file == null) {
        cameraSettings = null;
        projectorSettings = null;
        objectFinderSettings = null;
        markerDetectorSettings = null;
        alignerSettings = null;
        handMouseSettings = null;
        virtualBallSettings = null;
        realityAugmentorSettings = null;
        trackingSettings = null;

        trackingWorker = null;
    } else {
        XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(file)));
        cameraSettings = (CameraDevice.Settings)decoder.readObject();
        projectorSettings = (ProjectorDevice.Settings)decoder.readObject();
        objectFinderSettings = (ObjectFinder.Settings)decoder.readObject();
        markerDetectorSettings = (MarkerDetector.Settings)decoder.readObject();
        alignerSettings = (GNImageAligner.Settings)decoder.readObject();
        handMouseSettings = (HandMouse.Settings)decoder.readObject();
        virtualBallSettings = (VirtualBall.Settings)decoder.readObject();
        realityAugmentorSettings = (RealityAugmentor.Settings)decoder.readObject();
        trackingSettings = (TrackingWorker.Settings)decoder.readObject();
        decoder.close();
    }

    settingsFile = file;
    if (settingsFile == null) {
        setTitle("ProCamTracker");
    } else {
        setTitle(settingsFile.getName() + " - ProCamTracker");
    }

    buildSettingsView();

    if (trackingWorker == null) {
        statusLabel.setText("Idling.");
    }
}
 
Example 17
Source File: Test6341798.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(Locale locale, byte[] data) {
    Locale.setDefault(locale);
    System.out.println("locale = " + locale);

    XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(data));
    System.out.println("object = " + decoder.readObject());
    decoder.close();
}
 
Example 18
Source File: Test4822050.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void parse() {
    XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(this.buffer));
    decoder.readObject();
    decoder.close();
}
 
Example 19
Source File: Test4822050.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void parse() {
    XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(this.buffer));
    decoder.readObject();
    decoder.close();
}
 
Example 20
Source File: Test4822050.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void parse() {
    XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(this.buffer));
    decoder.readObject();
    decoder.close();
}