List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:org.glom.web.server.Utils.java
static public Object deepCopy(final Object oldObj) { ObjectOutputStream oos = null; ObjectInputStream ois = null; try {/*from w ww.ja v a 2 s . co m*/ final ByteArrayOutputStream bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); // serialize and pass the object oos.writeObject(oldObj); oos.flush(); final ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray()); ois = new ObjectInputStream(bin); // return the new object return ois.readObject(); } catch (final Exception e) { System.out.println("Exception in deepCopy:" + e); return null; } finally { try { oos.close(); ois.close(); } catch (final IOException e) { System.out.println("Exception in deepCopy during finally: " + e); return null; } } }
From source file:me.StevenLawson.TotalFreedomMod.TFM_Util.java
public static void setSavedFlag(String flag, boolean value) { Map<String, Boolean> flags = TFM_Util.getSavedFlags(); if (flags == null) { flags = new HashMap<String, Boolean>(); }//w w w . j a v a 2 s. c o m flags.put(flag, value); try { final FileOutputStream fos = new FileOutputStream( new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.SAVED_FLAGS_FILENAME)); final ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(flags); oos.close(); fos.close(); } catch (Exception ex) { TFM_Log.severe(ex); } }
From source file:com.wabacus.util.DesEncryptTools.java
public static boolean createEncryptKey(File file) { SecretKey deskey = null;// ww w .j a v a2 s. com try { KeyGenerator keygen = KeyGenerator.getInstance("DESede"); deskey = keygen.generateKey(); } catch (NoSuchAlgorithmException e) { throw new WabacusConfigLoadingException("?", e); } if (deskey == null) return false; FileOutputStream fos = null; ObjectOutputStream oos = null; try { fos = new FileOutputStream(file); oos = new ObjectOutputStream(fos); oos.writeObject(deskey); } catch (FileNotFoundException e) { throw new WabacusConfigLoadingException( "?" + file.getPath(), e); } catch (IOException e) { throw new WabacusConfigLoadingException( "?" + file.getPath() + "", e); } finally { try { if (fos != null) fos.close(); } catch (IOException e) { e.printStackTrace(); return false; } try { if (oos != null) oos.close(); } catch (IOException e) { e.printStackTrace(); return false; } } return true; }
From source file:finale.year.stage.utility.Util.java
public static void emptyFile() { //Empty the File after User Has Logged Out //userFile.delete(); String response = null;/*from w ww .j a v a2 s . c o m*/ ObjectOutputStream writer = null; userFile = new File("config.txt"); //Write to File try { writer = new ObjectOutputStream(new FileOutputStream(userFile)); writer.writeObject(""); //Write Empty to File writer.writeObject(""); //Write Empty to File } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } finally { if (writer != null) { try { writer.close(); //Close the Reader } catch (IOException ex) { ex.printStackTrace(); return; } } } //End of If Block }
From source file:com.asquareb.kaaval.MachineKey.java
/** * Method to encrypt a string. Accepts the string to be encrypted and the * name of the file to store the key vale which can be used for decryption *///w w w. j a v a 2 s .com public static String encrypt(String property, String app) throws IOException, KaavalException { InetAddress ip = null; String ipAddress = null; ObjectOutputStream os = null; NetworkInterface macAddress = null; byte[] macId = null; Cipher pbeCipher = null; Random rand = new Random(); rand.nextBytes(salt); try { SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES"); SecretKey key = keyFactory.generateSecret(new PBEKeySpec(password)); ip = InetAddress.getLocalHost(); ipAddress = ip.getHostAddress(); macAddress = NetworkInterface.getByInetAddress(ip); macId = macAddress.getHardwareAddress(); MachineKey mKey = new MachineKey(); mKey.api = ipAddress; mKey.macad = new String(macId); mKey.yek = key; mKey.tlas = salt; mKey.eti = rand.nextInt(1000); os = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(app))); os.writeObject(mKey); os.close(); pbeCipher = Cipher.getInstance("PBEWithMD5AndDES"); pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(salt, mKey.eti)); return base64Encode(pbeCipher.doFinal(property.getBytes())); } catch (IOException e) { throw new KaavalException(1, "Error in key file during encryption", e); } catch (Exception e) { throw new KaavalException(2, "Errors during encryption", e); } finally { if (os != null) os.close(); } }
From source file:com.github.tell.codec.Base64Serializer.java
public byte[] encode(final Serializable o) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final Base64OutputStream b64os = new Base64OutputStream(baos, true); final ObjectOutputStream oos = new ObjectOutputStream(b64os); oos.writeObject(o);//from www.j av a 2 s . c o m oos.close(); return baos.toByteArray(); }
From source file:com.github.tell.codec.Base64Serializer.java
public String encodeToString(final Serializable o) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o);/*from w ww. ja v a 2 s . c o m*/ oos.close(); final byte[] encoded = baos.toByteArray(); final Base64 encoder = new Base64(); return encoder.encodeToString(encoded); }
From source file:SerialCloneTest.java
public Object clone() { try {//w w w . j a va 2 s.c o m // save the object to a byte array ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bout); out.writeObject(this); out.close(); // read a clone of the object from the byte array ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); ObjectInputStream in = new ObjectInputStream(bin); Object ret = in.readObject(); in.close(); return ret; } catch (Exception e) { return null; } }
From source file:com.pcms.common.Common.java
public <T extends Serializable> T clone(T obj) { T clonedObj = null;//from w w w. j av a 2 s . c om try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(stream); out.writeObject(obj); out.close(); ByteArrayInputStream bais = new ByteArrayInputStream(stream.toByteArray()); ObjectInputStream os = new ObjectInputStream(bais); clonedObj = (T) os.readObject(); stream.close(); } catch (IOException e) { _log.error(e.getMessage()); } catch (ClassNotFoundException e) { _log.error(e.getMessage()); } return clonedObj; }
From source file:de.dfki.asr.compass.model.AbstractCompassEntity.java
public AbstractCompassEntity deepCopy() throws IOException, ClassNotFoundException { AbstractCompassEntity entity = null; forceEagerFetch();//from w ww . jav a 2s . c o m // Write the object out to a byte array ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(this); out.flush(); out.close(); // Make an input stream from the byte array and read // a copy of the object back in. ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())); entity = (AbstractCompassEntity) in.readObject(); entity.clearIdsAfterDeepCopy(); return entity; }