Ejemplo n.º 1
0
    def loadClick(self,e):
        returnVal = self._fc.showOpenDialog(self._splitpane)
        if returnVal == JFileChooser.APPROVE_OPTION:
            warning = """
            CAUTION: 

            Loading a saved configuration deserializes data. 
            This action may pose a security threat to the application.
            Only proceed when the source and contents of this file is trusted. 

            Load Selected File?
            """
            result = JOptionPane.showOptionDialog(self._splitpane, warning, "Caution", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, None, ["OK", "Cancel"],"OK")
            if result != JOptionPane.YES_OPTION:
                return
            f = self._fc.getSelectedFile()
            fileName = f.getPath()
            
            ins = ObjectInputStream(FileInputStream(fileName))
            dbData=ins.readObject()
            ins.close()

            self._db.load(dbData,self)
            self._userTable.redrawTable()
            self._messageTable.redrawTable()
Ejemplo 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)
Ejemplo n.º 3
0
def deserializeTree(filename):
    ''' For testing purposes, load & print a Java object parsetree. '''
    filein = FileInputStream(filename)
    oostream = ObjectInputStream(filein)
    jtree = oostream.readObject()
    oostream.close()
    f = open(filename + ".debug", 'w')
    deepstr = pprint.pformat(jtree, indent=4, width=80)
    f.write("TESTING JAVA OBJ:\n" + str(deepstr) + '\n')
    f.close()
Ejemplo n.º 4
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())
Ejemplo 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)
Ejemplo n.º 6
0
 def load_model(self, model, arff):
     try:
         j48 = J48()
         options = ('-i', '-l', model, '-T', arff)
         objectInputFileName = Utils.getOption('l', options);
         if len(objectInputFileName) == 0:
             print "No training file and no object input file given."
             raise
         inputStream = InputStream
         inputStream = FileInputStream(objectInputFileName)
         objectInputStream = ObjectInputStream(inputStream)
         j48 = objectInputStream.readObject()
         return j48
     except:
         raise
Ejemplo n.º 7
0
def deserialize(filepath):
  f = None
  o = None
  obj = None
  try:
    f = FileInputStream(filepath)
    o = ObjectInputStream(f)
    obj = o.readObject()
  except:
    syncPrintQ(sys.exc_info())
  finally:
    if f:
      f.close()
    if o:
      o.close()
  if obj is None:
    syncPrintQ("Failed to deserialize object at " + filepath)
  return obj
Ejemplo n.º 8
0
#encoding:utf-8
from java.io import FileInputStream
from java.io import ObjectInputStream

import sys

jarfiles = ["/opt/lingpipe-segmenter/lingpipe-4.0.1.jar", "/opt/lingpipe-segmenter/zhToksDemo.jar"]
for jar in jarfiles:
    if jar not in sys.path:
        sys.path.append(jar)
modelfile="/opt/lingpipe-segmenter/mxf_segmenter"
fin = FileInputStream(modelfile);
objin =  ObjectInputStream(fin);
mSpellChecker = objin.readObject()

mSpellChecker.setAllowInsert(True);
mSpellChecker.setAllowMatch(True);
mSpellChecker.setAllowDelete(False);
mSpellChecker.setAllowSubstitute(False);
mSpellChecker.setAllowTranspose(False);

mSpellChecker.setNumConsecutiveInsertionsAllowed(1);

mMaxNBest = 1024;
mSpellChecker.setNBest(mMaxNBest);


# segment a string
#sentence=u"你好世界"
#print mSpellChecker.didYouMean(sentence)
def readInstanceList(fname):
    s = ObjectInputStream(FileInputStream(fname))
    instances = s.readObject()
    s.close()
    return instances
Ejemplo n.º 10
0
def loadModel(file):
    s = ObjectInputStream(FileInputStream(file))
    crf = s.readObject()
    s.close()
    return crf
             #if specials.length > 0:
             #    variables.extend([specials.item(i) for i in range(specials.length)])
             #primitives=obj.getElementsByTagName("primitive")
             #if primitives.length > 0:
             #    variables.extend([primitives.item(i) for i in range(primitives.length)])
         # tag along subitems
         objclasses=obj.childNodes
         for objclass in [objclasses.item(i) for i in range(objclasses.length) if objclasses.item(i).nodeName == "class"]:
             subnodes=objclass.childNodes
             for variable in [subnodes.item(i) for i in range(subnodes.length) if subnodes.item(i).nodeName == "special-object" or subnodes.item(i).nodeName == "primitive"]:
                 #for variable in variables:
                 print>>fout,"%s=%s" % (variable.getAttribute("name"),variable.getAttribute("value")),
     print>>fout
 else: # native java serialization
     # deserialize that object
     obj=ObjectInputStream(ByteArrayInputStream(message)).readObject()
     msgtime=obj.getSchedule()
     if type(msgtime) == com.ibm.itim.scheduling.RecurringIntervalSchedule:
         timestring="Every %s mins%s" %(msgtime.getInterval(), "and %s secs" % msgtime.getIntervalSec() if msgtime.getIntervalSec() else "")
     elif type(msgtime) == com.ibm.itim.scheduling.RecurringTimeSchedule:
         timearray=[]
         if msgtime.isDaily():
             timearray.append("daily")
         if msgtime.isMonthly():
             timearray.append("monthly")
         if msgtime.isWeekly():
             timearray.append("weekly")
         if msgtime.isHourly():
             timearray.append("hourly")
         if msgtime.isMinutely():
             timearray.append("every minute")
Ejemplo n.º 12
0
def readInstanceList(fname):
    s = ObjectInputStream(FileInputStream(fname))
    instances = s.readObject()
    s.close()
    return instances