当前位置: 首页>>代码示例>>Python>>正文


Python IOUtils.toString方法代码示例

本文整理汇总了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()
开发者ID:kiranba,项目名称:the-fascinator,代码行数:30,代码来源:json_ims.py

示例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
开发者ID:sucitw,项目名称:python_snippets,代码行数:13,代码来源:json_to_string_transform.py

示例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
开发者ID:sucitw,项目名称:python_snippets,代码行数:15,代码来源:write_content.py

示例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')))
开发者ID:mattyb149,项目名称:nifi-script-tester,代码行数:15,代码来源:test_json2json.py

示例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    
开发者ID:dmoore247,项目名称:WhereHows,代码行数:17,代码来源:SchemaUrlHelper.py

示例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
开发者ID:alyiwang,项目名称:WhereHows,代码行数:19,代码来源:SchemaUrlHelper.py

示例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
开发者ID:sucitw,项目名称:python_snippets,代码行数:19,代码来源:json_transform.py

示例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)))
开发者ID:ChienHsiung,项目名称:python,代码行数:19,代码来源:nifi-wordcount.py

示例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")
开发者ID:Deakin,项目名称:redbox,代码行数:7,代码来源:timNotification.py

示例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')))
开发者ID:sucitw,项目名称:python_snippets,代码行数:5,代码来源:read_update_content.py

示例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)
开发者ID:ChienHsiung,项目名称:python,代码行数:5,代码来源:nifiPython0.py

示例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
开发者ID:kiranba,项目名称:the-fascinator,代码行数:6,代码来源:blog.py


注:本文中的org.apache.commons.io.IOUtils.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。