Search in sources :

Example 46 with XMLEncoder

use of java.beans.XMLEncoder in project omegat by omegat-org.

the class SRX method saveTo.

/**
 * Saves segmentation rules into specified file.
 */
public static void saveTo(SRX srx, File outFile) throws IOException {
    if (srx == null) {
        outFile.delete();
        return;
    }
    try {
        srx.setVersion(CURRENT_VERSION);
        XMLEncoder xmlenc = new XMLEncoder(new FileOutputStream(outFile));
        xmlenc.writeObject(srx);
        xmlenc.close();
    } catch (IOException ioe) {
        Log.logErrorRB("CORE_SRX_ERROR_SAVING_SEGMENTATION_CONFIG");
        Log.log(ioe);
        throw ioe;
    }
}
Also used : XMLEncoder(java.beans.XMLEncoder) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Example 47 with XMLEncoder

use of java.beans.XMLEncoder in project JavaYouShouldKnow by CFMystery.

the class JavaXml method saveToXML.

public void saveToXML(Object o) throws IOException {
    File xmlFile = new File("file/out/object.xml");
    if (!xmlFile.exists()) {
        xmlFile.createNewFile();
    }
    FileOutputStream ofs = new FileOutputStream(xmlFile);
    XMLEncoder xe = new XMLEncoder(ofs);
    xe.writeObject(o);
    xe.close();
    ofs.close();
}
Also used : XMLEncoder(java.beans.XMLEncoder) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 48 with XMLEncoder

use of java.beans.XMLEncoder in project Java8 by huhuhuHR.

the class ObjectToXMLUtil method objectXmlEncode.

@SneakyThrows
public static void objectXmlEncode(Object obj, String fileName) {
    var fo = new File(fileName);
    if (fo.exists()) {
        fo.delete();
    }
    fo.createNewFile();
    @Cleanup var fos = new FileOutputStream(fo);
    @Cleanup var encoder = new XMLEncoder(fos);
    encoder.writeObject(obj);
    encoder.flush();
}
Also used : XMLEncoder(java.beans.XMLEncoder) lombok.experimental.var(lombok.experimental.var) FileOutputStream(java.io.FileOutputStream) File(java.io.File) Cleanup(lombok.Cleanup) SneakyThrows(lombok.SneakyThrows)

Example 49 with XMLEncoder

use of java.beans.XMLEncoder in project java-swing-tips by aterai.

the class LoadSaveTask method saveWindowState.

protected static void saveWindowState(PersistenceService ps, URL codebase, WindowState windowState) {
    try {
        FileContents fc = ps.get(codebase);
        try (XMLEncoder e = new XMLEncoder(new BufferedOutputStream(fc.getOutputStream(true)))) {
            // Test: delete muf ex.
            // C:\Users\(user)\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\muffin\xxx-xxx.muf
            // ps.delete(codebase);
            // ObjectOutputStream e = new ObjectOutputStream(fc.getOutputStream(true));
            HashMap<String, Serializable> map = new HashMap<>();
            map.put("size", (Serializable) windowState.getSize());
            map.put("location", (Serializable) windowState.getLocation());
            // Test1: map.put("setting", (Serializable) windowState);
            // Test2: e.writeObject(windowState);
            e.writeObject(map);
            e.flush();
        // e.close();
        }
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}
Also used : XMLEncoder(java.beans.XMLEncoder) Serializable(java.io.Serializable) FileContents(javax.jnlp.FileContents) HashMap(java.util.HashMap) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 50 with XMLEncoder

use of java.beans.XMLEncoder in project antlrworks by antlr.

the class XJDataXML method writeData.

@Override
public void writeData() throws IOException {
    XMLEncoder e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(getFile())));
    e.writeObject(dictionary);
    customWriteData(e);
    e.close();
}
Also used : XMLEncoder(java.beans.XMLEncoder)

Aggregations

XMLEncoder (java.beans.XMLEncoder)51 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 BufferedOutputStream (java.io.BufferedOutputStream)19 FileOutputStream (java.io.FileOutputStream)14 IOException (java.io.IOException)13 XMLDecoder (java.beans.XMLDecoder)11 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Test (org.junit.Test)9 File (java.io.File)8 LinkedList (java.util.LinkedList)7 FileInputStream (java.io.FileInputStream)6 AssertionFailedError (junit.framework.AssertionFailedError)6 ExceptionListener (java.beans.ExceptionListener)5 PersistenceDelegate (java.beans.PersistenceDelegate)4 BufferedInputStream (java.io.BufferedInputStream)4 DefaultPersistenceDelegate (java.beans.DefaultPersistenceDelegate)3 Encoder (java.beans.Encoder)3 OutputStream (java.io.OutputStream)3 Metacard (ddf.catalog.data.Metacard)2 Query (ddf.catalog.operation.Query)2