List of usage examples for java.io ObjectOutputStream close
public void close() throws IOException
From source file:com.datatorrent.stram.FSRecoveryHandler.java
@Override public void save(Object state) throws IOException { if (fs.exists(snapshotBackupPath)) { throw new IllegalStateException("Found previous backup " + snapshotBackupPath); }/*from ww w . j av a 2 s . co m*/ if (fs.exists(snapshotPath)) { LOG.debug("Backup {} to {}", snapshotPath, snapshotBackupPath); fs.rename(snapshotPath, snapshotBackupPath); } LOG.debug("Writing checkpoint to {}", snapshotPath); final FSDataOutputStream fsOutputStream = fs.create(snapshotPath); try { ObjectOutputStream oos = new ObjectOutputStream(fsOutputStream); try { oos.writeObject(state); } finally { oos.close(); } } finally { fsOutputStream.close(); } // remove snapshot backup if (fs.exists(snapshotBackupPath) && !fs.delete(snapshotBackupPath, false)) { throw new IOException("Failed to remove " + snapshotBackupPath); } // remove log backup Path logBackup = new Path(basedir + Path.SEPARATOR + FILE_LOG_BACKUP); if (fs.exists(logBackup) && !fs.delete(logBackup, false)) { throw new IOException("Failed to remove " + logBackup); } }
From source file:net.nicholaswilliams.java.licensing.TestObjectSerializer.java
@Test public void testReadObject2() throws Exception { MockTestObject1 object = new MockTestObject1(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(bytes); stream.writeObject(object);//from w w w . j a va 2 s. com stream.close(); byte[] data = bytes.toByteArray(); MockTestObject1 returned = this.serializer.readObject(MockTestObject1.class, data); assertNotNull("The returned object should not be null.", returned); assertFalse("The returned object should not be the same.", returned == object); assertEquals("The returned object should be equal.", object, returned); }
From source file:net.nicholaswilliams.java.licensing.TestObjectSerializer.java
@Test public void testReadObject5() throws Exception { MockTestObject2 object = new MockTestObject2(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(bytes); stream.writeObject(object);//from ww w. ja va 2 s. c o m stream.close(); byte[] data = bytes.toByteArray(); MockTestObject2 returned = this.serializer.readObject(MockTestObject2.class, data); assertNotNull("The returned object should not be null.", returned); assertFalse("The returned object should not be the same.", returned == object); assertEquals("The returned object should be equal.", object, returned); }
From source file:net.nicholaswilliams.java.licensing.TestObjectSerializer.java
@Test public void testReadObject3() throws Exception { MockTestObject1 object = new MockTestObject1(); object.coolTest = true;//from ww w . java2s . com Arrays.fill(object.myArray, (byte) 12); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(bytes); stream.writeObject(object); stream.close(); byte[] data = bytes.toByteArray(); MockTestObject1 returned = this.serializer.readObject(MockTestObject1.class, data); assertNotNull("The returned object should not be null.", returned); assertFalse("The returned object should not be the same.", returned == object); assertEquals("The returned object should be equal.", object, returned); }
From source file:net.nicholaswilliams.java.licensing.TestObjectSerializer.java
@Test public void testReadObject6() throws Exception { MockTestObject2 object = new MockTestObject2(); object.aString = "another test string"; Arrays.fill(object.password, 'b'); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(bytes); stream.writeObject(object);/*from w ww. java2s. c o m*/ stream.close(); byte[] data = bytes.toByteArray(); MockTestObject2 returned = this.serializer.readObject(MockTestObject2.class, data); assertNotNull("The returned object should not be null.", returned); assertFalse("The returned object should not be the same.", returned == object); assertEquals("The returned object should be equal.", object, returned); }
From source file:eu.annocultor.reports.parts.ReportCounter.java
@Override public void flush() throws IOException { XStream xStream = new XStream(); OutputStream fos = new FileOutputStream(getFile(), true); ObjectOutputStream out = xStream.createObjectOutputStream(fos); try {//from www .ja v a 2s . c o m for (ObjectCountPair<T> pair : asSorted()) { // xStream.toXML(pair, out); out.writeObject(pair); } empty(); } finally { out.close(); fos.close(); } }
From source file:de.elatePortal.autotool.SubTasklet_AutotoolImpl.java
private byte[] serialize(Object obj) { try {/*from w w w. jav a 2s . c o m*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(obj); oos.close(); byte[] arr = bos.toByteArray(); bos.close(); return arr; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:org.n52.geoar.newdata.PluginLoader.java
/** * Saves the state of plugins to {@link SharedPreferences}. *///from w ww . j ava 2 s. c om public static void saveState() { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream); // store plugin state version objectOutputStream.writeInt(PLUGIN_STATE_VERSION); List<InstalledPluginHolder> checkedPlugins = mInstalledPlugins.getCheckedItems(); objectOutputStream.writeInt(checkedPlugins.size()); for (InstalledPluginHolder plugin : checkedPlugins) { objectOutputStream.writeUTF(plugin.getIdentifier()); plugin.saveState(objectOutputStream); } SharedPreferences preferences = GeoARApplication.applicationContext .getSharedPreferences(GeoARApplication.PREFERENCES_FILE, Context.MODE_PRIVATE); Editor editor = preferences.edit(); objectOutputStream.flush(); editor.putString(PLUGIN_STATE_PREF, Base64.encodeToString(outputStream.toByteArray(), Base64.DEFAULT)); editor.commit(); objectOutputStream.close(); } catch (IOException e) { e.printStackTrace(); // TODO } }
From source file:fi.aalto.seqpig.filter.CoordinateFilter.java
public CoordinateFilter(String samfileheaderfilename, String regions_str) { String str = ""; this.samfileheader = ""; this.regions_str = regions_str; try {//from w ww . j a v a2s.c o m Configuration conf = UDFContext.getUDFContext().getJobConf(); if (conf == null) { decodeSAMFileHeader(); return; } FileSystem fs; try { if (FileSystem.getDefaultUri(conf) == null || FileSystem.getDefaultUri(conf).toString() == "") fs = FileSystem.get(new URI("hdfs://"), conf); else fs = FileSystem.get(conf); } catch (Exception e) { fs = FileSystem.get(new URI("hdfs://"), conf); System.out.println("WARNING: problems with filesystem config?"); System.out.println("exception was: " + e.toString()); } BufferedReader in = new BufferedReader(new InputStreamReader( fs.open(new Path(fs.getHomeDirectory(), 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); p.setProperty("regionsstr", regions_str); } catch (Exception e) { System.out.println("ERROR: Unable to store SAMFileHeader in CoordinateFilter!"); } this.samfileheader_decoded = getSAMFileHeader(); populateRegions(); }
From source file:com.fuzhepan.arpc.client.ProxyHandler.java
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { log.debug("invoke was called!"); if (method.getName().equals("toString")) { return "toString method was called"; }// w w w . j a v a2s . c o m RpcContext rpcContext = new RpcContext(interfaceName, method.getName(), method.getParameterTypes(), args); //get service info and load balance List<HostPortPair> serviceList = RpcConfig.getServiceList(serviceName); if (serviceList == null || serviceList.size() == 0) throw new ClassNotFoundException("not find service : " + serviceName); int index = requestCount.get() % serviceList.size(); if (requestCount.get() > 100) requestCount.set(0); else requestCount.getAndIncrement(); HostPortPair hostPort = serviceList.get(index); Socket socket = new Socket(hostPort.host, hostPort.port); ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream()); objectOutputStream.writeObject(rpcContext); objectOutputStream.flush(); ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream()); Object response = objectInputStream.readObject(); objectInputStream.close(); objectOutputStream.close(); socket.close(); Class methodReturnType = method.getReturnType(); return methodReturnType.cast(response); }