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


Python StringWriter.close方法代码示例

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


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

示例1: __createPackage

# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import close [as 别名]
    def __createPackage(self, outputFile=None):
        title = self.__manifest.getString(None, "title")
        manifest = self.__createManifest()
        context = JAXBContext.newInstance("au.edu.usq.fascinator.ims")
        m = context.createMarshaller()
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, True)
        writer = StringWriter()
        jaxbElem = ObjectFactory.createManifest(ObjectFactory(), manifest)
        m.marshal(jaxbElem, writer)
        writer.close()

        if outputFile is not None:
            print "writing to %s..." % outputFile
            out = FileOutputStream(outputFile)
        else:
            print "writing to http output stream..."
            filename = urllib.quote(title.replace(" ", "_"))
            response.setHeader("Content-Disposition", "attachment; filename=%s.zip" % filename)
            out = response.getOutputStream("application/zip")

        zipOut = ZipOutputStream(out)

        zipOut.putNextEntry(ZipEntry("imsmanifest.xml"))
        IOUtils.write(writer.toString(), zipOut)
        zipOut.closeEntry()

        oidList = self.__manifest.search("id")
        for oid in oidList:
            obj = Services.getStorage().getObject(oid)
            for pid in obj.getPayloadIdList():
                payload = obj.getPayload(pid)
                if not PayloadType.Annotation.equals(payload.getType()):
                    zipOut.putNextEntry(ZipEntry("resources/%s/%s" % (oid, pid)))
                    IOUtils.copy(payload.open(), zipOut)
                    payload.close()
                    zipOut.closeEntry()
            obj.close()
        zipOut.close()
        out.close()
开发者ID:kiranba,项目名称:the-fascinator,代码行数:41,代码来源:imscp.py

示例2: __createPackage

# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import close [as 别名]
 def __createPackage(self, outputFile=None):
     manifest = self.__createManifest()
     context = JAXBContext.newInstance("au.edu.usq.fascinator.ims")
     m = context.createMarshaller()
     m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, True)
     writer = StringWriter()
     jaxbElem = ObjectFactory.createManifest(ObjectFactory(), manifest)
     m.marshal(jaxbElem, writer);
     writer.close()
     
     if outputFile is not None:
         print " * imscp.py: writing to %s..." % outputFile
         out = FileOutputStream(outputFile)
     else:
         print " * imscp.py: writing to http output stream..."
         response.setHeader("Content-Disposition", "attachment; filename=%s.zip" % self.__portal.getName())
         out = response.getOutputStream("application/zip")
     
     zipOut = ZipOutputStream(out)
     
     zipOut.putNextEntry(ZipEntry("imsmanifest.xml"))
     IOUtils.write(writer.toString(), zipOut)
     zipOut.closeEntry()
     
     for key in self.__portalManifest.keySet():
         item = self.__portalManifest.get(key)
         oid = item.get("id")
         obj = Services.getStorage().getObject(oid)
         for payload in obj.getPayloadList():
             pid = payload.getId()
             if pid != "SOF-META":
                 zipOut.putNextEntry(ZipEntry("%s/%s" % (key[5:], pid)))
                 IOUtils.copy(payload.getInputStream(), zipOut)
                 zipOut.closeEntry()
     
     zipOut.close()
     out.close()
开发者ID:kiranba,项目名称:the-fascinator,代码行数:39,代码来源:imscp.py


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