本文整理汇总了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;
}
示例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;
}
}
示例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 );
}