List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:com.ibm.sbt.test.lib.MockSerializer.java
private String serialize(Object o) throws IOException { if (o instanceof EofSensorInputStream) return serialize((EofSensorInputStream) o); if (o instanceof Node) return serialize((Node) o); if (o instanceof Header[]) return serialize((Header[]) o); ByteArrayOutputStream w = new ByteArrayOutputStream(); Base64OutputStream base64OutputStream = new Base64OutputStream(w); ObjectOutputStream os = new ObjectOutputStream(base64OutputStream); os.writeObject(o);/*from www. jav a 2s. co m*/ os.flush(); os.close(); base64OutputStream.flush(); base64OutputStream.close(); return w.toString("UTF-8"); }
From source file:com.linkedin.pinot.query.aggregation.DistinctCountHLLTest.java
private int getSerializedSize(Serializable ser) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; try {// w ww . j a va 2s .c o m oos = new ObjectOutputStream(baos); oos.writeObject(ser); oos.close(); return baos.size(); } catch (IOException e) { e.printStackTrace(); } return -1; }
From source file:cn.guoyukun.spring.jpa.repository.hibernate.type.ObjectSerializeUserType.java
/** * Hibernate??//ww w . j av a 2 s .c o m * ?PreparedStateme?? */ @Override public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { ObjectOutputStream oos = null; if (value == null) { st.setNull(index, Types.VARCHAR); } else { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(value); oos.close(); byte[] objectBytes = bos.toByteArray(); String hexStr = Hex.encodeHexString(objectBytes); st.setString(index, hexStr); } catch (Exception e) { throw new HibernateException(e); } finally { try { oos.close(); } catch (IOException e) { } } } }
From source file:com.fratello.longevity.smooth.catalog.CompareFilter.java
public void saveObject() { try {// w ww. j ava 2 s .c o m ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream( new File(new File(FileUtils.getTempDirectoryPath() + "NicksProgram"), "defaultsettings.ser"))); out.writeObject(this); out.close(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); out = new ObjectOutputStream(bos); out.writeObject(this); out.close(); } catch (IOException e) { } }
From source file:com.googlecode.fightinglayoutbugs.ScreenshotCache.java
private File saveToTempFile(Screenshot screenshot) { try {/*from ww w. j a v a 2 s . c om*/ File tempFile = File.createTempFile("flb-cached-screenshot-", ".ser"); tempFile.deleteOnExit(); FileOutputStream fileOutputStream = new FileOutputStream(tempFile); try { ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); try { objectOutputStream.writeObject(screenshot); } finally { try { objectOutputStream.close(); } catch (Throwable ignored) { } } } finally { try { fileOutputStream.close(); } catch (Throwable ignored) { } } return tempFile; } catch (IOException e) { throw new RuntimeException("Failed to save screenshot to temporary file.", e); } }
From source file:com.abelsky.idea.geekandpoke.entries.impl.OfflineCacheImpl.java
private void cache(@NotNull Entry entry) { if (!isEnabled()) { return;/*from ww w . ja va2 s . c o m*/ } synchronized (entry.getEntryInfo()) { if (getCached(entry.getEntryInfo()) != null) { physicallyDelete(entry); } @NotNull final File entryFile = entryFile(entry); FileUtil.createIfDoesntExist(entryFile); try { @NotNull final ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(entryFile)); try { out.writeObject(entry); } finally { out.close(); } } catch (IOException e) { if (log.isDebugEnabled()) { log.warn(e); } // Ensure there's no incomplete entry. physicallyDelete(entry); } } }
From source file:fi.aalto.seqpig.io.BamStorer.java
public BamStorer(String samfileheaderfilename) { String str = ""; this.samfileheader = ""; try {/*from www. j a v a2s. c o m*/ Configuration conf = UDFContext.getUDFContext().getJobConf(); // see https://issues.apache.org/jira/browse/PIG-2576 if (conf == null || conf.get("mapred.task.id") == null) { // we are running on the frontend decodeSAMFileHeader(); return; } URI uri = new URI(samfileheaderfilename); FileSystem fs = FileSystem.get(uri, conf); BufferedReader in = new BufferedReader(new InputStreamReader(fs.open(new Path(samfileheaderfilename)))); while (true) { str = in.readLine(); if (str == null) break; else this.samfileheader += str + "\n"; } in.close(); } catch (Exception e) { System.out.println("ERROR: could not read BAM header from file " + samfileheaderfilename); System.out.println("exception was: " + e.toString()); } try { Base64 codec = new Base64(); Properties p = UDFContext.getUDFContext().getUDFProperties(this.getClass()); ByteArrayOutputStream bstream = new ByteArrayOutputStream(); ObjectOutputStream ostream = new ObjectOutputStream(bstream); ostream.writeObject(this.samfileheader); ostream.close(); String datastr = codec.encodeBase64String(bstream.toByteArray()); p.setProperty("samfileheader", datastr); } catch (Exception e) { System.out.println("ERROR: Unable to store SAMFileHeader in BamStorer!"); } this.samfileheader_decoded = getSAMFileHeader(); }
From source file:com.inmobi.grill.server.GrillServices.java
private void persistGrillServiceState() throws IOException { if (conf.getBoolean(GrillConfConstants.GRILL_SERVER_RESTART_ENABLED, GrillConfConstants.DEFAULT_GRILL_SERVER_RESTART_ENABLED)) { FileSystem fs = persistDir.getFileSystem(conf); LOG.info("Persisting server state in " + persistDir); for (GrillService service : grillServices) { LOG.info("Persisting state of service:" + service.getName()); Path serviceWritePath = new Path(persistDir, service.getName() + ".out"); ObjectOutputStream out = null; try { out = new ObjectOutputStream(fs.create(serviceWritePath)); service.writeExternal(out); } finally { if (out != null) { out.close(); }//from w w w . j ava 2 s.c o m } Path servicePath = getServicePersistPath(service); fs.rename(serviceWritePath, servicePath); LOG.info("Persisted service " + service.getName() + " to " + servicePath); } } else { LOG.info("Server restart is not enabled. Not persisting the server state"); } }