本文整理汇总了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
示例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
示例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
示例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
示例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()