• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FileReadChannel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.appengine.api.files.FileReadChannel的典型用法代码示例。如果您正苦于以下问题:Java FileReadChannel类的具体用法?Java FileReadChannel怎么用?Java FileReadChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FileReadChannel类属于com.google.appengine.api.files包,在下文中一共展示了FileReadChannel类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: slurp

import com.google.appengine.api.files.FileReadChannel; //导入依赖的package包/类
private static byte[] slurp(BlobKey blobKey) throws IOException {
  FileReadChannel in = getFileService().openReadChannel(
      new AppEngineFile(AppEngineFile.FileSystem.BLOBSTORE, blobKey.getKeyString()), 
      false);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  ByteBuffer buf = ByteBuffer.allocate(BUFFER_BYTES);
  while (true) {
    int bytesRead = in.read(buf);
    if (bytesRead < 0) {
      break;
    }
    Preconditions.checkState(bytesRead != 0, "0 bytes read: %s", buf);
    out.write(buf.array(), 0, bytesRead);
    buf.clear();
  }
  return out.toByteArray();
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:18,代码来源:OversizedPropertyMover.java


示例2: loadSchemaStr

import com.google.appengine.api.files.FileReadChannel; //导入依赖的package包/类
public static String loadSchemaStr(String schemaFileName)
		throws FileNotFoundException, LockException, IOException {
	FileService fileService = FileServiceFactory.getFileService();
	AppEngineFile schemaFile = new AppEngineFile(schemaFileName);
	FileReadChannel readChannel = fileService.openReadChannel(schemaFile, false);
	BufferedReader reader = new BufferedReader(Channels.newReader(readChannel, "UTF8"));
	String schemaLine;
	try {
		schemaLine = reader.readLine().trim();
	} catch (NullPointerException npe) {
		throw new IOException("Encountered NPE reading " + schemaFileName);
	}
	reader.close();
	readChannel.close();
	return schemaLine;
}
 
开发者ID:steveseo,项目名称:l2bq,代码行数:17,代码来源:AnalysisUtility.java


示例3: slurp

import com.google.appengine.api.files.FileReadChannel; //导入依赖的package包/类
private static byte[] slurp(AppEngineFile file) throws IOException {
  FileReadChannel in = getFileService().openReadChannel(file, false);
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  ByteBuffer buf = ByteBuffer.allocate(BUFFER_BYTES);
  while (true) {
    buf.clear();
    int bytesRead = in.read(buf);
    if (bytesRead < 0) {
      break;
    }
    out.write(buf.array(), 0, bytesRead);
  }
  return out.toByteArray();
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:15,代码来源:FetchAttachmentsProcessor.java


示例4: getFileContent

import com.google.appengine.api.files.FileReadChannel; //导入依赖的package包/类
/**
 * Returns the content of the specified file
 * @param fileMetaData file meta data of the file
 * @param fileService  optionally you can pass the file service reference if you already have it
 * @return the content of the specified file or <code>null</code> if the file could not be found
 * @throws IOException thrown if reading the file from from the Blobstore fails
 */
public static byte[] getFileContent( final FileMetaData fileMetaData, FileService fileService ) throws IOException {
	if (true) {
		return null;
	}
	
	if ( fileMetaData.getContent() != null ) {
		// File content is in the file meta data
		return fileMetaData.getContent().getBytes();
	}
	else {
		// Get content from the Blobstore
		if ( fileService == null )
			fileService = FileServiceFactory.getFileService();
		
		// final AppEngineFile   appeFile = fileService.getBlobFile( file.getBlobKey() ); // This code throws exception on migrated blobs!
		final AppEngineFile   appeFile = new AppEngineFile( FileSystem.BLOBSTORE, fileMetaData.getBlobKey().getKeyString() );
		final FileReadChannel channel  = fileService.openReadChannel( appeFile, false );
		final byte[]          content  = new byte[ (int) fileMetaData.getSize() ];
		final ByteBuffer      wrapper  = ByteBuffer.wrap( content );
		
		while ( channel.read( wrapper ) > 0 )
			;
		
		channel.close();
		
		return content;
	}
}
 
开发者ID:icza,项目名称:sc2gears,代码行数:36,代码来源:ServerUtils.java


示例5: getStringFromChannel

import com.google.appengine.api.files.FileReadChannel; //导入依赖的package包/类
private String getStringFromChannel(FileReadChannel channel, int length) throws IOException {
    ByteBuffer buffer = ByteBuffer.allocate(length);
    int bytesRead = channel.read(buffer);

    byte[] bytes = new byte[bytesRead == -1 ? 0 : bytesRead];
    buffer.flip();
    buffer.get(bytes);

    return new String(bytes);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:11,代码来源:BlobstoreUploadTestBase.java


示例6: customTask

import com.google.appengine.api.files.FileReadChannel; //导入依赖的package包/类
private void customTask( final HttpServletRequest request, final PersistenceManager pm ) throws IOException {
	LOGGER.fine( "Key: " + request.getParameter( "key" ) + ", file type: " + request.getParameter( "fileType" ) );
	
	final FileType fileType = FileType.fromString( request.getParameter( "fileType" ) );
	if ( fileType == null ) {
		LOGGER.severe( "Invalid File type!" );
		return;
	}
	
	final Key key = KeyFactory.stringToKey( request.getParameter( "key" ) );
	
	final DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
       final Entity e;
	try {
        e = ds.get( key );
       } catch ( final EntityNotFoundException enfe ) {
		LOGGER.log( Level.WARNING, "Entity not found!", enfe );
        return;
       }
	
       if ( !e.getKind().equals( "Rep" ) && !e.getKind().equals( "Smpd" ) && !e.getKind().equals( "OtherFile" ) ) {
		LOGGER.severe( "Invalid Entity kind:" + e.getKind() );
		return;
       }
       
       if ( (Long) e.getProperty( "v" ) == 4 ) {
		LOGGER.warning( "Entity is already v4!" );
		return;
	}
       
       // Update common properties:
       // TODO
       final int size = ( (Long) e.getProperty( "size" ) ).intValue();
       if ( size < FileServlet.DATASTORE_CONTENT_STORE_LIMIT ) {
           final FileService fileService = FileServiceFactory.getFileService();
   		final AppEngineFile   appeFile = new AppEngineFile( FileSystem.BLOBSTORE, ( (BlobKey) e.getProperty( "blobKey" ) ).getKeyString() );
   		final FileReadChannel channel  = fileService.openReadChannel( appeFile, false );
   		final byte[]          content  = new byte[ size ];
   		final ByteBuffer      wrapper  = ByteBuffer.wrap( content );
   		while ( channel.read( wrapper ) > 0 )
   			;
   		channel.close();
   		
   		e.setProperty( "content", new Blob( content ) );
   		e.setProperty( "blobKey", null );
   		fileService.delete( appeFile );
       }
       e.setUnindexedProperty( "blobKey", e.getProperty( "blobKey" ) );
       e.setUnindexedProperty( "content", e.getProperty( "content" ) );
       
       switch ( fileType ) {
       case SC2REPLAY :
           e.setUnindexedProperty( "matchup", e.getProperty( "matchup" ) );
       	break;
       case MOUSE_PRINT :
       	break;
       case OTHER :
       	break;
       default:
       	throw new RuntimeException( "Invalid file type!" );
       }
       
       // UPGRADE COMPLETE!
	e.setProperty( "v", 4 );
	ds.put( e );
}
 
开发者ID:icza,项目名称:sc2gears,代码行数:67,代码来源:TaskServlet.java


示例7: getFileContents

import com.google.appengine.api.files.FileReadChannel; //导入依赖的package包/类
private String getFileContents(AppEngineFile file) throws IOException {
    try (FileReadChannel channel = FileServiceFactory.getFileService().openReadChannel(file, true)) {
        return getStringFromChannel(channel, 1000);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:6,代码来源:BlobstoreUploadTestBase.java


示例8: getInputStream

import com.google.appengine.api.files.FileReadChannel; //导入依赖的package包/类
public InputStream getInputStream() throws IOException {
  if (file == null)
    return null;
  FileReadChannel channel = fileService.openReadChannel(file, false);
  return Channels.newInputStream(channel);
}
 
开发者ID:mwl,项目名称:gwt-upload,代码行数:7,代码来源:FilesApiFileItemFactory.java



注:本文中的com.google.appengine.api.files.FileReadChannel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IncomingOperationType类代码示例发布时间:2022-05-22
下一篇:
Java AuthenticationHandler类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap