本文整理汇总了Python中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例。如果您正苦于以下问题:Python IOUtils.copy方法的具体用法?Python IOUtils.copy怎么用?Python IOUtils.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.IOUtils
的用法示例。
在下文中一共展示了IOUtils.copy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __load
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [as 别名]
def __load(self, oid):
template = """<div class="title" /><div class="page-toc" /><div class="body"><div>%s</div></div>"""
print "Loading HTML preview for %s..." % oid
if oid == "blank":
return template % "<p>This page intentionally left blank.</p>"
else:
object = Services.getStorage().getObject(oid)
# get preview payload or source if no preview
pid = self.__getPreviewPid(object)
payload = object.getPayload(pid)
mimeType = payload.getContentType()
print "pid=%s mimeType=%s" % (pid, mimeType)
isHtml = mimeType in ["text/html", "application/xhtml+xml"]
if isHtml or mimeType.startswith("text/"):
out = ByteArrayOutputStream()
IOUtils.copy(payload.open(), out)
content = out.toString("UTF-8")
if content.find('class="body"'): ## assumes ICE content
return content
elif isHtml:
return template % content
elif mimeType == "text/plain":
return template % ('<pre>%s</pre>' % content)
else:
return content
elif mimeType.startswith("image/"):
return template % ('<div rel="%s"><img src="%s" /></div>' % (oid, pid))
else:
return '<a href="%s" rel="%s">%s</a>' % (oid, mimeType, pid)
payload.close()
object.close()
示例2: parseFFmpeg
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [as 别名]
def parseFFmpeg(self, parent):
if parent is not None:
object = parent.getObject()
if object is not None:
payload = None
try:
payload = object.getPayload("ffmpeg.info")
# Stream the content out to string
out = ByteArrayOutputStream()
IOUtils.copy(payload.open(), out)
payload.close()
self.__ffmpegRaw = out.toString("UTF-8")
out.close()
payload.close()
# And parse it
self.__ffmpegData = JsonSimple(self.__ffmpegRaw)
if self.__ffmpegData is None:
return False
else:
self.__ffmpegOutputs = self.__ffmpegData.getJsonSimpleMap(["outputs"])
return True
except:
if payload is not None:
payload.close()
return False
示例3: __getFile
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [as 别名]
def __getFile(self, packageDir, filename):
file = File(packageDir, filename)
if not file.exists():
out = FileOutputStream(file)
IOUtils.copy(Services.getClass().getResourceAsStream("/workflows/" + filename), out)
out.close()
return file
示例4: getPayloadContent
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [as 别名]
def getPayloadContent(self):
format = self.__metadata.getField("dc_format")
slash = self.__oid.rfind("/")
pid = self.__oid[slash+1:]
print " *** payload content, format: %s, pid: %s *** " % (format, pid)
contentStr = ""
if format.startswith("text"):
contentStr = "<pre>"
payload = self.__storage.getPayload(self.__oid, pid)
str = StringWriter()
IOUtils.copy(payload.getInputStream(), str)
contentStr += str.toString()
contentStr += "</pre>"
elif format.find("vnd.ms-")>-1 or format.find("vnd.oasis.opendocument.")>-1:
#get the html version if exist....
pid = pid[:pid.find(".")] + ".htm"
payload = self.__storage.getPayload(self.__oid, pid)
saxReader = SAXReader()
document = saxReader.read(payload.getInputStream())
slideNode = document.selectSingleNode("//div[@class='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
示例5: pageContent
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [as 别名]
def pageContent(self):
# Object ID
oid = self.metadata.get("id")
# Determine MIME Type
mimeType = "Unknown"
mimeList = self.metadata.getList("dc_format")
if mimeList is not None and not mimeList.isEmpty():
mimeType = mimeList.get(0)
# The HTML payload is the real object, display in a frame because we
# have no idea what kind of object it is.
if mimeType == "text/html":
objectPath = "http://%s:%s%s/%s/download/%s/" % \
(self.req.serverName, self.serverPort, self.contextPath, self.portalId, oid)
objectLink = '<a class="iframe-link-alt" href="%s">View outside the frame</a>' % objectPath
objectFrame = '<iframe class="iframe-preview" src="%s"></iframe>' % objectPath
return objectLink + "<br/>" + objectFrame
# We are just rendering a HTML preview
else:
preview = self.metadata.get("preview")
try:
object = Services.getStorage().getObject(oid)
payload = object.getPayload(preview)
out = ByteArrayOutputStream()
IOUtils.copy(payload.open(), out)
payload.close()
return out.toString("UTF-8")
except StorageException, e:
return
示例6: getPayloadContent
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [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
示例7: getResourceContent
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [as 别名]
def getResourceContent(self, plugin, field):
resource = self.getMetadata(plugin, field)
stream = self.pageService.getResource(resource)
if stream:
writer = StringWriter()
IOUtils.copy(stream, writer, "UTF-8")
html = writer.toString()
print " *** html:", html
return html
return "<em>'%s' not found!</em>" % (field)
示例8: getPayloadContent
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [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
示例9: getAboutPage
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [as 别名]
def getAboutPage(self, plugin, type):
if type is None or plugin is None:
return "<em>This plugin has provided no information about itself.</em>"
pid = plugin.replace("-", "_")
resource = "plugin/%s/%s/about.html" % (type, pid)
stream = self.pageService.getResource(resource)
if stream:
writer = StringWriter()
IOUtils.copy(stream, writer, "UTF-8")
html = writer.toString()
return html
return "<em>This plugin has provided no information about itself.</em>"
示例10: getAboutPage
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [as 别名]
def getAboutPage(self, plugin, type):
if type is None or plugin is None:
return "<em>'plugin/%s/%s/about.html' not found!</em>" % (type, plugin)
pid = plugin.replace("-", "_")
resource = "plugin/%s/%s/about.html" % (type, pid)
stream = self.pageService.getResource(resource)
if stream:
writer = StringWriter()
IOUtils.copy(stream, writer, "UTF-8")
html = writer.toString()
return html
return "<em>'plugin/%s/%s/about.html' not found!</em>" % (type, pid)
示例11: getPayloadContent
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [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
示例12: __getPayloadContent
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [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
示例13: pageContent
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [as 别名]
def pageContent(self):
# Object ID
oid = self.metadata.getFirst("id")
# Determine MIME Type
mimeType = "Unknown"
mimeList = self.metadata.getList("dc_format")
if mimeList is not None and not mimeList.isEmpty():
mimeType = mimeList.get(0)
# The HTML payload is the real object, display in a frame because we
# have no idea what kind of object it is.
if mimeType == "text/html":
urlBase = self.config.getString(None, ["urlBase"])
if urlBase is None:
"http://%s:%s%s/" % (self.req.serverName, self.serverPort, self.contextPath)
objectPath = "%s%s/download/%s/" % (urlBase, self.portalId, oid)
return self.frameContent(objectPath)
# We are rendering a HTML preview...
else:
preview = self.metadata.getFirst("preview")
# ... of an IMS package or zipped website. Treat as per html above.
if mimeType == "application/zip":
urlBase = self.config.getString(None, ["urlBase"])
if urlBase is None:
"http://%s:%s%s/" % (self.req.serverName, self.serverPort, self.contextPath)
objectPath = "%s%s/download/%s/%s" % (urlBase, self.portalId, oid, preview)
return self.frameContent(objectPath)
# ... of an HTML excerpt, such as an ICE rendition. Render in page.
else:
try:
object = Services.getStorage().getObject(oid)
payload = object.getPayload(preview)
out = ByteArrayOutputStream()
IOUtils.copy(payload.open(), out)
payload.close()
return out.toString("UTF-8")
except StorageException, e:
return
示例14: __init__
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [as 别名]
def __init__(self):
basePath = portalId + "/" + pageName
uri = request.getAttribute("RequestURI")
print " * download.py: basePath=%s uri=%s" % (basePath, uri)
uri = uri[len(basePath) + 1 :]
if uri.find("%2F") == -1:
slash = uri.rfind("/")
else:
slash = uri.find("/")
oid = URLDecoder.decode(uri[:slash])
pid = URLDecoder.decode(uri[slash + 1 :])
print " * download.py: oid=%s pid=%s" % (oid, pid)
payload = Services.storage.getPayload(oid, pid)
filename = os.path.split(pid)[1]
mimeType = payload.contentType
if mimeType == "application/octet-stream":
response.setHeader("Content-Disposition", "attachment; filename=%s" % filename)
out = response.getOutputStream(payload.contentType)
IOUtils.copy(payload.inputStream, out)
out.close()
示例15: getSourceSample
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import copy [as 别名]
def getSourceSample(self, id, limit):
# Get source payload
object = self.services.getStorage().getObject(id)
if object is not None:
payload = object.getPayload(object.getSourceId())
# Read to a string
if payload is not None:
out = ByteArrayOutputStream()
IOUtils.copy(payload.open(), out)
payload.close()
string = out.toString("UTF-8")
# Return response
if string is not None:
if (len(string)) > limit:
return string[0:limit] + "..."
else:
return string
else:
return ""