當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLDecoder類代碼示例

本文整理匯總了Java中java.beans.XMLDecoder的典型用法代碼示例。如果您正苦於以下問題:Java XMLDecoder類的具體用法?Java XMLDecoder怎麽用?Java XMLDecoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XMLDecoder類屬於java.beans包,在下文中一共展示了XMLDecoder類的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: decodeXml

import java.beans.XMLDecoder; //導入依賴的package包/類
/**
 * Decode a Java object, which is contained in the given XML
 * 
 * @param xml
 *            a XML string
 * @return a Java object
 * @throws BillingException
 *             if the XML decoding fails
 */
Object decodeXml(String xml) throws BillingException {

    if (xml != null) {
        try (XMLDecoder xmlDecoder = new XMLDecoder(
                new ByteArrayInputStream(
                        xml.getBytes(StandardCharsets.UTF_8)))) {
            return xmlDecoder.readObject();
        } catch (Exception e) {
            throw new BillingException(
                    "File application response decoding error.");
        }
    } else {
        return null;
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:25,代碼來源:RestDAO.java

示例4: 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

示例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: 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:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:AbstractTest.java

示例7: validate

import java.beans.XMLDecoder; //導入依賴的package包/類
@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");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:TestArray.java

示例8: 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

示例9: toObject

import java.beans.XMLDecoder; //導入依賴的package包/類
/**
 * To object.
 *
 * @param xml
 *            the xml
 * @return the object
 */
public static Object toObject(final String xml) {
	// XStream x = createXStream();
	// return x.fromXML(xml);
	// try {
	final ByteArrayInputStream out = new ByteArrayInputStream(xml.getBytes());
	final XMLDecoder encoder = new XMLDecoder(out);
	final Object object = encoder.readObject();
	//
	encoder.close();
	return object;
	// } catch (Exception e) {
	// System.err.println("Failed to decode object : \n" + xml);
	// return null;
	// }
	// return null;
}
 
開發者ID:kiswanij,項目名稱:jk-util,代碼行數:24,代碼來源:JKObjectUtil.java

示例10: load

import java.beans.XMLDecoder; //導入依賴的package包/類
public List<HttpPostForm> load() {
    final List<HttpPostForm> list = new ArrayList<>();

    final FileObject fo = getSaveFolder();
    final File fileFolder = FileUtil.toFile(fo);

    final File[] files = fileFolder.listFiles();
    for (int i = 0; i < files.length; i++) {
        final File aFile = files[i];

        try (FileInputStream fis = new FileInputStream(aFile)) {
            XMLDecoder xmlDec = new XMLDecoder(fis);
            HttpPostForm hpf = (HttpPostForm) xmlDec.readObject();

            list.add(hpf);
        } catch (IOException ex) {
            ErrorManager.getDefault().notify(ex);
        }
    }
    return list;
}
 
開發者ID:bernhardhuber,項目名稱:netbeansplugins,代碼行數:22,代碼來源:Persistance.java

示例11: read

import java.beans.XMLDecoder; //導入依賴的package包/類
public static CheckList read(File file) throws Exception {
    XMLDecoder decoder = new XMLDecoder(new FileInputStream(file));
    try {
        return (CheckList) decoder.readObject();
    } finally {
        decoder.close();
    }
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:9,代碼來源:CheckList.java

示例12: 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

示例13: getObjectFromXML_closeStream

import java.beans.XMLDecoder; //導入依賴的package包/類
@Test
public void getObjectFromXML_closeStream() throws Exception {
    // given
    ResultSet rs = mock(ResultSet.class);
    InputStream is = mock(InputStream.class);
    doReturn(is).when(rs).getBinaryStream(eq("value"));
    XMLDecoder decoder = mock(XMLDecoder.class);
    doReturn(decoder).when(dbtask).newXmlDecoder(any(InputStream.class));

    // when
    dbtask.getObjectFromXML(rs, String.class);

    // then
    verify(dbtask).closeStream(is);
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:16,代碼來源:MigrateTriggersTest.java

示例14: loadConfigFromFile

import java.beans.XMLDecoder; //導入依賴的package包/類
@Override
public <E> E loadConfigFromFile(String fileName, Class<E> type) throws Exception {
    try(XMLDecoder xmlDecoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(getFileForFilename(fileName))), null, null, type.getClassLoader())) {
        Object theObject = xmlDecoder.readObject();
        if(type.isInstance(theObject)) {
            return type.cast(theObject);
        } else {
            LOGGER.warn("Unknown file format {}. Not {}.", fileName, type.getName());
            throw new Exception("Unknown file format");
        }
    } catch (RuntimeException e) {
        throw new Exception(e);
    }
}
 
開發者ID:jhkst,項目名稱:dlface,代碼行數:15,代碼來源:FrdStorageSupportImpl.java

示例15: 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


注:本文中的java.beans.XMLDecoder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。