Exemplo n.º 1
0
def java_utf8_message_dispatcher(buffer):
    byte_array = [buffer.get_byte(i) for i in range(buffer.length)]
    byteArrayInputStream = ByteArrayInputStream(byte_array)
    dataInputStream = DataInputStream(byteArrayInputStream)

    while dataInputStream.available() > 0:
        try:
            yield dataInputStream.readUTF()
        except:
            pass
Exemplo n.º 2
0
def runURL(url, args=[], callback=None, callbackOnErr=False):
	inp = DataInputStream(URL(url).openStream());

	contents = [];
	try:
		holder = inp.readByte()
		while holder != None:
			contents += [holder]
			holder = inp.readByte()
	except EOFException:
		pass
	except Exception as e:
		print str(e)
		return out(2, None, [], str(e).split("\n"))

	return run(contents, args, callback, callbackOnErr)
Exemplo n.º 3
0
 def run(self):
     print "connect to GS"
     sgs = Socket("127.0.0.1", 9011)
     i = DataInputStream(sgs.getInputStream())
     print "connect to GeoEditor"
     sge = Socket("127.0.0.1", 2109)
     # o = DataOutputStream(sge.getOutputStream())
     o = sge.getOutputStream()
     Thread.sleep(5000)
     GeoEditorListener.getInstance().getThread().addListener(self.vpl)
     print "gsge Ready"
     bufsize = 4096
     lastpos = 0
     buf = String("\0" * bufsize).getBytes()
     fc = 0
     while True:
         if not i.available():
             Thread.sleep(10)
             fc += 1
             if fc % 500 == 0:
                 o.flush()
                 fc = 0
             continue
         lastpos += i.read(buf, lastpos, bufsize - lastpos)
         while lastpos > 0 and lastpos > buf[0]:
             if buf[1] == 2:
                 pass
             elif buf[1] == 1:
                 x = self.list2num(buf[2:6])
                 y = self.list2num(buf[6:10])
                 z = self.list2num(buf[10:12])
                 if z > -15000:
                     rx, ry = GeoUtil.getRegionXY(x, y)
                     if (rx, ry) == (22, 22):
                         bx, by = GeoUtil.getBlockXY(x, y)
                         cx, cy = GeoUtil.getCellXY(x, y)
                         o.write(struct.pack(">BBBBh", bx, by, cx, cy, z))
             newpos = buf[0] + 1
             if len(buf) - newpos < bufsize:
                 buf = buf[newpos:] + String("\0" * bufsize).getBytes()
             else:
                 buf = buf[newpos:]
             lastpos -= newpos
Exemplo n.º 4
0
 def run(self):
     print "connect to GS"
     sgs = Socket("127.0.0.1", 9011)
     i = DataInputStream(sgs.getInputStream())
     print "connect to GeoEditor"
     sge = Socket("127.0.0.1", 2109)
     #o = DataOutputStream(sge.getOutputStream())
     o = sge.getOutputStream()
     Thread.sleep(5000)
     GeoEditorListener.getInstance().getThread().addListener(self.vpl)
     print "gsge Ready"
     bufsize = 4096
     lastpos = 0
     buf = String("\0" * bufsize).getBytes()
     fc = 0
     while True:
         if not i.available():
             Thread.sleep(10)
             fc += 1
             if fc % 500 == 0:
                 o.flush()
                 fc = 0
             continue
         lastpos += i.read(buf, lastpos, bufsize - lastpos)
         while lastpos > 0 and lastpos > buf[0]:
             if buf[1] == 2:
                 pass
             elif buf[1] == 1:
                 x = self.list2num(buf[2:6])
                 y = self.list2num(buf[6:10])
                 z = self.list2num(buf[10:12])
                 if z > -15000:
                     rx, ry = GeoUtil.getRegionXY(x, y)
                     if (rx, ry) == (22, 22):
                         bx, by = GeoUtil.getBlockXY(x, y)
                         cx, cy = GeoUtil.getCellXY(x, y)
                         o.write(struct.pack('>BBBBh', bx, by, cx, cy, z))
             newpos = buf[0] + 1
             if len(buf) - newpos < bufsize:
                 buf = buf[newpos:] + String("\0" * bufsize).getBytes()
             else:
                 buf = buf[newpos:]
             lastpos -= newpos
Exemplo n.º 5
0
 def readScalarDataFile(self, scalarfile):
     scalarData = []
     for j in range(2):
         scalerData.append(range(9))
     fis = FileInputStream(self.scalarList[i])
     dis = DataInputStream(fis)
     scalerBytes = jarray.zeros(18 * 4, 'b')
     dis.read(scalerBytes, 0, 18 * 4)
     fis.close()
     offset = 0
     for j in range(2):
         for l in range(0, 36, 4):
             scalarData[j][
                 l / 4] = (0x000000FF & scalerBytes[offset + l + 0]) + (
                     (0x000000FF & scalerBytes[offset + l + 1]) << 8
                 ) + ((0x000000FF & scalerBytes[offset + l + 2]) << 16) + (
                     (0x000000FF & scalerBytes[offset + l + 3]) << 24)
         offset = offset + 36
     fis.close()
     return scalarData
def loadModelStateFromWaypoint(startingDir, excitePath, lastExciteValue):
    wpPath = startingDir + excitePath + str(lastExciteValue) + "_wp.txt"
    Main.getRootModel().getWayPoints().setAttachedFileName(wpPath)
    waypointFile = Main.getRootModel().getWayPoints().getAttachedFile()
    dis = DataInputStream(FileInputStream(waypointFile))
    dis.readInt()
    dis.readDouble()
    cs = Main.getRootModel().createState()
    cs.readBinary(dis)
    dis.readDouble()
    cs = Main.getRootModel().createState()
    cs.readBinary(dis)
    Main.getRootModel().setState(cs)
    Main.getRootModel().rerender()
Exemplo n.º 7
0
 def onNext(self, iterator):
     if (iterator.hasTop()):
         mapping = {}
         key = iterator.getTopKey()
         cf = key.getColumnFamily()
         if cf != "f":
             while (iterator.hasTop() and "f" != key.getColumnFamily()):
                 iterator.next()
                 key = iterator.getTopKey()
         if not iterator.hasTop():
             return None
         value = iterator.getTopValue()
         size = "0"
         if value.getSize() > 0:
             bs = ByteArrayInputStream(value.get())
             ds = DataInputStream(bs)
             size = Long(WritableUtils.readVLong(ds)).toString()
         newval = Value(size)
         kv = KeyValue(key, newval)
         iterator.next()
         return kv
     else:
         return None
Exemplo n.º 8
0
    def writeKScanSummary(self, npoints, start, end, step, edgeEnergy, twoD,
                          kStartTime, kEndTime, kWeighting):
        self.writeDetectorFile(npoints)
        current = start
        # lets window this mofo
        fid = open(self.datafilename, 'a')
        current = start
        for i in range(npoints):
            windowedData = [0.0] * 9
            print 'Reading and windowing:', self.mcaList[i]
            frameData = Xspress2Utilities.interpretDataFile(
                self.mcaList[i].strip(), 0)
            totalw = 0.0
            for j in range(9):
                sumgrades = frameData[j]
                windowedData[j] = windowedData[j] + self.windowData(
                    sumgrades, self.windowValues[j][0],
                    self.windowValues[j][1])
            for j in range(9):
                totalw = totalw + windowedData[j]
            #
            # now read scalar data
            #
            scalarData = []
            for j in range(2):
                scalarData.append(range(9))
            fis = FileInputStream(self.scalarList[i])
            dis = DataInputStream(fis)
            scalerBytes = jarray.zeros(18 * 4, 'b')
            dis.read(scalerBytes, 0, 18 * 4)
            fis.close()
            offset = 0
            for j in range(2):
                for l in range(0, 36, 4):
                    scalarData[j][l / 4] = (
                        0x000000FF & scalerBytes[offset + l + 0]
                    ) + ((0x000000FF & scalerBytes[offset + l + 1]) << 8) + (
                        (0x000000FF & scalerBytes[offset + l + 2]) << 16) + (
                            (0x000000FF & scalerBytes[offset + l + 3]) << 24)
                offset = offset + 36
            secTime = self.timeForK(current, start, end, kWeighting, kEndTime,
                                    kStartTime)
            liveTime = secTime / 1000.0
            corrCounts = self.getCorrectedCounts(scalarData[0], scalarData[1],
                                                 liveTime)
            measuredCounts = scalarData[0]
            relinCounts = self.reLinearizeCounts(corrCounts)
            factor = []
            for j in range(len(relinCounts)):
                if (relinCounts[j] == 0 or measuredCounts[j] == 0):
                    val = 1
                    factor.append(1.0)
                else:
                    val = (relinCounts[j] / measuredCounts[j])
                    factor.append(val * liveTime)
            correctWindows = []
            corrWindTot = 0.0
            for j in range(9):
                correctW = float(windowedData[j]) * factor[j]
                corrWindTot = corrWindTot + correctW
                correctWindows.append(correctW)
            #print>>fid,self.mDegForK(current,edgeEnergy,twoD),comboDCM.calcEnergy(self.mDegForK(current,edgeEnergy,twoD)/1000.0),\
            #	secTime,self.ionchamberData[i][0],self.ionchamberData[i][1],self.ionchamberData[i][2],str(windowedData[0:]).strip('[]').replace(',',''), \
            #	totalw,str(correctWindows[0:]).strip('[]').replace(',',''),corrWindTot
            print>>fid,self.mDegForK(current,edgeEnergy,twoD),comboDCM.calcEnergy(self.mDegForK(current,edgeEnergy,twoD)/1000.0),\
             secTime,self.ionchamberData[i][0],self.ionchamberData[i][1],self.ionchamberData[i][2],str(windowedData[0:]).strip('[]').replace(',',''), \
             totalw,str(correctWindows[0:]).strip('[]').replace(',',''),corrWindTot
            current = current + step
            # SDP Stuff
            detectorVector = Vector()
            detectorVector.add(self.ionchamberData[i])
            detectorVector.add(windowedData[0:])
            positionVector = Vector()
            positionVector.add(str(self.mDegForK(current, edgeEnergy, twoD)))
            #sdp = ScanDataPoint("scan name",self.scannableNamesVector,self.detectorNamesVector,positionVector,detectorVector,"Panel Name","I18 Custom SDP","Header String",self.datafilename)
            sdp = ScanDataPoint("Exafs FluKScan", self.scannableNamesVector,
                                self.detectorNamesVector, None, None, None,
                                None, positionVector, detectorVector, None,
                                "Panel Name", "I18 Custom SDP",
                                "Header String", self.datafilename, 0)
            self.controller.update(None, sdp)
            self.mcontroller.update(None, sdp)

        fid.close()
Exemplo n.º 9
0
from java.net import Socket
from java.io import DataInputStream, DataOutputStream
import sys
import jline
from traceback import print_exc

if len(sys.argv) < 3:
    print "You need to specify the host and port, in that order, to"
    print "connect to."
    sys.exit()

print "Connecting..."
socket = Socket(sys.argv[1], int(sys.argv[2]))
print "Connected! One moment..."
in_stream = DataInputStream(socket.getInputStream())
out_stream = DataOutputStream(socket.getOutputStream())

try:
    while not socket.isClosed():
        mode = in_stream.readShort()
        if mode == 2: # normal text write
            sys.stdout.write(in_stream.readUTF())
            sys.stdout.flush()
        elif mode == 3: # raw_input with prompt
            result = raw_input(in_stream.readUTF())
            out_stream.writeUTF(result);
            out_stream.flush()
        elif mode == 4: # Exiting
            break
        else:
Exemplo n.º 10
0
from java.io import DataInputStream as DI
from java.io import DataOutputStream as DO

a = str(10)
b = str(20)
di = DI(a)
do = DO(b)
c = di.read()
do.write(c)

print(a,b,c)