本文整理汇总了Java中com.google.appengine.api.blobstore.BlobstoreInputStream类的典型用法代码示例。如果您正苦于以下问题:Java BlobstoreInputStream类的具体用法?Java BlobstoreInputStream怎么用?Java BlobstoreInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlobstoreInputStream类属于com.google.appengine.api.blobstore包,在下文中一共展示了BlobstoreInputStream类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFontFromBlobstore
import com.google.appengine.api.blobstore.BlobstoreInputStream; //导入依赖的package包/类
/**
* Get Font From Blobstore
* @param blobKey
* @return font
* @throws ServletException
*/
private Font getFontFromBlobstore(BlobKey blobKey) throws ServletException{
try {
//FileService fileService = FileServiceFactory.getFileService();
//AppEngineFile fontFile = fileService.getBlobFile(blobKey);
//FileReadChannel readChannel = fileService.openReadChannel(fontFile, false);
//BufferedReader reader = new BufferedReader(Channels.newReader(readChannel, "UTF8"));
//InputStream is = Channels.newInputStream(readChannel);
//BlobstoreInputStream is much faster than the above AppEngineFile
Font font = FontUtils.getFonts(new BlobstoreInputStream(blobKey))[0];
memcache.put(blobKey, font);
return font;
} catch (IOException ex){
throw new ServletException(ex);
}
}
示例2: getBlobstoreBytes
import com.google.appengine.api.blobstore.BlobstoreInputStream; //导入依赖的package包/类
private byte[] getBlobstoreBytes(String blobKeyString) throws BlobReadException {
BlobKey blobKey = new BlobKey(blobKeyString);
if (blobKey == null) {
throw new BlobReadException("Could not find BlobKey for " + blobKeyString);
}
try {
InputStream blobInputStream = new BlobstoreInputStream(blobKey);
return ByteStreams.toByteArray(blobInputStream);
} catch (IOException e) {
throw new BlobReadException(e, "Error trying to read blob from " + blobKey);
}
}
示例3: renameFileToGoogleId
import com.google.appengine.api.blobstore.BlobstoreInputStream; //导入依赖的package包/类
private String renameFileToGoogleId(BlobInfo blobInfo) throws IOException {
Assumption.assertNotNull(blobInfo);
BlobKey blobKey = blobInfo.getBlobKey();
byte[] imageData = new byte[(int) blobInfo.getSize()];
try (InputStream blobStream = new BlobstoreInputStream(blobKey)) {
blobStream.read(imageData);
}
deletePicture(blobKey);
return GoogleCloudStorageHelper.writeImageDataToGcs(account.googleId, imageData);
}
示例4: testBlobInputStream
import com.google.appengine.api.blobstore.BlobstoreInputStream; //导入依赖的package包/类
@Test
public void testBlobInputStream() throws Exception {
String CONTENT = "BlobInputStreamTest";
BlobKey blobKey = writeNewBlobFile(CONTENT);
BlobstoreInputStream stream = new BlobstoreInputStream(blobKey);
assertEquals(CONTENT, toString(stream));
}
示例5: testBlobInputStreamWithOffset
import com.google.appengine.api.blobstore.BlobstoreInputStream; //导入依赖的package包/类
@Test
public void testBlobInputStreamWithOffset() throws Exception {
BlobKey blobKey = writeNewBlobFile("BlobInputStreamTest");
int OFFSET = 4;
BlobstoreInputStream stream = new BlobstoreInputStream(blobKey, OFFSET);
assertEquals("InputStreamTest", toString(stream));
}
示例6: doPost
import com.google.appengine.api.blobstore.BlobstoreInputStream; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String password = req.getParameter("password");
Map<String, List<BlobKey>> uploads = blobstoreService.getUploads(req);
if (!uploads.containsKey("file")) {
sendError(resp, 400, "No certificate file");
return;
}
BlobKey key = uploads.get("file").get(0);
if (!signatureContainerService.isValid(new BlobstoreInputStream(key), password)) {
signatureContainerDescriptionRepository.delete(getUserId(req));
sendError(resp, 400, "Wrong password or file");
return;
}
if (!checkMasterPermission(req)) {
sendError(resp, 403, "Wrong permissions");
return;
}
signatureContainerDescriptionRepository.store(new SignatureContainerDescription(
key,
password,
isMaster(req) ? "master" : getUserId(req)));
}
示例7: toString
import com.google.appengine.api.blobstore.BlobstoreInputStream; //导入依赖的package包/类
private String toString(BlobstoreInputStream in) throws IOException {
byte[] contents = IOUtils.toBytes(in, true);
return new String(contents);
}
示例8: getContent
import com.google.appengine.api.blobstore.BlobstoreInputStream; //导入依赖的package包/类
public InputStream getContent(SignatureContainerDescription description) throws IOException {
return new BlobstoreInputStream(description.getKey());
}
示例9: structureFileAndPostToDb
import com.google.appengine.api.blobstore.BlobstoreInputStream; //导入依赖的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;
}