本文整理匯總了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();
}
示例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();
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
}
示例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();
}
示例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);
}
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}