java.beans.XMLDecoder Java Examples

The following examples show how to use java.beans.XMLDecoder. 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: TestArray.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    Number[] numbers = getArray(Number.class, 2, decoder.readObject());
    if (!numbers[0].equals(Byte.valueOf("-111"))) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected byte value");
    }
    if (!numbers[1].equals(Long.valueOf("1111"))) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected long value");
    }

    Object[] objects = getArray(Object.class, 3, decoder.readObject());
    if (objects[0] != null) {
        throw new Error("unexpected first value");
    }
    if (!objects[1].equals("Hello, world!")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected string value");
    }
    if (objects[2] != null) {
        throw new Error("unexpected last value");
    }
}
 
Example #2
Source File: TestArray.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    Number[] numbers = getArray(Number.class, 2, decoder.readObject());
    if (!numbers[0].equals(Byte.valueOf("-111"))) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected byte value");
    }
    if (!numbers[1].equals(Long.valueOf("1111"))) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected long value");
    }

    Object[] objects = getArray(Object.class, 3, decoder.readObject());
    if (objects[0] != null) {
        throw new Error("unexpected first value");
    }
    if (!objects[1].equals("Hello, world!")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected string value");
    }
    if (objects[2] != null) {
        throw new Error("unexpected last value");
    }
}
 
Example #3
Source File: TestObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    JPanel panel = (JPanel) decoder.readObject();
    if (2 != panel.getComponents().length) {
        throw new Error("unexpected component count");
    }
    JButton button = (JButton) panel.getComponents()[0];
    if (!button.getText().equals("button")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected button text");
    }
    if (SwingConstants.CENTER != button.getVerticalAlignment()) {
        throw new Error("unexpected vertical alignment");
    }
    JLabel label = (JLabel) panel.getComponents()[1];
    if (!label.getText().equals("label")) { // NON-NLS: hardcoded in XML
        throw new Error("unexpected label text");
    }
    if (button != label.getLabelFor()) {
        throw new Error("unexpected component");
    }
}
 
Example #4
Source File: AbstractTest.java    From jdk8u-jdk 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 #5
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 #6
Source File: TestJava.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    decoder.setOwner(this);
    if (this != decoder.readObject()) {
        throw new Error("owner should be the same");
    }
    if (this.message == null) {
        throw new Error("owner's method is not called");
    }
}
 
Example #7
Source File: TestJava.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    decoder.setOwner(this);
    if (this != decoder.readObject()) {
        throw new Error("owner should be the same");
    }
    if (this.message == null) {
        throw new Error("owner's method is not called");
    }
}
 
Example #8
Source File: TestFloat.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    validate(0.0f, decoder.readObject());
    validate(100.0f, decoder.readObject());
    validate(-1e15f, decoder.readObject());
    validate(100e-20f, decoder.readObject());
}
 
Example #9
Source File: JavaElementHandler.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the owner of the owner document handler
 * as a value of <java> element.
 *
 * @return the owner of the owner document handler
 */
private Object getValue() {
    Object owner = getOwner().getOwner();
    if ((this.type == null) || isValid(owner)) {
        return owner;
    }
    if (owner instanceof XMLDecoder) {
        XMLDecoder decoder = (XMLDecoder) owner;
        owner = decoder.getOwner();
        if (isValid(owner)) {
            return owner;
        }
    }
    throw new IllegalStateException("Unexpected owner class: " + owner.getClass().getName());
}
 
Example #10
Source File: JavaElementHandler.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the owner of the owner document handler
 * as a value of <java> element.
 *
 * @return the owner of the owner document handler
 */
private Object getValue() {
    Object owner = getOwner().getOwner();
    if ((this.type == null) || isValid(owner)) {
        return owner;
    }
    if (owner instanceof XMLDecoder) {
        XMLDecoder decoder = (XMLDecoder) owner;
        owner = decoder.getOwner();
        if (isValid(owner)) {
            return owner;
        }
    }
    throw new IllegalStateException("Unexpected owner class: " + owner.getClass().getName());
}
 
Example #11
Source File: TestDouble.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    validate(0.0, decoder.readObject());
    validate(1000.0, decoder.readObject());
    validate(-1.1e15, decoder.readObject());
    validate(10.11e-123, decoder.readObject());
}
 
Example #12
Source File: Test6338070.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #13
Source File: Test6329581.java    From jdk8u-dev-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 #14
Source File: AbstractTest.java    From openjdk-jdk8u 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 #15
Source File: Test4676532.java    From TencentKona-8 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 #16
Source File: TestField.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    FIELD = "static prefix";
    field = "prefix";
    decoder.setOwner(this);
    validate(decoder, "static prefix");
    validate(decoder, "static postfix");
    validate(decoder, "prefix");
    validate(decoder, "postfix");
}
 
Example #17
Source File: RunLabAction.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    try {
        XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(
                       new FileInputStream(labFile)));
         Lab lab= (Lab)decoder.readObject();
         lab.execute();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    }

}
 
Example #18
Source File: TestFloat.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    validate(0.0f, decoder.readObject());
    validate(100.0f, decoder.readObject());
    validate(-1e15f, decoder.readObject());
    validate(100e-20f, decoder.readObject());
}
 
Example #19
Source File: TestVar.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    for (int i = 0; i < 3; i++) {
        if (decoder != decoder.readObject()) {
            throw new Error("decoder instance expected");
        }
    }
}
 
Example #20
Source File: TestVar.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    for (int i = 0; i < 3; i++) {
        if (decoder != decoder.readObject()) {
            throw new Error("decoder instance expected");
        }
    }
}
 
Example #21
Source File: AbstractTest.java    From openjdk-8-source 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 #22
Source File: NukeBeans.java    From drftpd with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Legacy XML loader
 * Deserializes the Nukelog Map.
 */
@SuppressWarnings("unchecked")
private void loadXMLLRUMap(Map<String, NukeData> nukees) {
    // de-serializing the Hashtable.
    try (XMLDecoder xd = new XMLDecoder(new FileInputStream(
            _nukebeansPath + VirtualFileSystem.separator + "nukebeans.xml"))) {
        //switchClassLoaders();
        nukees.putAll((Map<String, NukeData>) xd.readObject());
        logger.debug("Loaded log from .xml, size: {}", nukees.size());
    } catch (FileNotFoundException e) {
        // nukelog does not exists yet.
    }
}
 
Example #23
Source File: AbstractTest.java    From jdk8u60 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 #24
Source File: CacheTypeTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
private <T> T copyObjectViaXmlEncoder(T o) {
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  XMLEncoder enc = new XMLEncoder(bos);
  enc.writeObject(o);
  enc.close();
  ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
  XMLDecoder dec = new XMLDecoder(bin);
  Object o2 = dec.readObject();
  dec.close();
  assertTrue("no reference identity", o2 != o);
  assertEquals("same class", o.getClass(), o2.getClass());
  return (T) o2;
}
 
Example #25
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 #26
Source File: ReadOnlyURLMapper.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public ReadOnlyURLMapper() {

        if (LASTPLATFORMS_FILE.exists()) {
            try {
                XMLDecoder decoder = new XMLDecoder(new FileInputStream(LASTPLATFORMS_FILE));
                String[] last = (String[]) decoder.readObject();
                if (last != null) {
                    reference.set(last);
                }
            } catch (Exception ex) {
            }
        }

    }
 
Example #27
Source File: TestNew.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    validate(decoder.readObject());
    validate(decoder.readObject(), null);
    validate(decoder.readObject(), "single");
    validate(decoder.readObject(), "first", "second", "third");
}
 
Example #28
Source File: TestMethod.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    this.exception = null;
    validate(decoder, A.class);
    validate(decoder, B.class);
    validate(decoder, C.class);
    validate(decoder, D.class);
    validate(decoder, E.class);
    if (this.exception == null) {
        throw new Error("NoSuchMethodException expected");
    }
}
 
Example #29
Source File: TestMethod.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void validate(XMLDecoder decoder) {
    this.exception = null;
    validate(decoder, A.class);
    validate(decoder, B.class);
    validate(decoder, C.class);
    validate(decoder, D.class);
    validate(decoder, E.class);
    if (this.exception == null) {
        throw new Error("NoSuchMethodException expected");
    }
}
 
Example #30
Source File: Test.java    From native-obfuscator with GNU General Public License v3.0 5 votes vote down vote up
public static Character encodeDecode(Character character) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(out);
    encoder.writeObject(character);
    encoder.close();
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    return (Character)new XMLDecoder(in).readObject();

}