Base64Helper.javaPackage: org.projectforge.framework.utils
Classes: Base64Helper
Methods (2): decodeObject, encodeObject
Imports: 2 packages
package org.projectforge.framework.utils;
import org.apache.commons.codec.binary.Base64;
import java.io.*;
/*******************************************************************************************************************************************
* Helper to encode/decode serializable objects into base64 representation.
*
* @see java.io.ObjectInputStream
* @see java.io.ObjectOutputStream
* @author Wolfgang Jung (w.jung@micromata.de)
*
* TODO DESIGNBUG ueberfluessig
*/
public class Base64Helper
{
/*****************************************************************************************************************************************
* Convert a given base64 representation into an object.
*
* @param base64object a base64 encoded object
* @return the deserialized object
* @throws IOException if the base64 representation doesn't contain an object
* @throws ClassNotFoundException if the deserialized object can not resolved
*/
public static Object decodeObject(String base64object) throws IOException, ClassNotFoundException
{
ObjectInputStream ois = new ObjectInputStream(
new ByteArrayInputStream(Base64.decodeBase64(base64object.getBytes())));
Object o = ois.readObject();
ois.close();
return o;
}
/*****************************************************************************************************************************************
* encodes an object into the base64 representation
*
* @param obj a serializable object
* @return the string representation
* @throws IOException if the object is not serializable
*/
public static String encodeObject(Object obj) throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
oos.close();
return new String(Base64.encodeBase64(baos.toByteArray()));
}
}
868d6abb7 2025 -> 2026 63081666f Source file headers: 2024-> 2025. b6092df09 Copyright 2023 -> 2024 ab45d51fa Copyright 2001-2022 -> 2001-2023. 5f7ef41b8 Copyright 2021 -> 2022