Codota Logo
XMLEncoder
Code IndexAdd Codota to your IDE (free)

How to use
XMLEncoder
in
java.beans

Best Java code snippets using java.beans.XMLEncoder (Showing top 20 results out of 909)

Refine searchRefine arrow

  • FileOutputStream
  • BufferedOutputStream
  • XMLDecoder
  • ByteArrayOutputStream
  • Common ways to obtain XMLEncoder
private void myMethod () {
XMLEncoder x =
  • Codota IconOutputStream out;new XMLEncoder(out)
  • Codota IconFile file;new XMLEncoder(new BufferedOutputStream(new FileOutputStream(file)))
  • Codota IconOutputStream out;new XMLEncoder(new BufferedOutputStream(out))
  • Smart code suggestions by Codota
}
origin: oracle/opengrok

ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLEncoder enc = new XMLEncoder(out);
enc.setExceptionListener(listener);
Project p1 = new Project("foo");
enc.writeObject(p1);
enc.close();
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
XMLDecoder dec = new XMLDecoder(in, null, listener);
Project p2 = (Project) dec.readObject();
assertNotNull(p2);
dec.close();
origin: oracle/opengrok

try {
  output = File.createTempFile("oghist", null, dir);
  try (FileOutputStream out = new FileOutputStream(output);
    XMLEncoder e = new XMLEncoder(new GZIPOutputStream(
      new BufferedOutputStream(out)))) {
    e.setPersistenceDelegate(File.class,
        new FilePersistenceDelegate());
    e.writeObject(history);
origin: oracle/opengrok

public void encodeObject(OutputStream out) {
  try (XMLEncoder e = new XMLEncoder(new BufferedOutputStream(out))) {
    e.writeObject(this);
  }
}
origin: apache/shiro

/**
 * Serializes the specified <code>source</code> into a byte[] array by using the
 * {@link java.beans.XMLEncoder XMLEncoder} to encode the object out to a
 * {@link java.io.ByteArrayOutputStream ByteArrayOutputStream}, where the resulting byte[] array is returned.
 * @param source the Object to convert into a byte[] array.
 * @return the byte[] array representation of the XML encoded output.
 */
public byte[] serialize(Object source) {
  if (source == null) {
    String msg = "argument cannot be null.";
    throw new IllegalArgumentException(msg);
  }
  ByteArrayOutputStream bos = new ByteArrayOutputStream();
  XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(bos));
  encoder.writeObject(source);
  encoder.close();
  return bos.toByteArray();
}
origin: looly/hutool

/**
 * 将可序列化的对象转换为XML写入文件,已经存在的文件将被覆盖<br>
 * Writes serializable object to a XML file. Existing file will be overwritten
 * 
 * @param dest 目标文件
 * @param bean 对象
 * @throws IOException IO异常
 */
public static void writeObjectAsXml(File dest, Object bean) throws IOException {
  XMLEncoder xmlenc = null;
  try {
    xmlenc = new XMLEncoder(FileUtil.getOutputStream(dest));
    xmlenc.writeObject(bean);
  } finally {
    // 关闭XMLEncoder会相应关闭OutputStream
    IoUtil.close(xmlenc);
  }
}
origin: net.sourceforge.jadex/jadex-platform-base

  /**
   *  Encode an object.
   *  @param obj The object.
   *  @throws IOException
   */
//    public byte[] encode(Object val, ClassLoader classloader)
  public Object encode(Object val, ClassLoader classloader)
  {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLEncoder enc = new XMLEncoder(baos);
    enc.setExceptionListener(new ExceptionListener()
    {
      public void exceptionThrown(Exception e)
      {
        System.out.println("XML encoding ERROR: ");
        e.printStackTrace();
      }
    });
    enc.writeObject(val);
    enc.close();
    try{baos.close();} catch(Exception e) {}
    return baos.toByteArray();
  }
 
origin: bobbylight/RSyntaxTextArea

File xmlFile = new File(directory, template.getID() + ".xml");
try {
  XMLEncoder e = new XMLEncoder(new BufferedOutputStream(
              new FileOutputStream(xmlFile)));
  e.writeObject(template);
  e.close();
} catch (IOException ioe) {
  ioe.printStackTrace();
origin: oracle/opengrok

/**
 * Verify that encoding of Group class does  not contain transient members.
 * @throws Exception exception
 */
@Test
public void testTransientKeywordGroups() throws Exception {
  Group foo = new Group("foo", "foo.*");
  Group bar = new Group("bar", "bar.*");
  Configuration cfg = new Configuration();
  cfg.addGroup(foo);
  foo.addGroup(bar);
  cfg.addGroup(bar);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  try (XMLEncoder enc = new XMLEncoder(out)) {
    enc.writeObject(cfg);
  }
  // In this test we are no so much interested in exceptions during the
  // XML decoding as that is covered by the {@code serializationOrderTest}
  // test.
  try (ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray())) {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = factory.newSAXParser();
    Handler handler = new Handler();
    saxParser.parse(new BufferedInputStream(in), handler);
  }
}
origin: openpnp/openpnp

public static String serialize(Object o) {
  ByteArrayOutputStream bOut = new ByteArrayOutputStream();
  XMLEncoder xmlEncoder = new XMLEncoder(bOut);
  xmlEncoder.writeObject(o);
  xmlEncoder.close();
  return bOut.toString();
}
origin: oracle/opengrok

XMLEncoder e = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(testXML)));
e.setExceptionListener(listener);
e.writeObject(in);
e.close();
XMLDecoder d = new XMLDecoder(new FileInputStream(testXML));
IgnoredNames in2 = (IgnoredNames) d.readObject();
d.close();
origin: oracle/opengrok

cfg.addGroup(opensource);
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (XMLEncoder enc = new XMLEncoder(out)) {
  enc.writeObject(cfg);
try (ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    XMLDecoder dec = new XMLDecoder(in, null, (Exception e) -> {
      exceptions.addLast(e);
    })) {
  cfg = (Configuration) dec.readObject();
  assertNotNull(cfg);
origin: stackoverflow.com

 public String serialize(Object o) {
    String s;
    ByteArrayOutputStream stream = new ByteArrayOutputStream();

    XMLEncoder encoder = new XMLEncoder( new BufferedOutputStream( stream ) );

    encoder.writeObject(o);
    encoder.close();
    s = stream.toString();
    return s;
  }

private Object deserialize(String s) {

  XMLDecoder decoder = new XMLDecoder( new ByteArrayInputStream( s.getBytes() ) );
  return decoder.readObject();
}
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: org.swinglabs/swingx-beaninfo

XMLEncoder e = new XMLEncoder(new FileOutputStream(file));
e.setOwner(new PersistenceOwner(baseURL));
e.setPersistenceDelegate(AbstractPainter.Interpolation.class, new TypeSafeEnumPersistenceDelegate());
e.setPersistenceDelegate(RectanglePainter.Style.class, new TypeSafeEnumPersistenceDelegate());
e.setPersistenceDelegate(AbstractLayoutPainter.HorizontalAlignment.class, new TypeSafeEnumPersistenceDelegate());
e.setPersistenceDelegate(AbstractLayoutPainter.VerticalAlignment.class, new TypeSafeEnumPersistenceDelegate());
e.setPersistenceDelegate(AbstractPainter.class, new AbstractPainterDelegate());
e.setPersistenceDelegate(ImagePainter.class, new ImagePainterDelegate());
e.setPersistenceDelegate(RenderingHints.class, new RenderingHintsDelegate());
e.setPersistenceDelegate(GradientPaint.class, new GradientPaintDelegate());
e.setPersistenceDelegate(Arc2D.Float.class, new Arc2DDelegate());
e.setPersistenceDelegate(Arc2D.Double.class, new Arc2DDelegate());
e.setPersistenceDelegate(CubicCurve2D.Float.class, new CubicCurve2DDelegate());
e.setPersistenceDelegate(CubicCurve2D.Double.class, new CubicCurve2DDelegate());
e.setPersistenceDelegate(Ellipse2D.Float.class, new Ellipse2DDelegate());
e.setPersistenceDelegate(Ellipse2D.Double.class, new Ellipse2DDelegate());
e.setPersistenceDelegate(Line2D.Float.class, new Line2DDelegate());
e.setPersistenceDelegate(Line2D.Double.class, new Line2DDelegate());
e.setPersistenceDelegate(Point2D.Float.class, new Point2DDelegate());
e.setPersistenceDelegate(Point2D.Double.class, new Point2DDelegate());
e.setPersistenceDelegate(QuadCurve2D.Float.class, new QuadCurve2DDelegate());
e.setPersistenceDelegate(QuadCurve2D.Double.class, new QuadCurve2DDelegate());
e.setPersistenceDelegate(Rectangle2D.Float.class, new Rectangle2DDelegate());
e.setPersistenceDelegate(Rectangle2D.Double.class, new Rectangle2DDelegate());
e.setPersistenceDelegate(RoundRectangle2D.Float.class, new RoundRectangle2DDelegate());
e.setPersistenceDelegate(RoundRectangle2D.Double.class, new RoundRectangle2DDelegate());
origin: jtrfp/terminal-recall

configurations.put(conf.getConfiguredClass(),conf.storeToMap(new HashMap<String,Object>()));
FileOutputStream os = new FileOutputStream(temp);
XMLEncoder xmlEnc   = new XMLEncoder(os);
xmlEnc.setExceptionListener(new ExceptionListener(){
@Override
public void exceptionThrown(Exception e) {
  e.printStackTrace();
}});
xmlEnc.setPersistenceDelegate(DefaultListModel.class,
  new DefaultPersistenceDelegate() {
  protected void initialize(Class clazz,
xmlEnc.writeObject(configurations);
xmlEnc.close();
  dstCh = new FileOutputStream(finalDest).getChannel();
  dstCh.transferFrom(srcCh, 0, srcCh.size());
  }catch(Exception e){e.printStackTrace();}
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();
}
origin: org.apache.hadoop.hive/hive-exec

/**
 * Serialize the mapredWork object to an output stream. DO NOT use this to write to standard
 * output since it closes the output stream. DO USE mapredWork.toXML() instead.
 */
public static void serializeMapRedWork(MapredWork w, OutputStream out) {
 XMLEncoder e = new XMLEncoder(out);
 // workaround for java 1.5
 e.setPersistenceDelegate(ExpressionTypes.class, new EnumDelegate());
 e.setPersistenceDelegate(GroupByDesc.Mode.class, new EnumDelegate());
 e.writeObject(w);
 e.close();
}
origin: stackoverflow.com

 XMLEncoder encoder = new XMLEncoder();
XMLDecoder decoder = new XMLDecoder();
origin: be.yildiz-games/common-file-xml

/**
 * Write an object into a XML file.
 *
 * @param o Object to persist.
 */
@Override
public void writeToFile(final T o) {
  try (OutputStream fos = Files.newOutputStream(this.file)) {
    try (XMLEncoder encoder = new XMLEncoder(fos)) {
      encoder.setExceptionListener(FileCreationException::new);
      encoder.writeObject(o);
    }
  } catch (IOException e) {
    throw new FileCreationException(e);
  }
}
origin: violetumleditor/violetumleditor

/**
 * Creates a new instance of XML Encoder pre-configured for Violet beans serailization
 * 
 * @param out
 * @return configured encoder
 */
private XMLEncoder getXMLEncoder(OutputStream out)
{
  XMLEncoder encoder = new XMLEncoder(out);

  encoder.setExceptionListener(new ExceptionListener()
  {
    public void exceptionThrown(Exception ex)
    {
      ex.printStackTrace();
    }
  });
  configure(encoder);
  return encoder;
}
java.beansXMLEncoder

Most used methods

  • <init>
  • writeObject
  • close
  • setExceptionListener
  • flush
  • setPersistenceDelegate
  • getOwner
  • setOwner
  • getPersistenceDelegate

Popular in Java

  • Making http requests using okhttp
  • startActivity (Activity)
  • getExternalFilesDir (Context)
  • scheduleAtFixedRate (ScheduledExecutorService)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • MessageFormat (java.text)
    MessageFormat provides a means to produce concatenated messages in language-neutral way. Use this to
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Dictionary (java.util)
    The Dictionary class is the abstract parent of any class, such as Hashtable, which maps keys to valu
  • Map (java.util)
    A Map is a data structure consisting of a set of keys and values in which each key is mapped to a si
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now