本文整理汇总了Python中java.io.StringWriter.toString方法的典型用法代码示例。如果您正苦于以下问题:Python StringWriter.toString方法的具体用法?Python StringWriter.toString怎么用?Python StringWriter.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.StringWriter
的用法示例。
在下文中一共展示了StringWriter.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [as 别名]
def execute(self):
self.customize(self.options)
connection = None
try:
connection = Overthere.getConnection(CifsConnectionBuilder.CIFS_PROTOCOL, self.options)
connection.setWorkingDirectory(connection.getFile(self.remotePath))
# upload the script and pass it to powershell
targetFile = connection.getTempFile("uploaded-powershell-script", ".ps1")
OverthereUtils.write(String(self.script).getBytes(), targetFile)
targetFile.setExecutable(True)
scriptCommand = CmdLine.build(
"powershell",
"-NoLogo",
"-NonInteractive",
"-InputFormat",
"None",
"-ExecutionPolicy",
"Unrestricted",
"-Command",
targetFile.getPath(),
)
return connection.execute(self.stdout, self.stderr, scriptCommand)
except Exception, e:
stacktrace = StringWriter()
writer = PrintWriter(stacktrace, True)
e.printStackTrace(writer)
self.stderr.handleLine(stacktrace.toString())
return 1
示例2: getPayloadContent
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [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
示例3: register_script
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [as 别名]
def register_script(self):
"""
Registers a pig scripts with its variables substituted.
raises: IOException If a temp file containing the pig script could not be created.
raises: ParseException The pig script could not have all its variables substituted.
todo: Refactor this processes that result in calling this method. This method gets
called twice for a single assert as every method that needs the data assumes no one
else has called it (even methods that call other methods that call it (assertOutput()
calls get_alias() which both call this method).
"""
pigIStream = BufferedReader(StringReader(self.orig_pig_code))
pigOStream = StringWriter()
ps = ParameterSubstitutionPreprocessor(50) # Where does 50 come from?
ps.genSubstitutedFile(pigIStream, pigOStream, self.args, self.arg_files)
substitutedPig = pigOStream.toString()
f = File.createTempFile("tmp", "pigunit")
pw = PrintWriter(f)
pw.println(substitutedPig)
pw.close()
pigSubstitutedFile = f.getCanonicalPath()
self._temp_pig_script = pigSubstitutedFile
self.pig.registerScript(pigSubstitutedFile, self.alias_overrides)
示例4: getPayloadContent
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [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
示例5: __toXMLString
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [as 别名]
def __toXMLString(self, document):
domSource = DOMSource(document)
writer = StringWriter()
result = StreamResult(writer)
tf = TransformerFactory.newInstance()
transformer = tf.newTransformer()
transformer.transform(domSource, result)
return writer.toString()
示例6: exec_script
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [as 别名]
def exec_script(self, engine_name, script, post_script="", attr={}):
r = ""
l2sem = L2ScriptEngineManager.getInstance()
context = SimpleScriptContext()
sw = StringWriter()
pw = PrintWriter(sw, True)
context.setAttribute("out_writer", pw, ScriptContext.ENGINE_SCOPE)
for k in attr:
context.setAttribute(str(k), attr[k], ScriptContext.ENGINE_SCOPE)
context.setWriter(pw)
context.setErrorWriter(pw)
try:
l2sem.eval(engine_name, script, context)
r += sw.toString()
except ScriptException, e:
r += sw.toString()
r += e.getMessage()
示例7: getResourceContent
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [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 java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [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 java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [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: _get_details
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [as 别名]
def _get_details(self):
# OOME.printStackTrace seems to throw NullPointerException
if self._is_out_of_memory_error(self._exc_type):
return ''
output = StringWriter()
self._exc_value.printStackTrace(PrintWriter(output))
details = '\n'.join(line for line in output.toString().splitlines()
if not self._is_ignored_stack_trace_line(line))
msg = unic(self._exc_value.getMessage() or '')
if msg:
details = details.replace(msg, '', 1)
return details
示例11: getAboutPage
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [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)
示例12: _get_java_details
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [as 别名]
def _get_java_details(exc_value):
# OOME.printStackTrace seems to throw NullPointerException
if isinstance(exc_value, OutOfMemoryError):
return ''
output = StringWriter()
exc_value.printStackTrace(PrintWriter(output))
lines = [ line for line in output.toString().splitlines()
if line and not _is_ignored_stacktrace_line(line) ]
details = '\n'.join(lines)
msg = unic(exc_value.getMessage() or '')
if msg:
details = details.replace(msg, '', 1)
return details
示例13: test_logger
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [as 别名]
def test_logger(self):
# Setup writer
stringWriter = StringWriter()
pyFileWriter = PyFileWriter(stringWriter)
oldWriter = sys.stdout
sys.stdout = pyFileWriter
# Run
logger.log('123')
output = stringWriter.toString()
sys.stdout = oldWriter
# Assert
self.assertTrue(output.index('123') > 0)
示例14: execute
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [as 别名]
def execute(self):
self.customize(self.options)
connection = None
try:
connection = Overthere.getConnection(CifsConnectionBuilder.CIFS_PROTOCOL, self.options)
connection.setWorkingDirectory(connection.getFile(self.TestPath))
# upload the ResultName and pass it to csResultName.exe
ResultNameCommand = CmdLine.build(WlrunExe, "-Run", "-TestPath", TestPath, "-ResultName", ResultName)
return connection.execute(self.stdout, self.stderr, ResultNameCommand)
except Exception, e:
stacktrace = StringWriter()
writer = PrintWriter(stacktrace, True)
e.printStackTrace(writer)
self.stderr.handleLine(stacktrace.toString())
return 1
示例15: writeDom
# 需要导入模块: from java.io import StringWriter [as 别名]
# 或者: from java.io.StringWriter import toString [as 别名]
def writeDom(doc):
try:
# set up a transformer
transfac = TransformerFactory.newInstance()
trans = transfac.newTransformer()
trans.setOutputProperty(OutputKeys.ENCODING, "utf-8")
trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no")
trans.setOutputProperty(OutputKeys.INDENT, "yes")
trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2")
sw1 = StringWriter()
result = StreamResult(sw1)
source = DOMSource(doc)
trans.transform(source, result)
xmlString = sw1.toString()
print xmlString
except Exception, e:
print e