def testReadWriteJSON(self): ostream = io.ByteArrayOutputStream() writeJSON(self.l, output=ostream) istream = io.ByteArrayInputStream(ostream.toByteArray()) l = readJSON(istream) assert self.l.count() == l.count() c = self.l.cursor("STATE_ABBR = 'TX'") ostream = io.ByteArrayOutputStream() writeJSON(c, output=ostream) c.close() istream = io.ByteArrayInputStream(ostream.toByteArray()) l = readJSON(istream) assert 1 == l.count() f = [x for x in l.features()][0] assert 'Texas' == f['STATE_NAME']
def _toXML(filter, pretty=True, version=1.0): """ Encodes a filter object as XML. """ ogc, ogcconfig = _ogc(version) e = Encoder(ogcconfig) e.indenting = pretty e.omitXMLDeclaration = True out = io.ByteArrayOutputStream() e.encode(filter, ogc.Filter, out) return str(lang.String(out.toByteArray()))
def execute(self, data): if not self.is_jython: print '[!] This module can only be used in jython!' return data # Creating XStream object and creating Java object from XML structure xs = XStream() serial = xs.fromXML(data) # writing created Java object to and serializing it with ObjectOutputStream bos = io.ByteArrayOutputStream() oos = io.ObjectOutputStream(bos) oos.writeObject(serial) # I had a problem with signed vs. unsigned bytes, hence the & 0xff return "".join([chr(x & 0xff) for x in bos.toByteArray().tolist()])
def serializeData(self): """ Serialize data, put the result inside self.output """ self.output = '\xAC\xED\x00\x05' for type_, data in self.input: print type_ print data print len(data) if type_ == 'object': # Create XStream object and create Java object from the XML structure xs = XStream() serialized = xs.fromXML(data) # Serialize created object with ObjectOutputStream bos = io.ByteArrayOutputStream() oos = io.ObjectOutputStream(bos) oos.writeObject(serialized) self.output += bos.toByteArray()[4:] elif type_ == 'block': # TC_BLOCKDATA = (byte)0x77 if len(data) <= 0xff: self.output += '\x77' self.output += struct.pack('<B', len(data)) # length on 1 byte # TC_BLOCKDATALONG = (byte)0x7A else: self.output += '\x7A' self.output += struct.pack( '>I', len(data)) # length on 4 bytes (big endian) self.output += ''.join( list(map(lambda x: chr(int(x, 16)), data)))