本文整理汇总了Python中java.io.FileInputStream.getChannel方法的典型用法代码示例。如果您正苦于以下问题:Python FileInputStream.getChannel方法的具体用法?Python FileInputStream.getChannel怎么用?Python FileInputStream.getChannel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.FileInputStream
的用法示例。
在下文中一共展示了FileInputStream.getChannel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: iconv
# 需要导入模块: from java.io import FileInputStream [as 别名]
# 或者: from java.io.FileInputStream import getChannel [as 别名]
def iconv(file):
print 'Converting', file
f = File(file)
if not f.exists():
print file, 'does not exist'
sys.exit(1)
buffer = ByteBuffer.allocate(f.length() * 2)
input = FileInputStream(f)
input.getChannel().read(buffer)
buffer.limit(buffer.position())
buffer.position(0)
if buffer.limit() != f.length():
print file, 'could not be read completely'
sys.exit(1)
input.close()
buffer = encoder.encode(decoder.decode(buffer))
buffer.position(0)
output = FileOutputStream(file + '.cnv')
if output.getChannel().write(buffer) != buffer.limit():
print file, 'could not be reencoded'
sys.exit(1)
output.close()
f.delete()
File(file + '.cnv').renameTo(f)
示例2: writeContainer
# 需要导入模块: from java.io import FileInputStream [as 别名]
# 或者: from java.io.FileInputStream import getChannel [as 别名]
def writeContainer(self, containerfoldername, ext, outputfilename=False):
written = False
if outputfilename == False:
outputfilename = containerfoldername.strip('/') + "-" + uniqid.uniqid() + "." + ext.strip('.')
containerfoldername = containerfoldername
#we have folder name, written earlier
#foldername is filename!!
if os.path.isdir(containerfoldername):
fname = outputfilename
fs = NPOIFSFileSystem()
root = fs.getRoot();
#triplet ([Folder], [sub-dirs], [files])
for folder, subs, files in os.walk(containerfoldername):
if subs != []:
#TODO: cant't yet write directories
break
else:
for f in files:
fin = FileInputStream(folder + '/' + f)
if fin.getChannel().size() == 0:
fin.close()
written = False
break
else:
root.createDocument(f, fin)
fin.close()
written = True
else:
sys.exit("Not a valid folder: " + containerfoldername)
if written == True:
fos = FileOutputStream(fname)
fs.writeFilesystem(fos);
fs.close()
return written