Exemplo n.º 1
0
 @NotNull
 private String createRemoteFile(
     @NotNull ObjectId id, @NotNull ObjectLoader loader, @NotNull Uploader uploader)
     throws IOException {
   // Create LFS stream.
   final String hash;
   final String cached = cacheSha256.get(id.name());
   long size = 0;
   if (cached == null) {
     final MessageDigest md = createSha256();
     try (InputStream istream = loader.openStream()) {
       byte[] buffer = new byte[0x10000];
       while (true) {
         int read = istream.read(buffer);
         if (read <= 0) break;
         md.update(buffer, 0, read);
         size += read;
       }
     }
     hash = new String(Hex.encodeHex(md.digest(), true));
     cacheSha256.put(id.name(), hash);
     cache.commit();
   } else {
     hash = cached;
   }
   uploader.upload(id, new Meta(hash, size));
   return hash;
 }
Exemplo n.º 2
0
  public void mousePressed() {
    // Upload the current camera frame.
    println("Uploading");

    loadPixels();
    PImage scrImg = get(0, 0, width, height);
    // First compress it as a jpeg.
    byte[] compressedImage = compressImage(scrImg);

    // Set some meta data.
    UploadMetaData uploadMetaData = new UploadMetaData();
    uploadMetaData.setTitle("Frame " + frameCount + " Uploaded from Processing");
    uploadMetaData.setDescription("mouseFound");
    uploadMetaData.setPublicFlag(true);

    // Finally, upload/
    try {
      uploader.upload(compressedImage, uploadMetaData);
    } catch (Exception e) {
      println("Upload failed");
    }

    println("Finished uploading");
  }