Java XML Data Type Converter toString(Serializable o)

Here you can find the source of toString(Serializable o)

Description

Converts the specified object into a base64 encoded string.

License

Open Source License

Parameter

Parameter Description
o The object to convert

Return

The object as a base64 encoded string.

Declaration

public static String toString(Serializable o) 

Method Source Code

//package com.java2s;
/*/*w w w  .jav a 2  s .  com*/
 * Copyright (C) 2012 Klaus Reimer <k@ailis.de>
 * See LICENSE.TXT for licensing information.
 */

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.io.ObjectOutputStream;
import java.io.Serializable;
import javax.xml.bind.DatatypeConverter;

public class Main {
    /**
     * Converts the specified object into a base64 encoded string.
     * 
     * @param o
     *            The object to convert
     * @return The object as a base64 encoded string.
     */
    public static String toString(Serializable o) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        try {
            ObjectOutputStream objectStream = new ObjectOutputStream(stream);
            objectStream.writeObject(o);
            objectStream.close();
            return DatatypeConverter.printBase64Binary(stream.toByteArray());
        } catch (IOException e) {
            // Can't happen
            throw new RuntimeException(e.toString(), e);
        }
    }
}

Related

  1. toBinaryKeyId(String keyId)
  2. toPlaintext(String encryptedText, String password)
  3. toRoboCommand(int command)
  4. toString(byte[] edid)
  5. toString(final Serializable o)
  6. toTime(String st)
  7. unserializeURLSafe(String string)
  8. writeKey(Writer writer, PublicKey publicKey)
  9. writeOpaqueValue(final String opaque)