Java 8 XMLDecoder - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 XMLDecoder class.

This code example shows how to use the following methods:close, readObject
		Object result = null; 
		FileInputStream fis = null;
		XMLDecoder xmldec = null;
		try { 
			fis = new FileInputStream(source);
			xmldec = new XMLDecoder(new BufferedInputStream(fis));
			result = xmldec.readObject();
		} finally { 
			StreamUtil.close(fis);
			if (xmldec != null) {
				xmldec.close();
			} 
		} 
		return result; 
	} 
 
	/** 
	 * @see #readObjectFromXml(java.io.File) 
	 */ 
	public static Object readObjectFromXml(String source) throws IOException {
6
CodeRank
This code example shows how to use the following methods:close, readObject
            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;
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:close, readObject
	public <T> T valueOf(byte[] str, Class<T> type) throws ParseException {
		if (str == null) {
			return null; 
		} 
		ByteArrayInputStream bi = new ByteArrayInputStream(str);
		XMLDecoder xd = new XMLDecoder(bi);
		try { 
			return (T) xd.readObject();
		} finally { 
			xd.close();
		} 
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:close, readObject, setExceptionListener
            encoder.setExceptionListener(this);
            encoder.writeObject(string);
            encoder.close();
 
            FileInputStream input = new FileInputStream(file);
            XMLDecoder decoder = new XMLDecoder(input);
            decoder.setExceptionListener(this);
            Object object = decoder.readObject();
            decoder.close();
 
            if (!string.equals(object))
                throw new Error(this.encoding + " - can't read properly");
 
            file.delete();
        } 
        catch (FileNotFoundException exception) {
            throw new Error(this.encoding + " - file not found", exception);
        } 
        catch (IllegalCharsetNameException exception) {
            throw new Error(this.encoding + " - illegal charset name", exception);
6
CodeRank
This code example shows how to use the following methods:close, readObject
		this.xmlToDecode = xmlToDecode;
	} 
	 
	public AbstractReportObject toAbstractReportObject() { 
		ExceptionListener exListener = new ReportObjectWrapperExceptionListener();
		XMLDecoder dec = new XMLDecoder(new BufferedInputStream(new ByteArrayInputStream(xmlToDecode.getBytes())), null,
		        exListener);
		AbstractReportObject o = (AbstractReportObject) dec.readObject();
		dec.close();
		 
		return o;
	} 
	 
	/** 
	 * @return Returns the xmlToDecode. 
	 */ 
	public String getXmlToDecode() {
		return xmlToDecode;
	} 
	 
6
CodeRank
This code example shows how to use the following methods:readObject
   */ 
  @SuppressWarnings("unchecked") 
  public EventData(String xml) {
    ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
    try { 
      XMLDecoder decoder = new XMLDecoder(bais);
      this.eventData = (Map<String, Object>) decoder.readObject();
    } catch (Exception e) {
      throw new EventException("Error decoding " + xml, e);
    } 
  } 
 
  /** 
   * Serialize all the EventData items into an XML representation. 
   *  
   * @return an XML String containing all the EventDAta items. 
   */ 
  public String toXML() {
    return toXML(eventData); 
  } 
6
CodeRank
This code example shows how to use the following methods:close, readObject
 
    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();
    } 
 
    public static class DataBean { 
        private boolean illegal;
 
        public boolean isIllegal() { 
            return this.illegal;
        } 
 
        public void setIllegal(boolean illegal) {
            this.illegal = illegal;
        } 
6
CodeRank
This code example shows how to use the following methods:readObject
		if (raw.length() == 0) {
			return new PublicKeyFriendBean[0]; 
		} 
		PublicKeyFriendBean[] res = null;
		ByteArrayInputStream in = new ByteArrayInputStream(raw.getBytes("UTF-8"));
		XMLDecoder d = new XMLDecoder(in);
 
		Object o = d.readObject();
		if (o instanceof PublicKeyFriendBean[]) { 
			res = ((PublicKeyFriendBean[]) o);
		} 
		in.close();
		if (!oldClassLoader.equals(beanClassLoader)) {
			log("setting old classloader: " + oldClassLoader);
			Thread.currentThread().setContextClassLoader(oldClassLoader);
		} 
		return res;
	} 
 
	private static void log(String msg) {
6
CodeRank
This code example shows how to use the following methods:setOwner
 
    @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");
    } 
 
    private static void validate(XMLDecoder decoder, String name) {
        if (!decoder.readObject().equals(name)) {
            throw new Error(name + " expected");
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:close, readObject
            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());
        } 
    } 
} 
6
CodeRank
See Code Examples for Java 8 XMLDecoder Methods: