List of usage examples for java.io ObjectOutputStream ObjectOutputStream
public ObjectOutputStream(OutputStream out) throws IOException
From source file:com.eviware.loadui.impl.statistics.db.util.TypeConverter.java
public static String objectToBase64(Serializable o) { try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(o);/* w w w .j ava2 s.c om*/ return new String(Base64.encodeBase64(baos.toByteArray())); } catch (IOException e) { return null; } }
From source file:net.sf.serfj.serializers.Base64Serializer.java
/** * Serialize object to an encoded base64 string. *//*from ww w. j a v a 2 s . co m*/ public String serialize(Object object) { ObjectOutputStream oos = null; ByteArrayOutputStream bos = null; try { bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(object); return new String(Base64.encodeBase64(bos.toByteArray())); } catch (IOException e) { LOGGER.error("Can't serialize data on Base 64", e); throw new IllegalArgumentException(e); } catch (Exception e) { LOGGER.error("Can't serialize data on Base 64", e); throw new IllegalArgumentException(e); } finally { try { if (bos != null) { bos.close(); } } catch (Exception e) { LOGGER.error("Can't close ObjetInputStream used for serialize data on Base 64", e); } } }
From source file:com.mnt.base.util.SerializeUtil.java
public static byte[] serialize(Object obj) { byte[] result; if (obj == null) { result = null;// w ww. j a v a2 s. c o m } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(baos); oos.writeObject(obj); } catch (IOException e) { log.error("error while open byte array output stream.", e); } finally { if (oos != null) { try { oos.close(); } catch (IOException e) { log.error("error while close byte array output stream.", e); } } } result = baos.toByteArray(); } return result; }
From source file:backtype.storm.serialization.SerializableSerializer.java
@Override public void write(Kryo kryo, Output output, Object object) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try {/*from w w w .j av a 2s.c o m*/ ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(object); oos.flush(); } catch (IOException e) { throw new RuntimeException(e); } byte[] ser = bos.toByteArray(); output.writeInt(ser.length); output.writeBytes(ser); }
From source file:de.kbs.acavis.service.SerializationHelper.java
public static String serializeAuthorIdentifier(AuthorIdentifier identifier) throws IOException { ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo); so.writeObject(identifier);//from ww w . j a va 2 s .c om so.flush(); String serialization = bo.toString(); so.close(); bo.close(); return serialization; }
From source file:fr.inria.atlanmod.neoemf.data.hbase.util.HBaseEncoderUtil.java
public static byte[] toBytes(String[] strings) { try {//from w w w. j ava 2 s . c om ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(strings); objectOutputStream.flush(); objectOutputStream.close(); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { NeoLogger.error("Unable to convert ''{0}'' to byte[]", Arrays.toString(strings)); } return null; }
From source file:org.terracotta.management.cli.rest.HttpServices.java
private static void save(String filename, Object o) throws IOException { File path = new File(System.getProperty("user.home"), ".tc/mgmt"); File file = new File(path, filename); ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(file)); try {/*w w w .j a v a 2 s . c om*/ objectOutputStream.writeObject(o); } finally { objectOutputStream.close(); } }
From source file:net.mindengine.oculus.frontend.web.Auth.java
public static String encodeUser(User user) throws Exception { if (user == null) { throw new IllegalArgumentException("User should not be null"); }/*from w ww.j ava2 s. c o m*/ if (secrectAuthKey == null) { throw new IllegalArgumentException("Couldn't generate secret key"); } Cipher cipher = Cipher.getInstance("DES"); cipher.init(Cipher.ENCRYPT_MODE, secrectAuthKey); SealedObject sealedUser = new SealedObject(user, cipher); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(sealedUser); oos.close(); return new String(Base64.encodeBase64(baos.toByteArray())); }
From source file:com.thoughtworks.go.util.ObjectUtil.java
public static byte[] serialize(Object o) { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); try {/*from w ww .j a v a2s. com*/ new ObjectOutputStream(buffer).writeObject(o); } catch (IOException e) { throw ExceptionUtils.bomb(e); } return buffer.toByteArray(); }
From source file:com.taobao.metamorphosis.utils.codec.impl.JavaSerializer.java
/** * @see com.taobao.notify.codec.Serializer#encodeObject(Object) *///from ww w .ja v a 2 s.c o m @Override public byte[] encodeObject(final Object objContent) throws IOException { ByteArrayOutputStream baos = null; ObjectOutputStream output = null; try { baos = new ByteArrayOutputStream(1024); output = new ObjectOutputStream(baos); output.writeObject(objContent); } catch (final IOException ex) { throw ex; } finally { if (output != null) { try { output.close(); if (baos != null) { baos.close(); } } catch (final IOException ex) { this.logger.error("Failed to close stream.", ex); } } } return baos != null ? baos.toByteArray() : null; }