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


Java FileReadChannel.close方法代码示例

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


在下文中一共展示了FileReadChannel.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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


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