本文整理汇总了Python中java.io.FileInputStream类的典型用法代码示例。如果您正苦于以下问题:Python FileInputStream类的具体用法?Python FileInputStream怎么用?Python FileInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: transformReport
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: process
def process(self):
'''Read the XML file and map xpath items to metadata
Return a list with 1 JsonSimple object (at most)
'''
jsonList = []
data = None
reader = None
inStream = None
document = None
# Run the XML through our parser
try:
inStream = FileInputStream(File(self.file))
reader = InputStreamReader(inStream, "UTF-8")
document = self.saxReader.read(reader)
# Parse fails
except:
raise
# Close our file access objects
finally:
if reader is not None:
reader.close()
if inStream is not None:
inStream.close()
# Now go looking for all our data
data = self.getNewJsonObject()
self.__mapXpathToFields(document, self.map, data)
if data is None:
return None
jsonList.append(JsonSimple(data))
return jsonList
示例3: process
def process(self):
#We'll return a list with 1 JsonSimple object
jsonList = []
data = None
reader = None
inStream = None
document = None
# Run the XML through our parser
try:
inStream = FileInputStream(File(self.file))
reader = InputStreamReader(inStream, "UTF-8")
document = self.saxReader.read(reader)
# Parse fails
except:
raise
# Close our file access objects
finally:
if reader is not None:
reader.close()
if inStream is not None:
inStream.close()
# Now go looking for all our data
data = JsonObject()
data.put("workflow_source", "XML Alert") # Default
self.__mapXpathToFields(document, self.map, data)
if data is None:
return None
jsonList.append(JsonSimple(data))
return jsonList
示例4: addPropertiesFromFile
def addPropertiesFromFile(props, filename, site_home):
addProps = Properties()
input = FileInputStream(filename)
addProps.load(input)
input.close()
baseFileList = addProps.getProperty('base')
if not baseFileList is None:
baseFiles = baseFileList.split(",")
for baseFile in baseFiles:
baseFileResolved=getBaseFile(baseFile, site_home)
if baseFileResolved=='':
log.error('Configuration inherits from properties file that does not exist: ' + baseFile)
log.info('Suggested Fix: Update the base property within ' + filename + ' to the correct file path')
sys.exit()
log.debug('Attempting to load properties from ' + baseFile)
addPropertiesFromFile(addProps, baseFileResolved, site_home)
addProps.remove('base')
enum = addProps.keys()
while enum.hasMoreElements():
key = enum.nextElement()
if props.getProperty(key) is None:
props.setProperty(key, addProps.getProperty(key))
addDataLinage(key,filename,addProps.getProperty(key))
示例5: read_versions
def read_versions(self):
versionsProperties = Properties()
fin = FileInputStream(self.versionsFileName)
versionsProperties.load(fin)
scriptVersion = versionsProperties.getProperty("script")
toolsVersion = versionsProperties.getProperty("tools")
fin.close()
return scriptVersion, toolsVersion
示例6: load_redback_registry
def load_redback_registry():
reg = Properties()
reg_file = 'redback.properties'
if os.path.isfile(reg_file):
reg_fd = FileInputStream(reg_file)
reg.load(reg_fd)
reg_fd.close()
return reg
示例7: loadProperties
def loadProperties(fileName):
properties = Properties()
input = FileInputStream(fileName)
properties.load(input)
input.close()
result= {}
for entry in properties.entrySet(): result[entry.key] = entry.value
return result
示例8: getPushProperties
def getPushProperties():
pushProperties = HashMap()
pushPropertiesFileStr = "%s%s%s" % (adapterConfigBaseDir, FILE_SEPARATOR, PUSH_PROPERTIES_FILE)
properties = Properties()
debugMode = 0
sortCSVFields = ""
smartUpdateIgnoreFields = ""
testConnNameSpace = "BMC.CORE"
testConnClass = "BMC_ComputerSystem"
try:
logger.debug("Checking push properties file for debugMode [%s]" % pushPropertiesFileStr)
fileInputStream = FileInputStream(pushPropertiesFileStr)
properties.load(fileInputStream)
# Property: debugMode
try:
debugModeStr = properties.getProperty("debugMode")
if isNoneOrEmpty(debugModeStr) or string.lower(string.strip(debugModeStr)) == 'false':
debugMode = 0
elif string.lower(string.strip(debugModeStr)) == 'true':
debugMode = 1
except:
logger.debugException("Unable to read debugMode property from push.properties")
if debugMode:
logger.debug("Debug mode = TRUE. XML data pushed to Remedy/Atrium will be persisted in the directory: %s" % adapterResBaseDir)
else:
logger.debug("Debug mode = FALSE")
# Property: smartUpdateIgnoreFields
try:
smartUpdateIgnoreFields = properties.getProperty("smartUpdateIgnoreFields")
except:
logger.debugException("Unable to read smartUpdateIgnoreFields property from push.properties")
# Property: sortCSVFields
try:
sortCSVFields = properties.getProperty("sortCSVFields")
except:
logger.debugException("Unable to read sortCSVFields property from push.properties")
# Property: testConnNameSpace
try:
testConnNameSpace = properties.getProperty("testConnNameSpace")
except:
logger.debugException("Unable to read testConnNameSpace property from push.properties")
# Property: testConnClass
try:
testConnClass = properties.getProperty("testConnClass")
except:
logger.debugException("Unable to read testConnClass property from push.properties")
fileInputStream.close()
except:
logger.debugException("Unable to process %s file." % PUSH_PROPERTIES_FILE)
return debugMode, smartUpdateIgnoreFields, sortCSVFields, testConnNameSpace, testConnClass
示例9: readBinaryFile
def readBinaryFile(cls, rootFile):
""" generated source for method readBinaryFile """
in_ = FileInputStream(rootFile)
out = ByteArrayOutputStream()
# Transfer bytes from in to out
buf = [None]*1024
while in_.read(buf) > 0:
out.write(buf)
in_.close()
return out.toByteArray()
示例10: read_tools_list
def read_tools_list(tmpToolsListFile):
"""Read the tools names and tools data urls
from the downlaoded tools list
"""
properties = Properties()
fin = FileInputStream(tmpToolsListFile)
properties.load(fin)
toolsRefs = properties.getProperty("tools.list").split("|")
fin.close()
return toolsRefs
示例11: loadPropertiesFromFile
def loadPropertiesFromFile(filename,props):
newprops=Properties()
inputstr = FileInputStream(filename)
newprops.load(inputstr)
inputstr.close()
enum = newprops.keys()
while enum.hasMoreElements():
key = enum.nextElement()
if props.getProperty(key) is None:
props.setProperty(key, newprops.getProperty(key))
return props
示例12: test_read_file
def test_read_file(self):
from java.io import FileInputStream
from java.lang import String
filename = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'data/read_file.txt')
fin = FileInputStream(filename)
ar = jarray(20, JBYTE_ID)
count = fin.read(ar)
s = String(ar, 0, count)
self.assertEqual(str(s).strip(), 'aewrv3v')
示例13: run
def run():
versionFile = File(os.getcwd(), 'core/resources/version.properties')
log.debug('Checking if ' + str(versionFile) + ' exists')
if os.path.exists(str(versionFile)):
versionProperties = Properties()
input = FileInputStream(versionFile)
versionProperties.load(input)
input.close()
versionInfo=getVersionInfo(versionProperties)
else:
versionInfo=getVersionInfo(None)
log.info('this')
log.info(versionInfo)
示例14: addFile
def addFile(self, file, parentDirName=None):
buffer = jarray.zeros(self._bufsize, 'b')
inputStream = FileInputStream(file)
jarEntryName = file.getName()
if parentDirName:
jarEntryName = parentDirName + "/" + jarEntryName
self.getJarOutputStream().putNextEntry(JarEntry(jarEntryName))
read = inputStream.read(buffer)
while read <> -1:
self.getJarOutputStream().write(buffer, 0, read)
read = inputStream.read(buffer)
self.getJarOutputStream().closeEntry()
inputStream.close()
示例15: write
def write(self, name, file):
fp = self.getFile(name)
if isinstance(file, ByteArrayOutputStream):
file.writeTo(fp)
else:
if isinstance(file, type('')):
file = FileInputStream(file)
data = jarray.zeros(1024*4, 'b')
#print 'writing', file,
while 1:
n = file.read(data)
#print n,
if n == -1: break
fp.write(data, 0, n)