java.beans.XMLEncoder.flush()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(86)

本文整理了Java中java.beans.XMLEncoder.flush()方法的一些代码示例,展示了XMLEncoder.flush()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMLEncoder.flush()方法的具体详情如下:
包路径:java.beans.XMLEncoder
类名称:XMLEncoder
方法名:flush

XMLEncoder.flush介绍

暂无

代码示例

代码示例来源:origin: sakaiproject/sakai

/**
 * 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;
}

代码示例来源:origin: net.sourceforge.ondex.core/workflow-api

/**
 * @param file
 */
public void save(String file) {
  try {
    //"D:/Test.xml"
    FileOutputStream out = new FileOutputStream(file);
    XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(out));
    for (PluginDescription pb : internalIdToPluginDescription.values()) {
      encoder.writeObject(pb);
      encoder.flush();
    }
    out.close();
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: com.intoverflow.booster/booster-core

public static String toXml(final Object o) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    XMLEncoder e = new XMLEncoder(out);
    e.writeObject(o);
    e.flush();
    e.close();
    return new String(out.toByteArray());
  }
}

代码示例来源:origin: com.intoverflow.base/intoverflow-util

public static String toXml(final Object o) {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  XMLEncoder e = new XMLEncoder(out);
  e.writeObject(o);
  e.flush();
  e.close();
  return new String(out.toByteArray());
}

代码示例来源:origin: net.sourceforge.mydoggy/mydoggy-plaf

protected byte[] encode() {
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  XMLEncoder e = new XMLEncoder(os);
  e.writeObject(multiSplitPaneModelRoot);
  e.flush();
  e.close();
  return os.toByteArray();
}

代码示例来源:origin: httl/httl

public byte[] toBytes(String key, Object value) {
  ByteArrayOutputStream bo = new ByteArrayOutputStream();
  XMLEncoder xe = new XMLEncoder(bo);
  try {
    xe.writeObject(value);
    xe.flush();
  } finally {
    xe.close();
  }
  return bo.toByteArray();
}

代码示例来源:origin: com.github.httl/httl

public byte[] toBytes(String key, Object value) {
  ByteArrayOutputStream bo = new ByteArrayOutputStream();
  XMLEncoder xe = new XMLEncoder(bo);
  try {
    xe.writeObject(value);
    xe.flush();
  } finally {
    xe.close();
  }
  return bo.toByteArray();
}

代码示例来源:origin: eu.mihosoft.vrl/vrl

@Override
public boolean save() {
  FileOutputStream out = null;
  try {
    out = new FileOutputStream(file);
  } catch (FileNotFoundException ex) {
    Logger.getLogger(ConfigurationFileImpl.class.getName()).
        log(Level.SEVERE, null, ex);
    try {
      out.close();
    } catch (Exception ex1) {
      Logger.getLogger(ConfigurationFileImpl.class.getName()).
          log(Level.SEVERE, null, ex1);
    }
    return false;
  }
  XMLEncoder e = new XMLEncoder(out);
  e.writeObject(properties);
  e.flush();
  e.close();
  return true;
}

代码示例来源:origin: eu.mihosoft.vrl/vrl

private void save() {
  // no file specified, saving/loading disabled
  if (cacheLocation == null) {
    return;
  }
  FileOutputStream out = null;
  try {
    out = new FileOutputStream(cacheLocation);
  } catch (FileNotFoundException ex) {
    Logger.getLogger(RecentFilesManager.class.getName()).
        log(Level.SEVERE, null, ex);
    try {
      out.close();
    } catch (Exception ex1) {
      Logger.getLogger(RecentFilesManager.class.getName()).
          log(Level.SEVERE, null, ex1);
    }
    return;
  }
  XMLEncoder e = new XMLEncoder(out);
  e.writeObject(recentSessions);
  e.flush();
  e.close();
}

代码示例来源:origin: org.ow2.novabpm/novaBpmIdentity

protected void flush() {
 XMLEncoder encoder = null;
 try {
  encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(
    file)));
  encoder.writeObject(next);
  writeGroups(encoder);
  writeUsers(encoder);
  encoder.flush();
 } catch (IOException ioe) {
  throw new RuntimeException(ioe);
 } finally {
  Misc.close(encoder);
 }
}

代码示例来源:origin: stackoverflow.com

Object1 obj = new Object1();
obj.setName("Girish");
obj.setAccount("3456");
obj.setCity("Ahmedabad");
  FileOutputStream f =new FileOutputStream("Tmp.txt");
XMLEncoder ob =new XMLEncoder (f);
  ob.writeObject(obj);
  ob.flush();

代码示例来源:origin: org.openwfe/openwfe-applic

public static byte[] objectsToByteArray (Object[] objects)
  throws ByteException
{
  java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();
  java.beans.XMLEncoder encoder = new java.beans.XMLEncoder(os);
  try
  {
    for (int i=0; i<objects.length; i++)
    {
      if (objects[i] == null) continue;
      encoder.writeObject(objects[i]);
      encoder.flush();
    }
  }
  catch (final Throwable t)
  {
    throw new ByteException
      ("Failed to encode objects", t);
  }
  return os.toByteArray();
}

代码示例来源:origin: eu.mihosoft.vrl/vrl

private static void saveRequests() {
  File f = new File(
      VRL.getPropertyFolderManager().getPluginUpdatesFolder(),
      ".uninstall-requests.xml");
  XMLEncoder e = null;
  try {
    e = new XMLEncoder(new FileOutputStream(f));
    e.writeObject(requests);
  } catch (FileNotFoundException ex) {
    Logger.getLogger(UninstallPluginController.class.getName()).
        log(Level.SEVERE, null, ex);
  } finally {
    if (e != null) {
      try {
        e.flush();
        e.close();
      } catch (Exception ex) {
        //
      }
    }
  }
}

代码示例来源:origin: stackoverflow.com

NPair fe = new NPair();
fe.setNumber1(12);
fe.setNumber2(13);
FileOutputStream fos1 = new FileOutputStream("d:\\ser.xml");
java.beans.XMLEncoder xe1 = new java.beans.XMLEncoder(fos1);
xe1.writeObject(fe);
xe1.flush();
xe1.close();

代码示例来源:origin: openpreserve/pagelyzer

/**
 * permet de sauvegarder au format XML un fichier de configuration
 * @param file nom du fichier de configuration a créer
 * @throws Exception
 */
public void serializeXMLToObject(String file) throws FileNotFoundException, IOException{
  FileOutputStream os = new FileOutputStream(file);
  XMLEncoder encoder = new XMLEncoder(os);
  try{
    encoder.writeObject(this);
    encoder.flush();
  } finally{
    encoder.close();
  }
}
//Exemple d'option a lancer pour creer un fichier XML de configuration

代码示例来源:origin: stackoverflow.com

String[][][] foo = new String[3][4][5];
foo[0][0][0] = "a";
foo[2][3][4] = "z";
XMLEncoder encoder = new XMLEncoder(System.out);
encoder.writeObject(foo);
encoder.flush();
encoder.close();

代码示例来源:origin: io.ultreia.java4all.jaxx/jaxx-widgets-extra

public static Component makeDeepCopy(Component clone) {
  XMLEncoder e = null;
  XMLDecoder d = null;
  try {
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    e = new XMLEncoder(byteOut);
    e.writeObject(clone);
    e.flush();
    ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut
                                    .toByteArray());
    d = new XMLDecoder(byteIn);
    return (Component) d.readObject();
  } catch (Exception eee) {
    eee.printStackTrace();
    throw (eee);
  } finally {
    if (e != null) {
      e.close();
    }
    if (d != null) {
      d.close();
    }
  }
}

代码示例来源:origin: org.nuiton/nuiton-widgets

public static Component makeDeepCopy(Component clone) throws Exception {
  XMLEncoder e = null;
  XMLDecoder d = null;
  try {
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    e = new XMLEncoder(byteOut);
    e.writeObject(clone);
    e.flush();
    ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut
        .toByteArray());
    d = new XMLDecoder(byteIn);
    return (Component) d.readObject();
  } catch (Exception eee) {
    eee.printStackTrace();
    throw (eee);
  } finally {
    if (e != null) {
      e.close();
    }
    if (d != null) {
      d.close();
    }
  }
}

代码示例来源:origin: net.sourceforge.mydoggy/mydoggy-plaf

protected void saveBar(XMLWriter writer, MyDoggyToolWindowBar toolWindowBar) throws SAXException {
  AttributesImpl attributes = new AttributesImpl();
  attributes.addAttribute(null, "anchor", null, null, toolWindowBar.getAnchor().toString());
  attributes.addAttribute(null, "dividerSize", null, null, String.valueOf(toolWindowBar.getDividerSize()));
  attributes.addAttribute(null, "aggregateMode", null, null, String.valueOf(toolWindowBar.isAggregateMode()));
  writer.startElement("toolWindowBar", attributes);
  // Check for model
  if (toolWindowBar.getToolWindows().length > 0) {
    writer.startElement("layout");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(os);
    encoder.writeObject(toolWindowBar.getLayout());
    encoder.flush();
    encoder.close();
    String model = os.toString();
    writer.cdata(model.substring(model.indexOf('\n')));
    writer.endElement("layout");
  }
  writer.endElement("toolWindowBar");
}

代码示例来源:origin: jboss-switchyard/core

/**
 * {@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();
}

相关文章