本文整理汇总了Python中java.io.FileOutputStream类的典型用法代码示例。如果您正苦于以下问题:Python FileOutputStream类的具体用法?Python FileOutputStream怎么用?Python FileOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveHM
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: retrieve_an_archive
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)
示例3: replaceDocumentSummary
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();
示例4: replaceSummaryInfo
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();
示例5: getMsgRaw
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
示例6: extractZip
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))
示例7: __getFile
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: XmlWriter
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
示例9: transformReport
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()
示例10: save_config
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)
示例11: save_versions
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: run
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)
示例13: writeToFile
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()
示例14: dump
def dump(obj,file):
x = Xmlizer()
xdoc = XmlDocument()
xe = x.toXml(obj,xdoc)
xdoc.appendChild(xe)
#
fos = FileOutputStream(file)
xdoc.write(fos)
fos.close()
示例15: make_icns
def make_icns(icns):
icons = IconSuite()
icons.setSmallIcon(generate_image(16, 16))
icons.setLargeIcon(generate_image(32, 32))
icons.setHugeIcon(generate_image(48, 48))
icons.setThumbnailIcon(generate_image(128, 128))
codec = IcnsCodec()
out = FileOutputStream(icns)
codec.encode(icons, out)
out.close()