当前位置: 首页>>代码示例>>Java>>正文


Java XMLDecoder.readObject方法代码示例

本文整理汇总了Java中java.beans.XMLDecoder.readObject方法的典型用法代码示例。如果您正苦于以下问题:Java XMLDecoder.readObject方法的具体用法?Java XMLDecoder.readObject怎么用?Java XMLDecoder.readObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.beans.XMLDecoder的用法示例。


在下文中一共展示了XMLDecoder.readObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadAnObjectXML

import java.beans.XMLDecoder; //导入方法依赖的package包/类
public static Object loadAnObjectXML(String path) throws FileNotFoundException {
    try {
        XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(path)));
        Object obj = decoder.readObject();
        decoder.close();
        return obj;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw e;
    }
}
 
开发者ID:phweda,项目名称:MFM,代码行数:12,代码来源:PersistUtils.java

示例2: read

import java.beans.XMLDecoder; //导入方法依赖的package包/类
public Object read(java.io.Reader r) throws IOException, ClassNotFoundException {
    java.io.
    BufferedReader buf = new BufferedReader(r, 4096);
    CharBuffer arr = CharBuffer.allocate(2048);
    buf.mark(arr.capacity());
    buf.read(arr);
    arr.flip();

    Matcher m = Pattern.compile("<java").matcher(arr);
    if (m.find()) {
        buf.reset();
        buf.skip(m.start());
    } else {
        buf.reset();
    }
    XMLDecoder d = new XMLDecoder(new ReaderInputStream(buf, "UTF-8"));
    return d.readObject();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:XMLBeanConvertor.java

示例3: objectXmlDecoder

import java.beans.XMLDecoder; //导入方法依赖的package包/类
/** 
 * 读取由objSource指定的XML文件中的序列化保存的对象,返回的结果经过了List封装 
 * @param objSource 带全部文件路径的文件全名 
 * @return 由XML文件里面保存的对象构成的List列表(可能是一个或者多个的序列化保存的对象)   
 * @throws FileNotFoundException 指定的对象读取资源不存在 
 * @throws IOException 读取发生错误 
 * @throws Exception 其他运行时异常发生 
 */ 
public static List objectXmlDecoder(String objSource)  
 throws FileNotFoundException,IOException,Exception 
{ 
 List objList = new ArrayList();     
 File fin = new File(objSource); 
 FileInputStream fis = new FileInputStream(fin); 
 XMLDecoder decoder = new XMLDecoder(fis); 
 Object obj = null; 
 try 
 { 
  while( (obj = decoder.readObject()) != null) 
  { 
   objList.add(obj); 
  } 
 } 
 catch (Exception e) 
 { 
  // TODO Auto-generated catch block     
 } 
 fis.close(); 
 decoder.close();      
 return objList; 
}
 
开发者ID:LuJiangLin,项目名称:TestDemo1-github,代码行数:32,代码来源:ObjectToXMLUtil.java

示例4: test

import java.beans.XMLDecoder; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:AbstractTest.java

示例5: test

import java.beans.XMLDecoder; //导入方法依赖的package包/类
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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:AbstractTest.java

示例6: validate

import java.beans.XMLDecoder; //导入方法依赖的package包/类
@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");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:TestObject.java

示例7: setText

import java.beans.XMLDecoder; //导入方法依赖的package包/类
@Override public void setText(String code) {
    ByteArrayInputStream stream = new ByteArrayInputStream(code.getBytes(StandardCharsets.UTF_8));
    XMLDecoder decoder = new XMLDecoder(stream);
    checklist = (CheckList) decoder.readObject();
    decoder.close();
    checkListView.setCheckListNode(new CheckListFormNode(checklist, Mode.EDIT));
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:8,代码来源:CheckListEditor.java

示例8: validate

import java.beans.XMLDecoder; //导入方法依赖的package包/类
@Override
protected void validate(XMLDecoder decoder) {
    for (int i = 0; i < 3; i++) {
        if (decoder != decoder.readObject()) {
            throw new Error("decoder instance expected");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TestVar.java

示例9: ReadOnlyURLMapper

import java.beans.XMLDecoder; //导入方法依赖的package包/类
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) {
            }
        }

    }
 
开发者ID:NBANDROIDTEAM,项目名称:NBANDROID-V2,代码行数:15,代码来源:ReadOnlyURLMapper.java

示例10: readObject

import java.beans.XMLDecoder; //导入方法依赖的package包/类
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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:AbstractTest.java

示例11: validate

import java.beans.XMLDecoder; //导入方法依赖的package包/类
@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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:TestJava.java

示例12: decode

import java.beans.XMLDecoder; //导入方法依赖的package包/类
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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:Test6329581.java

示例13: doLoad

import java.beans.XMLDecoder; //导入方法依赖的package包/类
@Override
public void
doLoad(
	InputStream 	in,
	Map				usersMap )
{
	XMLDecoder decoder = new XMLDecoder( in );
	UserManagerConfig managerConfig = (UserManagerConfig)decoder.readObject();
	for (Iterator iter = managerConfig.getUsers().iterator(); iter.hasNext();) {
		UserProfile user = (UserProfile) iter.next();
		usersMap.put(user.getUsername().toLowerCase(), user);
	}
	System.out.println("UserManager: registered " + usersMap.size() + " users");
	decoder.close();
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:16,代码来源:UserManagerXMLPersist.java

示例14: handleXml

import java.beans.XMLDecoder; //导入方法依赖的package包/类
public static Object handleXml(InputStream in) {
    XMLDecoder d = new XMLDecoder(in);
    try {
        Object result = d.readObject(); //Deserialization happen here
        return result;
    }
    finally {
        d.close();
    }
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:11,代码来源:XmlDecodeUtil.java

示例15: main

import java.beans.XMLDecoder; //导入方法依赖的package包/类
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());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:33,代码来源:Test4676532.java


注:本文中的java.beans.XMLDecoder.readObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。