List of usage examples for java.io ObjectOutputStream writeObject
public final void writeObject(Object obj) throws IOException
From source file:de.tudarmstadt.ukp.dkpro.argumentation.sequence.feature.meta.AbstractSequenceMetaDataFeatureGenerator.java
public static String encodeToString(Object object) throws TextClassificationException { try {/* ww w .j a v a2 s . co m*/ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(object); byteArrayOutputStream.close(); return Base64.encodeBase64String(byteArrayOutputStream.toByteArray()); } catch (IOException e) { throw new TextClassificationException(e); } }
From source file:gnomezgrave.gsyncj.auth.Profile.java
public static void saveSettings(Profile profile, String fileName) throws IOException, ClassNotFoundException { ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(fileName)); oo.writeObject(profile); oo.close();/*from ww w.j av a2s .co m*/ }
From source file:io.smartspaces.scheduling.quartz.orientdb.internal.util.SerialUtils.java
private static byte[] stringMapToBytes(Object object) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(object); out.flush();/*from ww w . j a v a 2 s .co m*/ return baos.toByteArray(); }
From source file:com.bworld.manager.ObjectSerializer.java
/** * Serialize.// w w w . j av a 2 s . c o m * * @param obj the obj * @return the string */ public static String serialize(Serializable obj) { if (obj == null) return ""; try { ByteArrayOutputStream serialObj = new ByteArrayOutputStream(); ObjectOutputStream objStream = new ObjectOutputStream(serialObj); objStream.writeObject(obj); objStream.close(); return encodeBytes(serialObj.toByteArray()); } catch (Exception e) { // throw WrappedIOException.wrap("Serialization error: " + e.getMessage(), e); } return null; }
From source file:com.weibo.api.motan.protocol.restful.support.RestfulUtil.java
public static Response serializeError(Exception ex) { try {//from w ww . jav a 2s .co m ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(ex); oos.flush(); String info = new String(Base64.encodeBytesToBytes(baos.toByteArray()), MotanConstants.DEFAULT_CHARACTER); return Response.status(Status.EXPECTATION_FAILED).header(EXCEPTION_HEADER, ex.getClass()).entity(info) .build(); } catch (IOException e) { LoggerUtil.error("serialize " + ex.getClass() + " error", e); return Response.status(Status.INTERNAL_SERVER_ERROR).entity("serialization " + ex.getClass() + " error") .build(); } }
From source file:Main.java
public static byte[] objectToByte(Object obj) throws Exception { ObjectOutputStream oos = null; try {/*w w w .j a v a 2s . co m*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(obj); return bos.toByteArray(); } finally { if (oos != null) oos.close(); } }
From source file:Util.java
/** * Writes a serialized version of obj to a given file, compressing it using gzip. * @param f File to write to/*from ww w . j a va 2s.c o m*/ * @param obj Object to serialize */ public static void writeGzippedObject(File f, Serializable obj) { try { ObjectOutputStream oos = new ObjectOutputStream( new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(f)))); oos.writeObject(obj); oos.close(); } catch (IOException e) { System.err.println("Exception writing file " + f + ": " + e); } }
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 ava 2 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:jp.queuelinker.system.util.SerializeUtil.java
/** * Serializes an object to a byte array. * @param obj//from w ww.j av a 2s . co m * @return */ public static byte[] serializeToBytes(final Object obj) { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); try { ObjectOutputStream objStream = new ObjectOutputStream(byteStream); objStream.writeObject(obj); objStream.close(); } catch (IOException e) { logger.error("Serialization Error. The class " + obj.getClass().getName() + " may not implement Serializable interface"); } return byteStream.toByteArray(); }
From source file:jp.queuelinker.system.util.SerializeUtil.java
/** * @param obj/*ww w. j ava2 s . co m*/ * @param file * @throws IOException */ public static void storeObject(final Object obj, final File file) throws IOException { ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream(file)); output.writeObject(obj); }