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


Python StringWriter.flush方法代码示例

本文整理汇总了Python中java.io.StringWriter.flush方法的典型用法代码示例。如果您正苦于以下问题:Python StringWriter.flush方法的具体用法?Python StringWriter.flush怎么用?Python StringWriter.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.StringWriter的用法示例。


在下文中一共展示了StringWriter.flush方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getPayloadContent

# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import flush [as 别名]
 def getPayloadContent(self):
     mimeType = self.__mimeType
     print " * single.py: payload content mimeType=%s" % mimeType
     contentStr = ""
     if mimeType.startswith("text/"):
         if mimeType == "text/html":
             contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s"></iframe>' % (
                 contextPath,
                 portalId,
                 self.__oid,
             )
         else:
             pid = self.__oid[self.__oid.rfind("/") + 1 :]
             payload = self.__storage.getPayload(self.__oid, pid)
             print " * single.py: pid=%s payload=%s" % (pid, payload)
             if payload is not None:
                 sw = StringWriter()
                 sw.write("<pre>")
                 IOUtils.copy(payload.getInputStream(), sw)
                 sw.write("</pre>")
                 sw.flush()
                 contentStr = sw.toString()
     elif (
         mimeType == "application/pdf"
         or mimeType.find("vnd.ms") > -1
         or mimeType.find("vnd.oasis.opendocument.") > -1
     ):
         # get the html version if exist...
         pid = os.path.splitext(self.__pid)[0] + ".htm"
         print " * single.py: pid=%s" % pid
         # contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s/%s"></iframe>' % \
         #    (contextPath, portalId, self.__oid, pid)
         payload = self.__storage.getPayload(self.__oid, pid)
         saxReader = SAXReader(Boolean.parseBoolean("false"))
         try:
             document = saxReader.read(payload.getInputStream())
             slideNode = document.selectSingleNode("//*[local-name()='body']")
             # linkNodes = slideNode.selectNodes("//img")
             # contentStr = slideNode.asXML();
             # encode character entities correctly
             slideNode.setName("div")
             out = ByteArrayOutputStream()
             format = OutputFormat.createPrettyPrint()
             format.setSuppressDeclaration(True)
             format.setExpandEmptyElements(True)
             writer = XMLWriter(out, format)
             writer.write(slideNode)
             writer.close()
             contentStr = out.toString("UTF-8")
         except:
             traceback.print_exc()
             contentStr = '<p class="error">No preview available</p>'
     elif mimeType.startswith("image/"):
         src = "%s/%s" % (self.__oid, self.__pid)
         contentStr = (
             '<a class="image" href="%(src)s"  style="max-width:98%%">'
             '<img src="%(src)s" style="max-width:100%%" /></a>' % {"src": self.__pid}
         )
     return contentStr
开发者ID:kiranba,项目名称:the-fascinator,代码行数:61,代码来源:single.py

示例2: getPayloadContent

# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import flush [as 别名]
 def getPayloadContent(self):
     mimeType = self.__mimeType
     print " * detail.py: payload content mimeType=%s" % mimeType
     contentStr = ""
     if mimeType == "application/octet-stream":
         dcFormat = self.__json.get("response/docs/dc_format")
         if dcFormat is not None:
             dcFormat = dcFormat[1:-1]
         print dcFormat, mimeType
         if dcFormat != mimeType:
             return "<div><em>(File not found)</em></div>"
         else:
             return "<div><em>(Binary file)</em></div>"
     elif mimeType.startswith("text/"):
         if mimeType == "text/html":
             contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s"></iframe>' % \
                 (contextPath, portalId, self.__oid)
         else:
             pid = self.__oid[self.__oid.rfind("/")+1:]
             payload = self.__storage.getPayload(self.__oid, pid)
             #print " * detail.py: pid=%s payload=%s" % (pid, payload)
             if payload is not None:
                 sw = StringWriter()
                 sw.write("<pre>")
                 IOUtils.copy(payload.getInputStream(), sw)
                 sw.write("</pre>")
                 sw.flush()
                 contentStr = sw.toString()
     elif mimeType == "application/pdf" or mimeType.find("vnd.ms")>-1 or mimeType.find("vnd.oasis.opendocument.")>-1:
         # get the html version if exist...
         pid = os.path.splitext(self.__pid)[0] + ".htm"
         print " * detail.py: pid=%s" % pid
         #contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s/%s"></iframe>' % \
         #    (contextPath, portalId, self.__oid, pid)
         payload = self.__storage.getPayload(self.__oid, pid)
         saxReader = SAXReader(Boolean.parseBoolean("false"))
         try:
             document = saxReader.read(payload.getInputStream())
             slideNode = document.selectSingleNode("//*[local-name()='body']")
             #linkNodes = slideNode.selectNodes("//img")
             #contentStr = slideNode.asXML();
             # encode character entities correctly
             slideNode.setName("div")
             out = ByteArrayOutputStream()
             format = OutputFormat.createPrettyPrint()
             format.setSuppressDeclaration(True)
             format.setExpandEmptyElements(True)
             writer = XMLWriter(out, format)
             writer.write(slideNode)
             writer.close()
             contentStr = out.toString("UTF-8")
         except:
             traceback.print_exc()
             contentStr = "<p class=\"error\">No preview available</p>"
     return contentStr
开发者ID:kiranba,项目名称:the-fascinator,代码行数:57,代码来源:detail.py

示例3: getPayloadContent

# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import flush [as 别名]
 def getPayloadContent(self):
     mimeType = self.__mimeType
     print " * detail.py: payload content mimeType=%s" % mimeType
     contentStr = ""
     if mimeType.startswith("text/"):
         if mimeType == "text/html":
             contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s"></iframe>' % \
                 (contextPath, portalId, self.__oid)
         else:
             pid = self.__oid[self.__oid.rfind("/")+1:]
             payload = self.__storage.getPayload(self.__oid, pid)
             print " * detail.py: pid=%s payload=%s" % (pid, payload)
             if payload is not None:
                 sw = StringWriter()
                 sw.write("<pre>")
                 IOUtils.copy(payload.getInputStream(), sw)
                 sw.write("</pre>")
                 sw.flush()
                 contentStr = sw.toString()
     elif mimeType == "application/pdf" or mimeType.find("vnd")>-1 or mimeType.find("vnd.oasis.opendocument.")>-1:
         # get the html version if exist...
         pid = os.path.splitext(self.__pid)[0] + ".htm"
         print " * detail.py: pid=%s" % pid
         #contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s/%s"></iframe>' % \
         #    (contextPath, portalId, self.__oid, pid)
         payload = self.__storage.getPayload(self.__oid, pid)
         saxReader = SAXReader(Boolean.parseBoolean("false"))
         try:
             document = saxReader.read(payload.getInputStream())
         except:
             traceback.print_exc()
         #slideNode = document.selectSingleNode("//div[@class='body']")
         slideNode = document.selectSingleNode("//*[local-name()='body']")
         #linkNodes = slideNode.selectNodes("//img")
         #contentStr = slideNode.asXML();
         # encode character entities correctly
         out = ByteArrayOutputStream()
         format = OutputFormat.createPrettyPrint()
         format.setSuppressDeclaration(True)
         writer = XMLWriter(out, format)
         writer.write(slideNode)
         writer.close()
         contentStr = out.toString("UTF-8")
     return contentStr
开发者ID:kiranba,项目名称:the-fascinator,代码行数:46,代码来源:detail.py

示例4: __getPayloadContent

# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import flush [as 别名]
 def __getPayloadContent(self, oid, pid):
     print " * combined.py: oid='%s' pid='%s'" % (oid, pid)
     payload = self.__storage.getPayload(oid, pid)
     if payload is None:
         return "<div>Error: No content for '%s'</div>" % oid
     mimeType = payload.contentType
     contentStr = ""
     if mimeType.startswith("text/"):
         if mimeType == "text/html":
             contentStr = '<iframe class="iframe-preview" src="%s/download/%s"></iframe>' % \
                 (portalPath, oid)
         else:
             sw = StringWriter()
             sw.write("<pre>")
             IOUtils.copy(payload.getInputStream(), sw)
             sw.write("</pre>")
             sw.flush()
             contentStr = sw.toString()
     elif mimeType == "application/pdf" or mimeType.find("vnd.ms")>-1 or mimeType.find("vnd.oasis.opendocument.")>-1:
         # get the html version if exist...
         pid = os.path.splitext(pid)[0] + ".htm"
         print " * combined.py: pid=%s" % pid
         payload = self.__storage.getPayload(oid, pid)
         saxReader = SAXReader(False)
         try:
             document = saxReader.read(payload.getInputStream())
             slideNode = document.selectSingleNode("//*[local-name()='body']")
             slideNode.setName("div")
             out = ByteArrayOutputStream()
             format = OutputFormat.createPrettyPrint()
             format.setSuppressDeclaration(True)
             format.setExpandEmptyElements(True)
             writer = XMLWriter(out, format)
             writer.write(slideNode)
             writer.close()
             contentStr = out.toString("UTF-8")
         except:
             traceback.print_exc()
             contentStr = "<p class=\"error\">No preview available</p>"
     elif mimeType.startswith("image/"):
         src = "%s/%s" % (oid, pid)
         contentStr = '<a class="image" href="%(src)s"  style="max-width:98%%">' \
             '<img src="%(src)s" style="max-width:100%%" /></a>' % { "src": pid }
     return contentStr
开发者ID:Deakin,项目名称:the-fascinator,代码行数:46,代码来源:combined.py

示例5: __getPayloadAsString

# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import flush [as 别名]
 def __getPayloadAsString(self, payload):
     sw = StringWriter()
     IOUtils.copy(payload.getInputStream(), sw)
     sw.flush()
     return sw.toString()
开发者ID:kiranba,项目名称:the-fascinator,代码行数:7,代码来源:blog.py


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