use of com.google.cloud.storage.BlobInfo in project pokebattler-fight by celandro.
the class CloudStorageRankingSimulator method fetchBlob.
// public RankingResult rankAttacker(AttackStrategyType attackStrategy,
// AttackStrategyType defenseStrategy, SortType sortType, FilterType filterType, String filterValue,
// PokemonCreator attackerCreator, PokemonCreator defenderCreator, DodgeStrategyType dodgeStrategy, boolean noCloud) {
// if (noCloud == false && defenseStrategy == AttackStrategyType.DEFENSE_RANDOM_MC) {
// // create the url for monte carlo to see if it already exists
// String url = "rankings/attackers/levels/" + attackerCreator.createPokemon(PokemonId.ABRA, PokemonMove.ACID_FAST, PokemonMove.ABSORB).getLevel()
// + "/defenders/levels/" + defenderCreator.createPokemon(PokemonId.ABRA, PokemonMove.ACID_FAST, PokemonMove.ABSORB).getLevel()
// + "/strategies/" + attackStrategy + '/' + AttackStrategyType.DEFENSE_RANDOM_MC + '/'
// + sortType + "-" + dodgeStrategy + "-" + filterType + "-" + filterValue + ".bin";
// RankingResult retval = fetchBlob(url);
// if (retval != null) return retval;
// }
// return cachingRankingSimulator.rankAttacker(attackStrategy, defenseStrategy, sortType, filterType, filterValue, attackerCreator, defenderCreator, dodgeStrategy);
// }
//
private RankingResult fetchBlob(String url) {
try {
BlobInfo blob = BlobInfo.newBuilder(bucketName, url).build();
byte[] ranking = storage.readAllBytes(bucketName, url);
log.info("Found in google cloud storage!");
return RankingResult.parseFrom(ranking);
} catch (Exception e) {
log.info("Could not find gs://{}/{}, falling back", bucketName, url);
}
return null;
}
use of com.google.cloud.storage.BlobInfo in project getting-started-java by GoogleCloudPlatform.
the class CloudStorageHelper method uploadFile.
// [END init]
// [START uploadFile]
/**
* Uploads a file to Google Cloud Storage to the bucket specified in the BUCKET_NAME
* environment variable, appending a timestamp to end of the uploaded filename.
*/
public String uploadFile(FileItemStream fileStream, final String bucketName) throws IOException, ServletException {
checkFileExtension(fileStream.getName());
DateTimeFormatter dtf = DateTimeFormat.forPattern("-YYYY-MM-dd-HHmmssSSS");
DateTime dt = DateTime.now(DateTimeZone.UTC);
String dtString = dt.toString(dtf);
final String fileName = fileStream.getName() + dtString;
// the inputstream is closed by default, so we don't need to close it here
@SuppressWarnings("deprecation") BlobInfo blobInfo = storage.create(BlobInfo.newBuilder(bucketName, fileName).setAcl(new ArrayList<>(Arrays.asList(Acl.of(User.ofAllUsers(), Role.READER)))).build(), fileStream.openStream());
logger.log(Level.INFO, "Uploaded file {0} as {1}", new Object[] { fileStream.getName(), fileName });
// return the public download link
return blobInfo.getMediaLink();
}
use of com.google.cloud.storage.BlobInfo in project zeppelin by apache.
the class GCSNotebookRepoTest method createMalformed.
private void createMalformed(String noteId, String notePath) throws IOException {
BlobInfo info = BlobInfo.newBuilder(makeBlobId(noteId, notePath)).setContentType("application/json").build();
storage.create(info, "{ invalid-json }".getBytes("UTF-8"));
}
use of com.google.cloud.storage.BlobInfo in project zeppelin by apache.
the class GCSNotebookRepoTest method create.
private void create(Note note) throws IOException {
BlobInfo info = BlobInfo.newBuilder(makeBlobId(note.getId(), note.getPath())).setContentType("application/json").build();
storage.create(info, note.toJson().getBytes("UTF-8"));
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class StorageSnippets method updateBlobWithMetageneration.
/**
* Example of udating a blob, only if the blob's metageneration matches a value, otherwise a
* {@link StorageException} is thrown.
*/
// [TARGET update(BlobInfo, BlobTargetOption...)]
// [VARIABLE "my_unique_bucket"]
// [VARIABLE "my_blob_name"]
public Blob updateBlobWithMetageneration(String bucketName, String blobName) {
// [START updateBlobWithMetageneration]
Blob blob = storage.get(bucketName, blobName);
BlobInfo updatedInfo = blob.toBuilder().setContentType("text/plain").build();
storage.update(updatedInfo, BlobTargetOption.metagenerationMatch());
// [END updateBlobWithMetageneration]
return blob;
}
Aggregations