Search in sources :

Example 81 with BlobInfo

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;
}
Also used : BlobInfo(com.google.cloud.storage.BlobInfo)

Example 82 with BlobInfo

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();
}
Also used : BlobInfo(com.google.cloud.storage.BlobInfo) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime)

Example 83 with BlobInfo

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"));
}
Also used : BlobInfo(com.google.cloud.storage.BlobInfo)

Example 84 with BlobInfo

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"));
}
Also used : BlobInfo(com.google.cloud.storage.BlobInfo)

Example 85 with BlobInfo

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;
}
Also used : Blob(com.google.cloud.storage.Blob) BlobInfo(com.google.cloud.storage.BlobInfo)

Aggregations

BlobInfo (com.google.cloud.storage.BlobInfo)94 Test (org.junit.Test)61 Blob (com.google.cloud.storage.Blob)56 BlobId (com.google.cloud.storage.BlobId)31 Storage (com.google.cloud.storage.Storage)21 StorageException (com.google.cloud.storage.StorageException)17 WriteChannel (com.google.cloud.WriteChannel)13 ReadChannel (com.google.cloud.ReadChannel)7 CopyWriter (com.google.cloud.storage.CopyWriter)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ByteBuffer (java.nio.ByteBuffer)7 InputStream (java.io.InputStream)4 URL (java.net.URL)4 StorageBatch (com.google.cloud.storage.StorageBatch)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 TestRunner (org.apache.nifi.util.TestRunner)3 Acl (com.google.cloud.storage.Acl)2 Bucket (com.google.cloud.storage.Bucket)2 FileInputStream (java.io.FileInputStream)2 OutputStream (java.io.OutputStream)2