本文整理汇总了Python中java.io.FileOutputStream.write方法的典型用法代码示例。如果您正苦于以下问题:Python FileOutputStream.write方法的具体用法?Python FileOutputStream.write怎么用?Python FileOutputStream.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.FileOutputStream
的用法示例。
在下文中一共展示了FileOutputStream.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveHM
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def saveHM(filename):
# Create new HTTP client
client = HttpClient()
client.getParams().setAuthenticationPreemptive(True)
defaultcreds = UsernamePasswordCredentials(user, password)
client.getState().setCredentials(AuthScope.ANY, defaultcreds)
# Get data across HTTP
url = (
"http://"
+ host
+ ":"
+ str(port)
+ "/admin/savedataview.egi?type="
+ type
+ "&data_format=NEXUSHDF5_LZW_6&data_saveopen_action=OPEN_ONLY"
)
getMethod = GetMethod(url)
getMethod.setDoAuthentication(True)
client.executeMethod(getMethod)
# Save locally
file = File(directory + "/" + filename)
out = FileOutputStream(file)
out.write(getMethod.getResponseBody())
out.close()
# Clean up
getMethod.releaseConnection()
示例2: extractZip
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def extractZip(zip, dest):
"extract zip archive to dest directory"
logger.info("Begin extracting:" + zip + " --> " +dest)
mkdir_p(dest)
zipfile = ZipFile(zip)
entries = zipfile.entries()
while entries.hasMoreElements():
entry = entries.nextElement()
if entry.isDirectory():
mkdir_p(os.path.join(dest, entry.name))
else:
newFile = File(dest, entry.name)
mkdir_p(newFile.parent)
zis = zipfile.getInputStream(entry)
fos = FileOutputStream(newFile)
nread = 0
buffer = ByteBuffer.allocate(1024)
while True:
nread = zis.read(buffer.array(), 0, 1024)
if nread <= 0:
break
fos.write(buffer.array(), 0, nread)
fos.close()
zis.close()
logger.info("End extracting:" + str(zip) + " --> " + str(dest))
示例3: exportAll
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def exportAll(exportConfigFile, generalConfigFile):
try:
print "Loading export config from :", exportConfigFile
exportConfigProp = loadProps(exportConfigFile,generalConfigFile)
adminUrl = exportConfigProp.get("adminUrl")
user = exportConfigProp.get("user")
passwd = exportConfigProp.get("password")
jarFileName = exportConfigProp.get("jarFileName")
customFile = exportConfigProp.get("customizationFile")
passphrase = exportConfigProp.get("passphrase")
project = exportConfigProp.get("project")
connectToServer(user, passwd, adminUrl)
print 'connected'
ALSBConfigurationMBean = findService("ALSBConfiguration", "com.bea.wli.sb.management.configuration.ALSBConfigurationMBean")
print "ALSBConfiguration MBean found"
print project
if project == None :
ref = Ref.DOMAIN
collection = Collections.singleton(ref)
if passphrase == None :
print "Export the config"
theBytes = ALSBConfigurationMBean.export(collection, true, None)
else :
print "Export and encrypt the config"
theBytes = ALSBConfigurationMBean.export(collection, true, passphrase)
else :
ref = Ref.makeProjectRef(project);
print "Export the project", project
collection = Collections.singleton(ref)
theBytes = ALSBConfigurationMBean.exportProjects(collection, passphrase)
print 'fileName',jarFileName
aFile = File(jarFileName)
print 'file',aFile
out = FileOutputStream(aFile)
out.write(theBytes)
out.close()
print "ALSB Configuration file: "+ jarFileName + " has been exported"
if customFile != None:
print collection
query = EnvValueQuery(None, Collections.singleton(EnvValueTypes.WORK_MANAGER), collection, false, None, false)
customEnv = FindAndReplaceCustomization('Set the right Work Manager', query, 'Production System Work Manager')
print 'EnvValueCustomization created'
customList = ArrayList()
customList.add(customEnv)
print customList
aFile = File(customFile)
out = FileOutputStream(aFile)
Customization.toXML(customList, out)
out.close()
# print "ALSB Dummy Customization file: "+ customFile + " has been created"
except:
raise
示例4: save_example
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def save_example(self, label, image_byte_array):
output_file_name = label + "_" + str(java.lang.System.currentTimeMillis()) + ".png"
save_path = File(self.dir_path, output_file_name).getCanonicalPath()
fileos = FileOutputStream(save_path)
for byte in image_byte_array:
fileos.write(byte)
fileos.flush()
fileos.close()
示例5: writeToFile
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def writeToFile(text, testId):
filename = "log/%s-%s-page-%d.html" % (grinder.processName,
testId,
grinder.runNumber)
# Use Java FileOutputStream since it has better Unicode handling
os = FileOutputStream(filename)
os.write(text)
os.close()
示例6: run
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def run(string, args=[], callback=None, callbackOnErr=False):
def out (exit, call, inp, err):
return {
"exitCode": exit,
"callbackReturn": call,
"inputArray": inp,
"errorArray": err
}
tmp = File.createTempFile('tmp', None)
tmp.setExecutable(True)
writer = FileOutputStream(tmp);
writer.write(string)
writer.flush()
writer.close()
try:
process = Runtime.getRuntime().exec([tmp.getAbsolutePath()] + ([str(i) for i in args] or []))
process.waitFor()
inp = BufferedReader(InputStreamReader(process.getInputStream()))
err = BufferedReader(InputStreamReader(process.getErrorStream()))
errFlag = False
inputArray = []
errorArray = []
holder = inp.readLine()
while holder != None:
print holder
inputArray += [holder]
holder = inp.readLine()
holder = err.readLine()
while holder != None:
errFlag = True
errorArray += [holder]
holder = err.readLine()
tmp.delete()
if errFlag:
if callback and callbackOnErr: return out(1, callback(out(1, None, inputArray, errorArray)), inputArray, errorArray)
else: return out(1, None, inputArray, errorArray)
else:
if callback: return out(0, callback(out(0, None, inputArray, [])), inputArray, [])
else: return out(0, None, inputArray, [])
except Exception as e:
print str(e)
tmp.delete()
if callback and callbackOnErr: return out(3, callback(out(3, None, [], str(e).split("\n"))), [], str(e).split("\n"))
else: return out(3, None, [], str(e).split("\n"))
示例7: unzipFile
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def unzipFile(zipFile, outputFolder):
zis = ZipInputStream(FileInputStream(zipFile))
ze = zis.getNextEntry()
while ze != None:
fileName = ze.getName()
newFile = File(outputFolder + File.separator + fileName)
print ("file unzip : " + str(newFile.getAbsoluteFile()))
File(newFile.getParent()).mkdirs()
fos = FileOutputStream(newFile)
len = zis.read()
while len > 0:
fos.write(len)
len = zis.read()
fos.close()
ze = zis.getNextEntry()
zis.closeEntry()
zis.close()
示例8: exportAll
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def exportAll():
try:
ALSBConfigurationMBean = findService("ALSBConfiguration", "com.bea.wli.sb.management.configuration.ALSBConfigurationMBean")
print "ALSBConfiguration MBean found"
print project
if project == "None" :
ref = Ref.DOMAIN
collection = Collections.singleton(ref)
if passphrase == None :
print "Export the config"
theBytes = ALSBConfigurationMBean.export(collection, true, None)
else :
print "Export and encrypt the config"
theBytes = ALSBConfigurationMBean.export(collection, true, passphrase)
else :
ref = Ref.makeProjectRef(project);
print "Export the project", project
collection = Collections.singleton(ref)
theBytes = ALSBConfigurationMBean.exportProjects(collection, passphrase)
aFile = File(exportJar)
out = FileOutputStream(aFile)
out.write(theBytes)
out.close()
print "ALSB Configuration file: "+ exportJar + " has been exported"
if customFile != "None":
print collection
query = EnvValueQuery(None, Collections.singleton(EnvValueTypes.WORK_MANAGER), collection, false, None, false)
customEnv = FindAndReplaceCustomization('Set the right Work Manager', query, 'Production System Work Manager')
print 'EnvValueCustomization created'
customList = ArrayList()
customList.add(customEnv)
print customList
aFile = File(customFile)
out = FileOutputStream(aFile)
Customization.toXML(customList, out)
out.close()
print "ALSB Dummy Customization file: "+ customFile + " has been created"
except:
raise
示例9: getNagiosStatus
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def getNagiosStatus(self, name=""):
# os io functions not implented in wsadmin jython, use java equivalents
while 1:
try:
fifo=FileOutputStream(self.__nagiosFifo)
logger.debug("Opened fifo for output : %s" % self.__nagiosFifo)
statuslines=[]
perflines=[]
code=-1
statusMessage="WAS-STATUS UNKNOWN"
try:
for a in self.getWasObjects('Server') + self.getWasObjects('DB2DataSource') + self.getWasObjects('AS400DataSource'):
for s in a.getNagiosStatus():
if (s.getPerformanceData()!=""):
perflines.append("%s%s" % (a.getContainmentPath(),s.getPerformanceData()))
statuslines.append("%s %s-%s" % (a.getConfigType(),a.getName(),s.getMessage()))
if s.getCode()>code:
code=s.getCode()
if code==NagiosStat.OK:
statusmessage="WAS-OK"
else:
statusmessage="WAS-%s" % s.getMessage()
except:
logger.error("Error querying PMI state")
logger.error(str(sys.exc_info()[1]) + "\n")
logger.debug(sys.exc_info()[2].dumpStack() + "\n")
if len(perflines) > 0:
statuslines[-1]="%s|%s" % (statuslines[-1],perflines[0])
if len(perflines[1:]) > 1:
statuslines+=perflines[1:]
if code==-1: code=NagiosStat.UNKNOWN
fifo.write(java.lang.String("%s\n" % code).getBytes())
fifo.write(java.lang.String("%s\n" % statusmessage).getBytes())
for s in statuslines:
fifo.write(java.lang.String(s).getBytes())
fifo.write(java.lang.String("\n").getBytes())
# Send EOT to end the message
fifo.write(java.lang.String("\004").getBytes())
fifo.close()
logger.debug("Closed fifo for output : %s" % self.__nagiosFifo)
except:
fifo.close()
logger.error("Interupted syscall, closed fifo for output : %s" % self.__nagiosFifo)
time.sleep(1)
示例10: _get_file
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def _get_file(self, remote_path, local_path):
local_file = FileOutputStream(local_path)
remote_file_size = self._client.stat(remote_path).size
remote_file = self._client.openFileRO(remote_path)
array_size_bytes = 4096
data = jarray.zeros(array_size_bytes, 'b')
offset = 0
while True:
read_bytes = self._client.read(remote_file, offset, data, 0,
array_size_bytes)
data_length = len(data)
if read_bytes == -1:
break
if remote_file_size - offset < array_size_bytes:
data_length = remote_file_size - offset
local_file.write(data, 0, data_length)
offset += data_length
self._client.closeFile(remote_file)
local_file.flush()
local_file.close()
示例11: extract_tools_data_from_jar_files
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def extract_tools_data_from_jar_files(self):
"""Create tools directories from JAR files with tools data
Read directories from tools/data and create jar files in tools/jar
"""
jarDir = File(self.jarDir)
for jarFileName in jarDir.list():
toolDir = File.separator.join([self.toolsDir, jarFileName[:-4]])
self.delete_old_tool_directory(File(toolDir))
jar = JarFile(File(self.jarDir, jarFileName))
for entry in jar.entries():
f = File(File.separator.join([self.toolsDir, entry.getName()]))
if entry.isDirectory():
f.mkdir()
continue
inputStream = jar.getInputStream(entry)
fos = FileOutputStream(f)
while inputStream.available() > 0:
fos.write(inputStream.read())
fos.close()
inputStream.close()
示例12: writeMovie
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def writeMovie(bytes, fname):
from org.openlaszlo.iv.flash.api import FlashFile, Script
from org.openlaszlo.iv.flash.api.action import DoAction, Program
file = FlashFile.newFlashFile()
file.version = 5
file.mainScript = Script(1)
frame = file.mainScript.newFrame()
program = Program(bytes, 0, len(bytes))
frame.addFlashObject(DoAction(program))
istr = file.generate().inputStream
from jarray import zeros
bytes = zeros(istr.available(), 'b')
istr.read(bytes)
from java.io import FileOutputStream
ostr = FileOutputStream(fname)
try:
ostr.write(bytes)
finally:
ostr.close()
return
示例13: _get_file
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def _get_file(self, source, dest):
localfile = FileOutputStream(dest)
tempstats = self._client.stat(source)
remotefilesize = tempstats.size
remotefile = self._client.openFileRO(source)
size = 0
arraysize = 4096
data = jarray.zeros(arraysize, "b")
while True:
moredata = self._client.read(remotefile, size, data, 0, arraysize)
datalen = len(data)
if moredata == -1:
break
if remotefilesize - size < arraysize:
datalen = remotefilesize - size
localfile.write(data, 0, datalen)
size += datalen
self._client.closeFile(remotefile)
localfile.flush()
localfile.close()
示例14: syncNmapPortConfigFile
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def syncNmapPortConfigFile(agentPath):
'''
Sync nmap port config with global probe's "port number to port name" mapping
'''
logger.debug('synchronizing nmap port config file')
portConfigFilename = agentPath + CollectorsParameters.getDiscoveryConfigFolder() + CollectorsParameters.FILE_SEPARATOR + 'portNumberToPortName.xml'
mamservice = File(portConfigFilename)
nmapservice = File(agentPath + CollectorsParameters.getDiscoveryResourceFolder() + CollectorsParameters.FILE_SEPARATOR + 'nmap-services')
if nmapservice.lastModified() > mamservice.lastModified():
return
nmapFile = FileOutputStream(nmapservice)
document = SAXBuilder(0).build(mamservice)
# document = parse(portConfigFilename)
ports = XmlWrapper(document.getRootElement().getChildren('portInfo'))
for port in ports:
if int(port.getAttributeValue("discover")):
portNumber = port.getAttributeValue("portNumber")
portName = port.getAttributeValue("portName")
portProtocol = port.getAttributeValue("portProtocol")
nmapFile.write("%s\t%s/%s\r\n" % (portName, portNumber, portProtocol))
nmapFile.close()
示例15: __init__
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import write [as 别名]
def __init__(self):
dataDir = Settings.dataDir + 'quickstart/'
# Open the stream. Read only access is enough for Aspose.Words to load a document.
stream = FileInputStream(dataDir + 'Document.doc')
# Load the entire document into memory.
doc = Document(stream)
# You can close the stream now, it is no longer needed because the document is in memory.
stream.close()
# ... do something with the document
# Convert the document to a different format and save to stream.
dstStream = ByteArrayOutputStream()
doc.save(dstStream, SaveFormat.RTF)
output = FileOutputStream(dataDir + "Document Out.rtf")
output.write(dstStream.toByteArray())
output.close()
print "Document loaded from stream and then saved successfully."