List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:com.topekalabs.bigmachine.lib.app.ContinuationSerializationTest.java
@Test public void simpleSerializationTest() throws Exception { MutableInt context = new MutableInt(); Continuation c = Continuation.startWith(new SimpleContinuationRunnable(), context); logger.debug("Is serializable: {}", c.isSerializable()); Assert.assertEquals("The value of the context was not set properly", SimpleContinuationRunnable.FIRST_VALUE, context.getValue());//from www . jav a2s. c om ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(c); oos.close(); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray())); c = (Continuation) ois.readObject(); ois.close(); Continuation.continueWith(c, context); Assert.assertEquals("The value of the context was not set properly", SimpleContinuationRunnable.SECOND_VALUE, context.getValue()); }
From source file:gumga.framework.application.GumgaTempFileService.java
public String create(GumgaFile gumgaFile) { String tempFileName = "uploadData" + (System.currentTimeMillis() * 1000 + new Random().nextInt(1000)); try { //TODO Arrumar o tratamento da Exception File folder = new File(gumgaValues.getUploadTempDir()); folder.mkdirs();// www. jav a 2s . c om FileOutputStream fos = new FileOutputStream(gumgaValues.getUploadTempDir() + "/" + tempFileName); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(gumgaFile); oos.close(); fos.close(); return tempFileName; } catch (Exception ex) { log.error("erro ao criar arquivo temporario " + tempFileName, ex); } return "error"; }
From source file:MSUmpire.SpectrumParser.DIA_Setting.java
public void WriteDIASettingSerialization(String mzXMLFileName) { try {/*w ww .ja va 2 s . c o m*/ Logger.getRootLogger().info("Writing DIA setting to file:" + FilenameUtils.getFullPath(mzXMLFileName) + FilenameUtils.getBaseName(mzXMLFileName) + "_diasetting.ser..."); FileOutputStream fout = new FileOutputStream(FilenameUtils.getFullPath(mzXMLFileName) + FilenameUtils.getBaseName(mzXMLFileName) + "_diasetting.ser", false); ObjectOutputStream oos = new ObjectOutputStream(fout); oos.writeObject(this); oos.close(); fout.close(); } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); } }
From source file:com.btoddb.trellis.common.serialization.JavaSerializer.java
private void serializeToOutputStream(Serializable obj, OutputStream os) { try {/*from ww w . j a v a 2s. c om*/ ObjectOutputStream oos = new ObjectOutputStream(os); oos.writeObject(obj); oos.close(); } catch (IOException e) { throw new TrellisException("exception while serializing Java Serializable object", e); } }
From source file:bancvirt.Recurso.java
public Boolean commit(Long tId) { FileOutputStream fout = null; try {/* w w w .j av a 2 s .co m*/ fout = new FileOutputStream(getResourceId()); ObjectOutputStream oos = new ObjectOutputStream(fout); oos.writeObject(this); oos.close(); fout.close(); return true; } catch (FileNotFoundException ex) { ex.printStackTrace(); return false; } catch (IOException ex) { ex.printStackTrace(); return false; } finally { try { fout.close(); } catch (IOException ex) { ex.printStackTrace(); return false; } } }
From source file:de.tudarmstadt.ukp.dkpro.tc.weka.util.WekaUtils.java
/** * Writes a file with all necessary information for evaluation. * * @param result the result file//ww w . j a v a 2 s. c o m * @param file the file to write to * @throws IOException i/o error * @throws FileNotFoundException file not found */ public static void writeMlResultToFile(MultilabelResult result, File file) throws FileNotFoundException, IOException { //file.mkdirs(); //file.createNewFile(); ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(file)); stream.writeObject(result); stream.close(); }
From source file:io.gumga.application.GumgaTempFileService.java
/** * Criar um arquivo temporario/*from w ww.ja va2 s . c om*/ * @param gumgaFile * @return dados do arquivo */ public String create(GumgaFile gumgaFile) { String tempFileName = "uploadData" + (System.currentTimeMillis() * 1000 + new Random().nextInt(1000)); try { //TODO Arrumar o tratamento da Exception File folder = new File(gumgaValues.getUploadTempDir()); folder.mkdirs(); FileOutputStream fos = new FileOutputStream(gumgaValues.getUploadTempDir() + "/" + tempFileName); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(gumgaFile); oos.close(); fos.close(); return tempFileName; } catch (Exception ex) { log.error("erro ao criar arquivo temporario " + tempFileName, ex); } return "error"; }
From source file:com.earldouglas.xjdl.io.LicenseCreator.java
public String encryptLicense(License license, String key) throws Exception, NoSuchAlgorithmException, NoSuchPaddingException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(license); objectOutputStream.close(); byte[] serializedLicense = byteArrayOutputStream.toByteArray(); SecretKeySpec secretKeySpec = new SecretKeySpec(key.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec); byte[] encryptedLicense = cipher.doFinal(serializedLicense); String encodedLicense = Base64.encodeBase64String(encryptedLicense); encodedLicense = encodedLicense.replaceAll("\n", ""); encodedLicense = encodedLicense.replaceAll("\r", ""); return encodedLicense; }
From source file:gnomezgrave.gsyncj.auth.ProfileSettings.java
public void saveSettings() throws IOException, ClassNotFoundException { ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(filePath)); oo.writeObject(this); oo.close(); }
From source file:com.googlecode.jeeunit.example.test.spring.AuthorTest.java
/** * Test case for Glassfish <a/*from www. j ava 2 s. co m*/ * href="https://glassfish.dev.java.net/issues/show_bug.cgi?id=12599">bug #12599</a>. * * @throws IOException * @throws ClassNotFoundException */ @Test @Ignore public void serialization() throws IOException, ClassNotFoundException { long expectedNumBooks = libraryService.getNumBooks(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(libraryService); oos.close(); byte[] bytes = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bais); Object obj = ois.readObject(); assertTrue(obj instanceof LibraryService); // the deserialized proxy throws a NullPointerException on method invocation long numBooks = ((LibraryService) obj).getNumBooks(); assertEquals(expectedNumBooks, numBooks); }