本文整理汇总了Python中org.apache.commons.io.IOUtils.toString方法的典型用法代码示例。如果您正苦于以下问题:Python IOUtils.toString方法的具体用法?Python IOUtils.toString怎么用?Python IOUtils.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.IOUtils
的用法示例。
在下文中一共展示了IOUtils.toString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __getJson
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toString [as 别名]
def __getJson(self):
rvtMap = HashMap()
try:
oid = formData.get("oid")
object = Services.storage.getObject(oid)
payload = object.getPayload("imsmanifest.xml")
try:
from xml.etree import ElementTree
xmlStr = IOUtils.toString(payload.open(), "UTF-8")
payload.close()
xml = ElementTree.XML(xmlStr.encode("UTF-8"))
ns = xml.tag[:xml.tag.find("}")+1]
resources = {}
for res in xml.findall(ns+"resources/"+ns+"resource"):
resources[res.attrib.get("identifier")] = res.attrib.get("href")
organizations = xml.find(ns+"organizations")
defaultName = organizations.attrib.get("default")
organizations = organizations.findall(ns+"organization")
organizations = [o for o in organizations if o.attrib.get("identifier")==defaultName]
organization = organizations[0]
title = organization.find(ns+"title").text
rvtMap.put("title", title)
items = organization.findall(ns+"item")
rvtMap.put("toc", self.__getJsonItems(ns, items, resources))
except Exception, e:
data["error"] = "Error - %s" % str(e)
print data["error"]
object.close()
示例2: process
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toString [as 别名]
def process(self, inputStream, outputStream):
try:
# Read input FlowFile content
input_text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
input_obj = json.loads(input_text)
output_text = "{},{},{},{}".format(input_obj['name'],input_obj['value'],input_obj['message'],input_obj['timestamp'])
outputStream.write(bytearray(output_text.encode('utf-8')))
except:
traceback.print_exc(file=sys.stdout)
raise
示例3: process
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toString [as 别名]
def process(self, inputStream, outputStream):
try:
# Read input FlowFile content
input_text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
input_obj = json.loads(input_text)
# Transform content
output_obj = input_obj
# Write output content
outputStream.write(StringUtil.(output_obj['values']))
except:
traceback.print_exc(file=sys.stdout)
raise
示例4: process
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toString [as 别名]
def process(self, inputStream, outputStream):
text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
obj = json.loads(text)
newObj = {
"Range": 5,
"Rating": obj['rating']['primary']['value'],
"SecondaryRatings": {}
}
for key, value in obj['rating'].iteritems():
if key != "primary":
newObj['SecondaryRatings'][key] = {"Id": key, "Range": 5, "Value": value['value']}
outputStream.write(bytearray(json.dumps(newObj, indent=4).encode('utf-8')))
示例5: get_from_hdfs
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toString [as 别名]
def get_from_hdfs(self, file_loc):
"""
Try to get the text content from HDFS based on file_loc
Return schema literal string
"""
fp = HdfsPath(file_loc)
try:
if self.fs.exists(fp):
in_stream = self.fs.open(fp)
return IOUtils.toString(in_stream, 'UTF-8')
else:
return None
except:
return None
示例6: get_from_hdfs
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toString [as 别名]
def get_from_hdfs(self, file_loc):
"""
Try to get the text content from HDFS based on file_loc
Return schema literal string
"""
fp = HdfsPath(file_loc)
try:
if self.fs.exists(fp):
in_stream = self.fs.open(fp)
self.logger.info('GET schema literal from {}'.format(file_loc))
return IOUtils.toString(in_stream, 'UTF-8')
else:
self.logger.info('Schema not exists: {}'.format(file_loc))
return None
except Exception as e:
self.logger.error(str(e))
return None
示例7: process
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toString [as 别名]
def process(self, inputStream, outputStream):
try:
# Read input FlowFile content
input_text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
input_obj = json.loads(input_text)
# Transform content
output_obj = input_obj
output_obj['value'] = output_obj['value'] * output_obj['value']
output_obj['message'] = 'Hello World'
# Write output content
output_text = json.dumps(output_obj)
outputStream.write(StringUtil.toBytes(output_text))
except:
traceback.print_exc(file=sys.stdout)
raise
示例8: process
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toString [as 别名]
def process(self, instream, outstream):
# To read content as a byte array:
# data = IOUtils.toByteArray(instream)
# To read content as a string:
data = IOUtils.toString(instream, StandardCharsets.UTF_8)
# Do wordcount
words = {}
for word in data.strip().split():
if word not in words:
words[word] = 1
else:
words[word] += 1
# Write modified content
outstream.write(bytearray(json.dumps(words)))
示例9: __wget
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toString [as 别名]
def __wget(self, url):
client = BasicHttpClient(url)
m = GetMethod(url)
client.executeMethod(m)
return IOUtils.toString(m.getResponseBodyAsStream(), "UTF-8")
示例10: process
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toString [as 别名]
def process(self, inputStream, outputStream):
text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
outputStream.write(bytearray('Hello World!'[::-1].encode('utf-8')))
示例11: process
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toString [as 别名]
def process(self,inputStream,outputStream):
text = IOUtils.toString(inputStream,StandardCharsets.UTF_8)
f.write(text)
示例12: __getPayloadAsString
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toString [as 别名]
def __getPayloadAsString(self, payload):
payloadStr = IOUtils.toString(payload.open(), "UTF-8")
payload.close();
return payloadStr