本文整理汇总了Java中com.google.appengine.api.files.FileServiceFactory.getFileService方法的典型用法代码示例。如果您正苦于以下问题:Java FileServiceFactory.getFileService方法的具体用法?Java FileServiceFactory.getFileService怎么用?Java FileServiceFactory.getFileService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.appengine.api.files.FileServiceFactory
的用法示例。
在下文中一共展示了FileServiceFactory.getFileService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadSchemaStr
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的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: doGet
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
try {
System.out.println(newFileName());
FileService fileService = FileServiceFactory.getFileService();
GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder()
.setBucket("wt1-test1")
.setKey(newFileName());
AppEngineFile aef = fileService.createNewGSFile(optionsBuilder.build());
FileWriteChannel ch = fileService.openWriteChannel(aef, true);
Channels.newWriter(ch, "utf8").append("pouet").flush();
ch.closeFinally();
System.out.println("SUCCESS **************");
} catch (Exception e) {
System.out.println("FAILURE **************************");
e.printStackTrace();
}
}
示例3: getFileContent
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的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;
}
}
示例4: processFileWithContent
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的package包/类
private void processFileWithContent( final PersistenceManager pm, final Key fileKey, final String fileTypeString ) throws IOException {
LOGGER.fine( "File key: " + fileKey + ", file type: " + fileTypeString );
final FileType fileType = FileType.fromString( fileTypeString );
final FileMetaData fmd;
try {
fmd = (FileMetaData) pm.getObjectById( FILE_TYPE_CLASS_MAP.get( fileType ), fileKey );
} catch ( final JDOObjectNotFoundException jonfe ) {
LOGGER.warning( "File not found! (Deleted?)" );
return;
}
LOGGER.fine( "sha1: " + fmd.getSha1() );
if ( fmd.getBlobKey() != null && fmd.getContent() == null ) {
LOGGER.warning( "This file is already processed!" );
return;
}
if ( fmd.getContent() == null ) {
LOGGER.warning( "File does not have content!" );
return;
}
// Store content in the Blobstore
final FileService fileService = FileServiceFactory.getFileService();
final AppEngineFile appeFile = fileService.createNewBlobFile( FILE_TYPE_MIME_TYPE_MAP.get( fileType ), fmd.getSha1() );
final FileWriteChannel channel = fileService.openWriteChannel( appeFile, true );
final ByteBuffer bb = ByteBuffer.wrap( fmd.getContent().getBytes() );
while ( bb.hasRemaining() )
channel.write( bb );
channel.closeFinally();
fmd.setBlobKey( fileService.getBlobKey( appeFile ) );
fmd.setContent( null );
// I do not catch exceptions (so the task will be retried)
}
示例5: service
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的package包/类
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
log.info("Ping - " + req);
if (requestHandler != null) {
requestHandler.handleRequest(req);
}
lastRequest = req;
final DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
try {
Entity entity = new Entity("Qwert");
entity.setProperty("xyz", 123);
Key key = ds.put(entity);
entity = ds.get(key);
log.info(entity.toString());
FileService fs = FileServiceFactory.getFileService();
AppEngineFile file = fs.createNewBlobFile("qwertfile");
FileWriteChannel fwc = fs.openWriteChannel(file, false);
try {
log.info("b_l = " + fwc.write(ByteBuffer.wrap("qwert".getBytes())));
} finally {
fwc.close();
}
} catch (Exception e) {
throw new IOException(e);
}
}
示例6: setUp
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile("image/png");
FileWriteChannel channel = fileService.openWriteChannel(file, true);
try {
try (ReadableByteChannel in = Channels.newChannel(getImageStream("capedwarf.png"))) {
copy(in, channel);
}
} finally {
channel.closeFinally();
}
blobKey = fileService.getBlobKey(file);
}
示例7: writeNewBlobFile
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的package包/类
protected BlobKey writeNewBlobFile(String text) throws IOException {
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile("text/plain", "uploadedText.txt");
FileWriteChannel channel = fileService.openWriteChannel(file, true);
try {
channel.write(ByteBuffer.wrap(text.getBytes()));
} finally {
channel.closeFinally();
}
return fileService.getBlobKey(file);
}
示例8: writeToFile
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的package包/类
private static BlobKey writeToFile(Image image) throws IOException {
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile(toMimeType(image.getFormat()));
FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
writeChannel.write(ByteBuffer.wrap(image.getImageData()));
writeChannel.closeFinally();
return fileService.getBlobKey(file);
}
示例9: getFileService
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的package包/类
public static FileService getFileService() {
return FileServiceFactory.getFileService();
}
示例10: getFileService
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的package包/类
private static FileService getFileService() {
return FileServiceFactory.getFileService();
}
示例11: customTask
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的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 );
}
示例12: storeBlob
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的package包/类
private BlobKey storeBlob(String contentType, String fileName, InputStream stream) throws IOException {
FileService fileService = FileServiceFactory.getFileService();
AppEngineFile file = fileService.createNewBlobFile(contentType, fileName);
boolean lock = true;
FileWriteChannel writeChannel = fileService.openWriteChannel(file, lock);
ByteBuffer buf = ByteBuffer.allocateDirect(10);
byte[] bytes = new byte[1024];
int count = 0;
int index = 0;
// Continue writing bytes until there are no more
while (count >= 0) {
if (index == count) {
count = stream.read(bytes);
index = 0;
}
// Fill ByteBuffer
while (index < count && buf.hasRemaining()) {
buf.put(bytes[index++]);
}
// Set the limit to the current position and the
// position to 0
// making the new bytes visible for write()
buf.flip();
// Write the bytes to the channel
int numWritten = writeChannel.write(buf);
// Check if all bytes were written
if (buf.hasRemaining()) {
buf.compact();
} else {
buf.clear();
}
}
writeChannel.closeFinally();
return fileService.getBlobKey(file);
}
示例13: doGet
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
AppIdentityCredential credential = new AppIdentityCredential(AnalysisConstants.SCOPES);
String bigqueryProjectId = AnalysisUtility.extractParameterOrThrow(req, AnalysisConstants.BIGQUERY_PROJECT_ID_PARAM);
String jobId = AnalysisUtility.extractParameterOrThrow(req, AnalysisConstants.BIGQUERY_JOB_ID_PARAM);
String queueName = AnalysisUtility.extractParameterOrThrow(req, AnalysisConstants.QUEUE_NAME_PARAM);
Bigquery bigquery = Bigquery.builder(HTTP_TRANSPORT, JSON_FACTORY)
.setHttpRequestInitializer(credential)
.setApplicationName("Streak Logs")
.build();
Job j = bigquery.jobs().get(bigqueryProjectId, jobId).execute();
j.getConfiguration().getLoad().getSourceUris();
if ("DONE".equals(j.getStatus().getState())) {
FileService fs = FileServiceFactory.getFileService();
List<AppEngineFile> filesForJob = new ArrayList<AppEngineFile>();
for (String f : j.getConfiguration().getLoad().getSourceUris()) {
if (f.contains("gs://")) {
String filename = f.replace("gs://", "/gs/");
AppEngineFile file = new AppEngineFile(filename);
filesForJob.add(file);
resp.getWriter().println("Deleting: " + f + ", appengine filename: " + filename);
}
}
fs.delete(filesForJob.toArray(new AppEngineFile[0]));
}
else {
resp.getWriter().println("Status was not DONE, it was " + j.getStatus().getState());
// check again in 5 mins if the job is done
String retryCountStr = req.getParameter(AnalysisConstants.RETRY_COUNT_PARAM);
int retryCount = -1;
if (AnalysisUtility.areParametersValid(retryCountStr)) {
retryCount = Integer.parseInt(retryCountStr);
}
retryCount++;
if (retryCount > 15) {
resp.getWriter().println("Tried too many times to find job, aborting");
}
Queue taskQueue = QueueFactory.getQueue(queueName);
taskQueue.add(
Builder.withUrl(
AnalysisUtility.getRequestBaseName(req) + "/deleteCompletedCloudStorageFilesTask")
.method(Method.GET)
.param(AnalysisConstants.BIGQUERY_JOB_ID_PARAM, jobId)
.param(AnalysisConstants.QUEUE_NAME_PARAM, queueName)
.param(AnalysisConstants.RETRY_COUNT_PARAM, String.valueOf(retryCount))
.etaMillis(System.currentTimeMillis() + 5 * 60 * 1000)
.param(AnalysisConstants.BIGQUERY_PROJECT_ID_PARAM, bigqueryProjectId));
}
}
示例14: getAppEngineFile
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的package包/类
private AppEngineFile getAppEngineFile(BlobKey blobKey) {
FileService fileService = FileServiceFactory.getFileService();
return fileService.getBlobFile(blobKey);
}
示例15: structureFileAndPostToDb
import com.google.appengine.api.files.FileServiceFactory; //导入方法依赖的package包/类
/**
* @return
* @throws IOException
*/
private boolean structureFileAndPostToDb() throws IOException {
/* Define the File API specific instances */
BlobstoreService blobStoreService = BlobstoreServiceFactory.getBlobstoreService();
FileService fileService = FileServiceFactory.getFileService();
/* */
final AppEngineFile blobFile = fileService.createNewBlobFile(dataWhole.getMimeType(), dataWhole.getFileName());
/* */
final FileWriteChannel writeChannel = fileService.openWriteChannel(blobFile, true);
/* */
Boolean transaction = ofy().transact(new Work<Boolean>() {
@Override
public Boolean run() {
dataPieces = ofy().load().keys(dataWhole.getDataPieceKeyList());
return dataPieces.size() > 0 ? true : false;
}
});
if (transaction) {
int length;
byte[] buffer = new byte[1024000];
for (int i = 1; i <= dataPieces.size(); i++) {
Key<DataPiece> pieceKey = Key.create(Key.create(DataWhole.class, dataWhole.getKey()), DataPiece.class,
dataWhole.getKey() + i);
DataPiece dataPiece = dataPieces.get(pieceKey);
logger.log(Level.INFO, "DataPiece Blobkey is " + dataPiece.getBlobKey());
BlobstoreInputStream blobStream = new BlobstoreInputStream(dataPiece.getBlobKey());
while ((length = blobStream.read(buffer)) != -1) {
writeChannel.write(ByteBuffer.wrap(buffer, 0, length));
}
blobStream.close();
blobStoreService.delete(dataPiece.getBlobKey());
}
writeChannel.closeFinally();
dataWhole.setBlobKey(fileService.getBlobKey(blobFile));
logger.log(Level.INFO, "New Blobkey is " + fileService.getBlobKey(blobFile));
/* Remove the pieces once it has been successfully restructured */
for (DataPiece piece : dataPieces.values()) {
blobStoreService.delete(piece.getBlobKey());
}
Boolean dwTransaction = ofy().transact(new Work<Boolean>() {
@Override
public Boolean run() {
/* Persist the modified DataWhole */
dataWhole.setDataPieceKeyList(new ArrayList<Key<DataPiece>>());
ofy().save().entity(dataWhole).now();
/* Remove the DataWhole's children */
ofy().delete().entities(dataPieces.values()).now();
return true;
}
});
return dwTransaction;
}
return false;
}