本文整理汇总了Python中java.io.FileInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Python FileInputStream.read方法的具体用法?Python FileInputStream.read怎么用?Python FileInputStream.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.FileInputStream
的用法示例。
在下文中一共展示了FileInputStream.read方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addFile
# 需要导入模块: from java.io import FileInputStream [as 别名]
# 或者: from java.io.FileInputStream import read [as 别名]
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()
示例2: compareFileHashes
# 需要导入模块: from java.io import FileInputStream [as 别名]
# 或者: from java.io.FileInputStream import read [as 别名]
def compareFileHashes(dxFileName, amFileName, msgId):
dxFile = FileInputStream(dxFileName)
dxMsgContentHash = sha.new(str(dxFile.read()))
dxFile.close()
amFile = FileInputStream(amFileName)
amMsgContentHash = sha.new(str(amFile.read()))
amFile.close()
if dxMsgContentHash.digest() == amMsgContentHash.digest():
#print "message has same hash on AM partition and DX", msgId
printQueue.append("output message " + str(msgId) + " is present in DX")
return True
else:
printErrorToRemigrate(msgId, " content hash differ on AM partition and DX. dx hash: " + dxMsgContentHash.hexdigest() + " am hash: " + amMsgContentHash.hexdigest())
return False
示例3: add_folder
# 需要导入模块: from java.io import FileInputStream [as 别名]
# 或者: from java.io.FileInputStream import read [as 别名]
def add_folder(zos, folder_name, base_folder_name):
f = File(folder_name)
if not f.exists():
return
if f.isDirectory():
for f2 in f.listFiles():
add_folder(zos, f2.absolutePath, base_folder_name)
return
entry_name = folder_name[len(base_folder_name) + 1:len(folder_name)]
ze = ZipEntry(entry_name)
zos.putNextEntry(ze)
input_stream = FileInputStream(folder_name)
buffer = zeros(1024, 'b')
rlen = input_stream.read(buffer)
while (rlen > 0):
zos.write(buffer, 0, rlen)
rlen = input_stream.read(buffer)
input_stream.close()
zos.closeEntry()
示例4: readBinaryFile
# 需要导入模块: from java.io import FileInputStream [as 别名]
# 或者: from java.io.FileInputStream import read [as 别名]
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()
示例5: test_read_file
# 需要导入模块: from java.io import FileInputStream [as 别名]
# 或者: from java.io.FileInputStream import read [as 别名]
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')
示例6: write
# 需要导入模块: from java.io import FileInputStream [as 别名]
# 或者: from java.io.FileInputStream import read [as 别名]
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)
示例7: __readBytes
# 需要导入模块: from java.io import FileInputStream [as 别名]
# 或者: from java.io.FileInputStream import read [as 别名]
def __readBytes(file):
# Returns the contents of the file in a byte array.
inputstream = FileInputStream(file)
# Get the size of the file
length = file.length()
# Create the byte array to hold the data
bytes = jarray.zeros(length, "b")
# Read in the bytes
offset = 0
numRead = 1
while (offset < length) and (numRead > 0):
numRead = inputstream.read(bytes, offset, len(bytes) - offset)
offset += numRead
# Ensure all the bytes have been read in
if offset < len(bytes):
log.warn("Could not read entire contents of '" + file.getName())
# Close the input stream and return bytes
inputstream.close()
return bytes
示例8: FileInputStream
# 需要导入模块: from java.io import FileInputStream [as 别名]
# 或者: from java.io.FileInputStream import read [as 别名]
try:
Integer.byteValue()
except:
print 'regression: no crash yet'
#raise TypeError, 'test'
print """
##################################################
# array handling
##################################################
"""
# just for fun
fin = FileInputStream("configure")
ar = jarray(20, JBYTE_ID)
count = fin.read(ar)
# strip any other lines, just want first
if(10 in ar):
count = ar.index(10)
ar = ar[0:count]
print 'configure starts ', String(ar, 0, count)
fin.close()
# array handling
ar = testo.getStringArray()
print 'string[] len: ', len(ar)
print '[0], [1], [2]: ', ar[0], ar[1], ar[2]
ar[0] = "new"
ar[1] = None
print '[0], [1]: ', ar[0], ar[1]