当前位置: 首页>>代码示例>>Python>>正文


Python FileInputStream.getChannel方法代码示例

本文整理汇总了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)
开发者ID:lfiaschi,项目名称:fiji,代码行数:26,代码来源:iconv.py

示例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
开发者ID:exponential-decay,项目名称:ole2-re-combiner,代码行数:38,代码来源:JHandleOLE2Containers.py


注:本文中的java.io.FileInputStream.getChannel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。