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


Java XMLEncoder.flush方法代碼示例

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


在下文中一共展示了XMLEncoder.flush方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: objectXmlEncoder

import java.beans.XMLEncoder; //導入方法依賴的package包/類
/** 
 * 把java的可序列化的對象(實現Serializable接口)序列化保存到XML文件裏麵,如果想一次保存多個可序列化對象請用集合進行封裝 
 * 保存時將會用現在的對象原來的XML文件內容 
 * @param obj 要序列化的可序列化的對象 
 * @param fileName 帶完全的保存路徑的文件名  
 * @throws FileNotFoundException 指定位置的文件不存在 
 * @throws IOException 輸出時發生異常 
 * @throws Exception 其他運行時異常 
 */ 
public static void objectXmlEncoder(Object obj,String fileName) 
 throws FileNotFoundException,IOException,Exception 
{   
 //創建輸出文件 
 File fo = new File(fileName); 
 //文件不存在,就創建該文件 
 if(!fo.exists()) 
 { 
  //先創建文件的目錄 
     String path = fileName.substring(0,fileName.lastIndexOf('.')); 
     File pFile = new File(path); 
     pFile.mkdirs();          
 } 
 //創建文件輸出流 
 FileOutputStream fos = new FileOutputStream(fo); 
 //創建XML文件對象輸出類實例 
 XMLEncoder encoder = new XMLEncoder(fos);   
 //對象序列化輸出到XML文件 
 encoder.writeObject(obj); 
 encoder.flush();  
 //關閉序列化工具 
 encoder.close(); 
 //關閉輸出流 
 fos.close();     
}
 
開發者ID:LuJiangLin,項目名稱:TestDemo1-github,代碼行數:35,代碼來源:ObjectToXMLUtil.java

示例2: objectXmlEncoder

import java.beans.XMLEncoder; //導入方法依賴的package包/類
/**
 * 將Object序列化到XML文件
 * @param obj 目標對象
 * @param fileName 完整路徑的文件名
 * @throws IOException
 */
public static void objectXmlEncoder(Object obj , String fileName) throws IOException{
	 File fo = new File(fileName);
	 //文件不存在,就創建該文件
	 if(!fo.exists()){
		 String path = fileName.substring(0,fileName.lastIndexOf('.'));
		 File pFile = new File(path);
		 pFile.mkdirs();
	 }
	 FileOutputStream fos = new FileOutputStream(fo);
	 //創建XML文件對象輸出類實例
	 XMLEncoder encoder = new XMLEncoder(fos);
	 //對象序列化輸出到XML文件
	 encoder.writeObject(obj);
	 encoder.flush();
	 encoder.close();
	 fos.close();
}
 
開發者ID:leopardoooo,項目名稱:cambodia,代碼行數:24,代碼來源:XMLHelper.java

示例3: serialize

import java.beans.XMLEncoder; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public <T> int serialize(T obj, Class<T> type, OutputStream out) throws IOException {
    out = new CountingOutputStream(new BufferedOutputStream(out, getBufferSize()));
    EL el = new EL();
    XMLEncoder enc = new XMLEncoder(out);
    try {
        enc.setExceptionListener(el);
        enc.writeObject(obj);
        enc.flush();
    } finally {
        if (isCloseEnabled()) {
            enc.close();
        }
    }
    IOException ioe = el.getIOException();
    if (ioe != null) {
        throw ioe;
    }
    return ((CountingOutputStream)out).getCount();
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:24,代碼來源:XMLBeanSerializer.java

示例4: serialize

import java.beans.XMLEncoder; //導入方法依賴的package包/類
@Override
public boolean serialize(Object src, OutputStream dst) throws IOException {
    XMLEncoder encoder = new XMLEncoder(dst);
    encoder.writeObject(src);
    encoder.flush();
    encoder.close();
    return false;
}
 
開發者ID:worldiety,項目名稱:homunculus,代碼行數:9,代碼來源:Xml.java

示例5: propertyChange

import java.beans.XMLEncoder; //導入方法依賴的package包/類
@Override
public void propertyChange(PropertyChangeEvent evt) {

    Runnable runnable = new Runnable() {
        public void run() {
            Collection<? extends AndroidJavaPlatformProvider8> providers = Lookup.getDefault().lookupAll(AndroidJavaPlatformProvider8.class);
            List<String> tmp = new ArrayList<>();
            for (AndroidJavaPlatformProvider8 provider : providers) {
                if (provider != null) {
                    JavaPlatform[] installedPlatforms = provider.getInstalledPlatforms();
                    for (JavaPlatform installedPlatform : installedPlatforms) {
                        List<ClassPath.Entry> entries = installedPlatform.getSourceFolders().entries();
                        for (ClassPath.Entry entrie : entries) {
                            if (!tmp.contains(entrie.getURL().getPath())) {
                                tmp.add(entrie.getURL().getPath());
                            }
                        }
                    }
                }
            }
            try {
                XMLEncoder encoder = new XMLEncoder(new FileOutputStream(LASTPLATFORMS_FILE));
                encoder.writeObject(tmp.toArray(new String[tmp.size()]));
                encoder.flush();
                encoder.close();
            } catch (Exception ex) {
            }
            reference.set(tmp.toArray(new String[tmp.size()]));
        }
    };
    POOL.execute(runnable);
}
 
開發者ID:NBANDROIDTEAM,項目名稱:NBANDROID-V2,代碼行數:33,代碼來源:ReadOnlyURLMapper.java

示例6: encodeToString

import java.beans.XMLEncoder; //導入方法依賴的package包/類
private String encodeToString(Object object) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(bos);

    encoder.writeObject(object);
    encoder.flush();
    encoder.close();

    try {
        return new String(bos.toByteArray(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        LOG.error("Oops", e);
        throw new IllegalArgumentException(e);
    }
}
 
開發者ID:cucina,項目名稱:opencucina,代碼行數:16,代碼來源:XmlEncoderDecoderConverter.java

示例7: marshallObject

import java.beans.XMLEncoder; //導入方法依賴的package包/類
/**
 * Get a by array by serializing the specified object as XML
 * 
 * @param object
 *            an object
 */
public static byte[] marshallObject(Object object) {
    if (object == null) {
        throw new IllegalArgumentException("Null is not serializable");
    }
    if (!Serializable.class.isAssignableFrom(object.getClass())) {
        throw new IllegalArgumentException("The object must be Serializable");
    }
    ByteArrayOutputStream baOut = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(baOut);
    encoder.writeObject(object);
    encoder.flush();
    encoder.close();
    return baOut.toByteArray();
}
 
開發者ID:theAgileFactory,項目名稱:app-framework,代碼行數:21,代碼來源:Utilities.java

示例8: writeDeadLetterToFile

import java.beans.XMLEncoder; //導入方法依賴的package包/類
/**
 * Write the dead letters to the file system
 * 
 * @param deadLetter
 *            a dead letter
 */
private void writeDeadLetterToFile(DeadLetter deadLetter) {
    String fileName = String.format(OUTPUT_FILE_NAME_TEMPLATE, deadLetter.recipient().path().name(), new Date(), ".log");
    BufferedWriter bWriter = null;
    try {
        bWriter = new BufferedWriter(new FileWriter(new File(getDeadLetterFileSystem(), fileName)));
        // Serialize the message as XML
        ByteArrayOutputStream baOut = new ByteArrayOutputStream();
        XMLEncoder encoder = new XMLEncoder(baOut);
        if (deadLetter.message() != null) {
            encoder.writeObject(deadLetter.message());
        }
        encoder.flush();
        encoder.close();
        // Write it to a file
        // First line is actor path
        bWriter.write(deadLetter.recipient().path().toString());
        bWriter.newLine();
        // Then write the message
        bWriter.write(baOut.toString());
        bWriter.flush();
    } catch (Exception e) {
        log.error("Error while writing the dead letter info the dead letters folder", e);
    } finally {
        IOUtils.closeQuietly(bWriter);
    }
}
 
開發者ID:theAgileFactory,項目名稱:app-framework,代碼行數:33,代碼來源:DeadLetterManager.java

示例9: archive

import java.beans.XMLEncoder; //導入方法依賴的package包/類
/**
 * Serializes this gradebook archive into an xml document
 */
public String archive() {
    if(log.isDebugEnabled()) log.debug("GradebookArchive.archive() called");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(baos));
    encoder.writeObject(this);
    encoder.flush();
    String xml = baos.toString();
    if(log.isDebugEnabled()) log.debug("GradebookArchive.archive() finished");
    return xml;
}
 
開發者ID:sakaiproject,項目名稱:sakai,代碼行數:14,代碼來源:GradebookArchive.java

示例10: objectToContent

import java.beans.XMLEncoder; //導入方法依賴的package包/類
private byte[] objectToContent(final Object value) {
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

    final XMLEncoder encoder = new XMLEncoder(byteArrayOutputStream);
    encoder.setExceptionListener(new LogEncoderExceptionListener(value));

    LOG.debug("START Writing Object {} with XMLEncoder", value.getClass().getName());
    encoder.writeObject(value);
    LOG.debug("FINISH Writing Object {} with XMLEncoder", value.getClass().getName());

    encoder.flush();
    encoder.close();
    return byteArrayOutputStream.toByteArray();
}
 
開發者ID:brabenetz,項目名稱:settings4j,代碼行數:15,代碼來源:JavaXMLBeansObjectResolverTest.java

示例11: main

import java.beans.XMLEncoder; //導入方法依賴的package包/類
public static void main(String[] argv)
{
	VixConfigurationStrategy strategy = new VixConfigurationStrategy();
	
	CacheConfigurationMemento memento = strategy.getMemento();
	
	XMLEncoder encoder = new XMLEncoder(System.out);

	encoder.writeObject(memento);
	
	encoder.flush();
	encoder.close();
}
 
開發者ID:VHAINNOVATIONS,項目名稱:Telepathology,代碼行數:14,代碼來源:VixConfigurationStrategy.java

示例12: main

import java.beans.XMLEncoder; //導入方法依賴的package包/類
public static void main(String[] argv)
{
	TestWithNoEvictionConfigurationStrategy strategy = new TestWithNoEvictionConfigurationStrategy();
	
	CacheConfigurationMemento memento = strategy.getMemento();
	
	XMLEncoder encoder = new XMLEncoder(System.out);

	encoder.writeObject(memento);
	
	encoder.flush();
	encoder.close();
}
 
開發者ID:VHAINNOVATIONS,項目名稱:Telepathology,代碼行數:14,代碼來源:TestWithNoEvictionConfigurationStrategy.java

示例13: main

import java.beans.XMLEncoder; //導入方法依賴的package包/類
public static void main(String[] argv)
{
	TestWithEvictionConfigurationStrategy strategy = new TestWithEvictionConfigurationStrategy();
	
	CacheConfigurationMemento memento = strategy.getMemento();
	
	XMLEncoder encoder = new XMLEncoder(System.out);

	encoder.writeObject(memento);
	
	encoder.flush();
	encoder.close();
}
 
開發者ID:VHAINNOVATIONS,項目名稱:Telepathology,代碼行數:14,代碼來源:TestWithEvictionConfigurationStrategy.java


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