001
014
015 package com.liferay.portal.kernel.util;
016
017 import com.liferay.portal.kernel.io.ProtectedObjectInputStream;
018 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream;
019 import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream;
020
021 import java.io.IOException;
022 import java.io.ObjectInputStream;
023 import java.io.ObjectOutputStream;
024
025
030 @Deprecated
031 public class SerializableUtil {
032
033 public static Object clone(Object object) {
034 return deserialize(serialize(object));
035 }
036
037 public static Object deserialize(byte[] bytes) {
038 ObjectInputStream objectInputStream = null;
039
040 try {
041 objectInputStream = new ProtectedObjectInputStream(
042 new UnsyncByteArrayInputStream(bytes));
043
044 return objectInputStream.readObject();
045 }
046 catch (ClassNotFoundException cnfe) {
047 throw new RuntimeException(cnfe);
048 }
049 catch (IOException ioe) {
050 throw new RuntimeException(ioe);
051 }
052 finally {
053 StreamUtil.cleanUp(objectInputStream);
054 }
055 }
056
057 public static Object deserialize(byte[] bytes, ClassLoader classLoader) {
058 ObjectInputStream objectInputStream = null;
059
060 try {
061 objectInputStream = new ProtectedClassLoaderObjectInputStream(
062 new UnsyncByteArrayInputStream(bytes), classLoader);
063
064 return objectInputStream.readObject();
065 }
066 catch (ClassNotFoundException cnfe) {
067 throw new RuntimeException(cnfe);
068 }
069 catch (IOException ioe) {
070 throw new RuntimeException(ioe);
071 }
072 finally {
073 StreamUtil.cleanUp(objectInputStream);
074 }
075 }
076
077 public static byte[] serialize(Object object) {
078 ObjectOutputStream objectOutputStream = null;
079
080 UnsyncByteArrayOutputStream unsyncByteArrayOutputStream =
081 new UnsyncByteArrayOutputStream();
082
083 try {
084 objectOutputStream = new ObjectOutputStream(
085 unsyncByteArrayOutputStream);
086
087 objectOutputStream.writeObject(object);
088 }
089 catch (IOException ioe) {
090 throw new RuntimeException(ioe);
091 }
092 finally {
093 StreamUtil.cleanUp(objectOutputStream);
094 }
095
096 return unsyncByteArrayOutputStream.toByteArray();
097 }
098
099 }