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


Java AppEngineFile类代码示例

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


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

示例1: slurp

import com.google.appengine.api.files.AppEngineFile; //导入依赖的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: dump

import com.google.appengine.api.files.AppEngineFile; //导入依赖的package包/类
private static AppEngineFile dump(@Nullable String mimeType, String downloadFilename,
    ByteBuffer bytes) throws IOException {
  bytes.rewind();
  AppEngineFile file = newBlob(mimeType, downloadFilename);
  FileWriteChannel out = getFileService().openWriteChannel(file, true);
  while (bytes.hasRemaining()) {
    out.write(bytes);
  }
  out.closeFinally();
  // Verify if what's in the file matches what we wanted to write -- the Files
  // API is still experimental and I've seen it misbehave.
  bytes.rewind();
  byte[] expected = getBytes(bytes);
  byte[] actual = slurp(file);
  if (!Arrays.equals(expected, actual)) {
    // These may be big log messages, but we need to log something that helps debugging.
    log.warning("Tried to write: " + prettyBytes(expected));
    log.warning("Bytes found in file: " + prettyBytes(actual));
    throw new IOException("File " + file + " does not contain the bytes we intended to write");
  }
  return file;
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:23,代码来源:FetchAttachmentsProcessor.java

示例3: writeSchema

import com.google.appengine.api.files.AppEngineFile; //导入依赖的package包/类
public static void writeSchema(FileService fileService, String bucketName, String schemaKey, List<String> fieldNames, List<String> fieldTypes) throws IOException,
FileNotFoundException, FinalizationException, LockException {
	GSFileOptionsBuilder schemaOptionsBuilder = new GSFileOptionsBuilder()
	.setBucket(bucketName)
	.setKey(schemaKey)
	.setAcl("project-private");
	AppEngineFile schemaFile = fileService.createNewGSFile(schemaOptionsBuilder.build());
	FileWriteChannel schemaChannel = fileService.openWriteChannel(schemaFile, true);
	PrintWriter schemaWriter = new PrintWriter(Channels.newWriter(schemaChannel, "UTF8"));
	StringBuilder sb = new StringBuilder();
	for (int i = 0; i < fieldNames.size(); i++) {
		sb.append(fieldNames.get(i) + ":" + fieldTypes.get(i));
		if (i < fieldNames.size() - 1) {
			sb.append(",");
		}
	}
	schemaWriter.print(sb);
	schemaWriter.close();
	schemaChannel.closeFinally();
}
 
开发者ID:steveseo,项目名称:l2bq,代码行数:21,代码来源:AnalysisUtility.java

示例4: loadSchemaStr

import com.google.appengine.api.files.AppEngineFile; //导入依赖的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

示例5: doGet

import com.google.appengine.api.files.AppEngineFile; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String mimeType = request.getParameter("mimeType");
    String contents = request.getParameter("contents");
    String blobRange = request.getParameter("blobRange");
    String name = request.getParameter("name");

    AppEngineFile file = service.createNewBlobFile(mimeType, name);
    writeToFile(file, contents);
    BlobKey blobKey = service.getBlobKey(file);

    response.addHeader("X-AppEngine-BlobKey", blobKey.getKeyString());
    if (blobRange != null) {
        response.addHeader("X-AppEngine-BlobRange", blobRange);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:17,代码来源:ServeBlobServlet.java

示例6: doGet

import com.google.appengine.api.files.AppEngineFile; //导入依赖的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();
	}
}
 
开发者ID:dataiku,项目名称:wt1,代码行数:23,代码来源:TestServlet.java

示例7: getBlobKey

import com.google.appengine.api.files.AppEngineFile; //导入依赖的package包/类
private BlobKey getBlobKey(final AppEngineFile finalizedBlobFile) 
    throws IOException {
  try {
    return new RetryHelper().run(
        new RetryHelper.Body<BlobKey>() {
          @Override public BlobKey run() throws RetryableFailure, PermanentFailure {
            // HACK(ohler): The file service incorrectly uses the current
            // transaction.  Make a dummy transaction as a workaround.
            // Apparently it even needs to be XG.
            CheckedTransaction tx = datastore.beginTransactionXG();
            try {
              BlobKey key = getFileService().getBlobKey(finalizedBlobFile);
              if (key == null) {
                // I have the impression that this can happen because of HRD's
                // eventual consistency.  Retry.
                throw new RetryableFailure(this + ": getBlobKey() returned null");
              }
              return key;
            } finally {
              tx.close();
            }
          }
        });
  } catch (PermanentFailure e) {
    throw new IOException("Failed to get blob key for " + finalizedBlobFile, e);
  }
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:28,代码来源:OversizedPropertyMover.java

示例8: dump

import com.google.appengine.api.files.AppEngineFile; //导入依赖的package包/类
private BlobKey dump(String fileDescription, byte[] bytes) throws IOException {
  AppEngineFile file = newFile(fileDescription);
  OutputStream out = openForFinalWrite(file);
  out.write(bytes);
  out.close();
  BlobKey blobKey = getBlobKey(file);
  // We verify if what's in the file matches what we wanted to write -- the
  // Files API is still experimental and I've seen it lose data.
  byte[] actualContent = slurp(blobKey);
  if (!Arrays.equals(bytes, actualContent)) {
    throw new IOException("File " + file + " does not contain the bytes we intended to write");
  }
  return blobKey;
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:15,代码来源:OversizedPropertyMover.java

示例9: slurp

import com.google.appengine.api.files.AppEngineFile; //导入依赖的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

示例10: getFileContent

import com.google.appengine.api.files.AppEngineFile; //导入依赖的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

示例11: processFileWithContent

import com.google.appengine.api.files.AppEngineFile; //导入依赖的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)
}
 
开发者ID:icza,项目名称:sc2gears,代码行数:37,代码来源:TaskServlet.java

示例12: service

import com.google.appengine.api.files.AppEngineFile; //导入依赖的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);
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:31,代码来源:PrintServlet.java

示例13: setUp

import com.google.appengine.api.files.AppEngineFile; //导入依赖的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);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:16,代码来源:ImageServingUrlTest.java

示例14: writeToFile

import com.google.appengine.api.files.AppEngineFile; //导入依赖的package包/类
private void writeToFile(AppEngineFile file, String content) throws IOException {
    FileWriteChannel channel = service.openWriteChannel(file, true);
    try {
        channel.write(ByteBuffer.wrap(content.getBytes()));
    } finally {
        channel.closeFinally();
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:9,代码来源:ServeBlobServlet.java

示例15: writeNewBlobFile

import com.google.appengine.api.files.AppEngineFile; //导入依赖的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);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-tck,代码行数:12,代码来源:BlobstoreTestBase.java


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