本文整理汇总了Python中java.io.FileOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Python FileOutputStream.close方法的具体用法?Python FileOutputStream.close怎么用?Python FileOutputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.FileOutputStream
的用法示例。
在下文中一共展示了FileOutputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transformReport
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [as 别名]
class report_generation:
'Test Report Generation'
def transformReport(self,stylesheet,xml,output,params):
from java.io import FileInputStream
from java.io import FileOutputStream
from java.io import ByteArrayOutputStream
from javax.xml.transform import TransformerFactory
from javax.xml.transform.stream import StreamSource
from javax.xml.transform.stream import StreamResult
self.xsl = FileInputStream("%s" % stylesheet)
self.xml = FileInputStream("%s" % xml)
self.html = FileOutputStream("%s" % output)
try:
self.xslSource = StreamSource(self.xsl)
self.tfactory = TransformerFactory.newInstance()
self.xslTemplate = self.tfactory.newTemplates(self.xslSource)
self.transformer = self.xslTemplate.newTransformer()
self.source = StreamSource(self.xml)
self.result = StreamResult(self.html)
for self.key,self.value in params.items():
self.transformer.setParameter(self.key, self.value)
self.transformer.transform(self.source, self.result)
finally:
self.xsl.close()
self.xml.close()
self.html.close()
示例2: saveHM
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [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()
示例3: XmlWriter
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [as 别名]
class XmlWriter(AbstractXmlWriter):
def __init__(self, path):
self.path = path
self._output = FileOutputStream(path)
self._writer = SAXTransformerFactory.newInstance().newTransformerHandler()
self._writer.setResult(StreamResult(self._output))
self._writer.startDocument()
self.content('\n')
self.closed = False
def start(self, name, attributes={}, newline=True):
attrs = AttributesImpl()
for attrname, attrvalue in attributes.items():
attrs.addAttribute('', '', attrname, '', attrvalue)
self._writer.startElement('', '', name, attrs)
if newline:
self.content('\n')
def content(self, content):
if content is not None:
content = self._encode(content)
self._writer.characters(content, 0, len(content))
def end(self, name, newline=True):
self._writer.endElement('', '', name)
if newline:
self.content('\n')
def close(self):
self._writer.endDocument()
self._output.close()
self.closed = True
示例4: extractZip
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [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))
示例5: retrieve_an_archive
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [as 别名]
def retrieve_an_archive(cust_id, archive_name, user_id, chunk_hint, file_name, output_ids):
print "\nretrieve_a_chunk routine:: output file_name is :", file_name
try:
outfile_stream = FileOutputStream(file_name)
except:
print "retrieve_a_chunk routine:: Failed to open output stream on file : ", file_name, "..returning"
return None
# retrieve data
mc = ManagementContainer.getInstance()
rm = mc.getRecoveryManager()
l_cust_id = Integer.parseInt(cust_id);
l_user_id = Integer.parseInt(user_id);
sosw = IRecoveryManager.SimpleOutputStreamWrapper(outfile_stream)
try:
rm.createPerUserActiveRecoveryArchiveFile(l_cust_id, archive_name, l_user_id, sosw, chunk_hint)
except:
print "retrieve_a_chunk routine:: `Exception while creating active recovery archive..returning"
sys.exc_info()[1].printStackTrace()
print("*** print_exc:")
traceback.print_exc(file=sys.stdout)
outfile_stream.close()
raise
outfile_stream.close()
return get_chunk_hint(file_name, output_ids)
示例6: getMsgRaw
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [as 别名]
def getMsgRaw(fileName, rs):
msgID = rs.getLong(1)
size = rs.getInt(2)
storageLocation = StoredMessage.stripOldStorageDir(rs.getString(3))
custID = rs.getInt(4)
ts = rs.getTimestamp(5)
receivedDate = None
if ts is not None:
receivedDate = Date(ts.getTime)
msg = StoredMessage(custID, msgID, storageLocation, None, None, receivedDate, 0, 0, 0, 0, None, amPartId, size, size, None, None)
if msg:
# do some validation
if long(msgId) != msg.getMessageId():
printQueue.append("consumer: ERROR: message ID " + str(msgId) + " not the same as " + str(msg.getMessageId()))
#print "found message", msgId, "in DB for AM partition"
msgStream = msg.getEncryptedCompressedContentStream()
if msgStream:
out = FileOutputStream(fileName)
FileUtils.copyStream(msg.getEncryptedCompressedContentStream(), out)
out.flush()
out.close()
#print "found message", msgId, "on disk in AM partition"
return True
else:
printErrorToRemigrate(msgId, " not found on disk for AM partition.")
return False
else:
printErrorToRemigrate(msgId, " not found in db for AM partition.")
return False
示例7: __getFile
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [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
示例8: replaceDocumentSummary
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [as 别名]
def replaceDocumentSummary(self, ole2filename, blank=False):
fin = FileInputStream(ole2filename)
fs = NPOIFSFileSystem(fin)
root = fs.getRoot()
si = False
siFound = False
for obj in root:
x = obj.getShortDescription()
if x == (u"\u0005" + "DocumentSummaryInformation"):
siFound=True
if blank == False:
test = root.getEntry((u"\u0005" + "DocumentSummaryInformation"))
dis = DocumentInputStream(test);
ps = PropertySet(dis);
try:
si = DocumentSummaryInformation(ps)
except UnexpectedPropertySetTypeException as e:
sys.stderr.write("Error writing old DocumentSymmaryInformation:" + str(e).replace('org.apache.poi.hpsf.UnexpectedPropertySetTypeException:',''))
sys.exit(1)
if blank == False and siFound == True:
si.write(root, (u"\u0005" + "DocumentSummaryInformation"))
else:
ps = PropertySetFactory.newDocumentSummaryInformation()
ps.write(root, (u"\u0005" + "DocumentSummaryInformation"));
out = FileOutputStream(ole2filename);
fs.writeFilesystem(out);
out.close();
示例9: replaceSummaryInfo
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [as 别名]
def replaceSummaryInfo(self, ole2filename, blank=False):
fin = FileInputStream(ole2filename)
fs = NPOIFSFileSystem(fin)
root = fs.getRoot()
si = False
siFound = False
for obj in root:
x = obj.getShortDescription()
if x == (u"\u0005" + "SummaryInformation"):
siFound = True
if blank == False:
test = root.getEntry((u"\u0005" + "SummaryInformation"))
dis = DocumentInputStream(test);
ps = PropertySet(dis);
#https://poi.apache.org/apidocs/org/apache/poi/hpsf/SummaryInformation.html
si = SummaryInformation(ps);
if blank == False and siFound == True:
si.write(root, (u"\u0005" + "SummaryInformation"))
else:
ps = PropertySetFactory.newSummaryInformation()
ps.write(root, (u"\u0005" + "SummaryInformation"));
out = FileOutputStream(ole2filename);
fs.writeFilesystem(out);
out.close();
示例10: exportAll
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [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
示例11: save_versions
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [as 别名]
def save_versions(self):
print "save versions"
versionsProperties = Properties()
outFile = FileOutputStream(self.versionsFileName)
versionsProperties.setProperty("script", self.app.SCRIPTVERSION)
versionsProperties.setProperty("tools", self.app.TOOLSVERSION)
versionsProperties.store(outFile, None)
outFile.close()
示例12: save_example
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [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()
示例13: save_config
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [as 别名]
def save_config(self):
"""Save preferences to config file
"""
out = FileOutputStream(app.configFileName)
app.properties.store(out, None)
out.close()
#load new preferences
self.config = ConfigLoader(self)
示例14: run
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [as 别名]
def run(self):
while 1:
print "Writing out channels", Date()
ostream = FileOutputStream(self.filename)
p = ObjectOutputStream(ostream)
p.writeObject(self.registry.getChannelGroup("Default"))
p.flush()
ostream.close()
self.sleep(self.delay)
示例15: writeToFile
# 需要导入模块: from java.io import FileOutputStream [as 别名]
# 或者: from java.io.FileOutputStream import close [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()