本文整理匯總了Python中java.io.InputStreamReader方法的典型用法代碼示例。如果您正苦於以下問題:Python io.InputStreamReader方法的具體用法?Python io.InputStreamReader怎麽用?Python io.InputStreamReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.io
的用法示例。
在下文中一共展示了io.InputStreamReader方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: view_source
# 需要導入模塊: from java import io [as 別名]
# 或者: from java.io import InputStreamReader [as 別名]
def view_source(context, web_view, filename):
from base64 import b64encode
from os.path import join
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_for_filename
from java.io import BufferedReader, InputStreamReader
stream = context.getAssets().open(join(ASSET_SOURCE_DIR, filename))
reader = BufferedReader(InputStreamReader(stream))
text = "\n".join(iter(reader.readLine, None))
formatter = HtmlFormatter()
body = highlight(text, get_lexer_for_filename(filename), formatter)
html = ("<html><head><style>{}\n{}</style></head><body>{}</body></html>"
.format(formatter.get_style_defs(), EXTRA_CSS, body)).encode()
web_view.loadData(b64encode(html).decode(), "text/html", "base64")
示例2: run
# 需要導入模塊: from java import io [as 別名]
# 或者: from java.io import InputStreamReader [as 別名]
def run(self):
try:
while (self.inStream.read() != -1):
isr = InputStreamReader(self.inStream)
br = BufferedReader(isr)
print str(br.readLine())
except BaseException as ex:
print 'Could not read API input/output/error buffer\n'
示例3: _excmd
# 需要導入模塊: from java import io [as 別名]
# 或者: from java.io import InputStreamReader [as 別名]
def _excmd(self, sshcmd):
'''
return (connected_ok, response_array)
'''
connected_ok=True
resp = []
try:
conn = Connection(self.hostname)
conn.connect()
self.logger.info('ssh connection created.')
isAuthenticated = conn.authenticateWithPassword(self.user, self.password)
if not isAuthenticated:
connected_ok=False
self.logger.error('ssh failed to authenticatd.')
else:
self.logger.info('ssh authenticated.')
sess = conn.openSession()
self.logger.info('ssh session created.')
sess.execCommand(sshcmd)
self.logger.info('ssh command issued. cmd is %s'%sshcmd)
stdout = StreamGobbler(sess.getStdout())
br = BufferedReader(InputStreamReader(stdout))
while True:
line = br.readLine()
if line is None:
break
else :
resp.append(line)
self.logger.warning('ssh command output: '%resp)
except IOException ,ex:
connected_ok=False
#print "oops..error,", ex
self.logger.error('ssh exception: %s'% ex)
示例4: _stringio_as_reader
# 需要導入模塊: from java import io [as 別名]
# 或者: from java.io import InputStreamReader [as 別名]
def _stringio_as_reader(s):
return BufferedReader(InputStreamReader(ByteArrayInputStream(bytearray(s.getvalue()))))