コード例 #1
0
 private byte[] readBlob(final Long blobId) {
   try (BlobReader readBlob = blobstore.readBlob(blobId)) {
     int blobSize = (int) readBlob.getSize();
     byte[] result = new byte[blobSize];
     readBlob.read(result, 0, blobSize);
     return result;
   }
 }
コード例 #2
0
 private Long createBlob(final InputStream inputStream) {
   Objects.requireNonNull(inputStream, "inputStream cannot be null");
   try (BlobAccessor blobAccessor = blobstore.createBlob()) {
     int nRead;
     byte[] data = new byte[BUFFER_SIZE];
     while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
       blobAccessor.write(data, 0, nRead);
     }
     return blobAccessor.getBlobId();
   } catch (IOException e) {
     throw new UncheckedIOException(e);
   }
 }
コード例 #3
0
 private Attachment createAttachment(
     final Long blobId, final String contentType, final String name) {
   InputStreamSupplier inputStreamSupplier = null;
   if (blobId != null) {
     inputStreamSupplier =
         () -> {
           BlobReader readBlob = blobstore.readBlob(blobId);
           return new BlobInputStream(readBlob);
         };
   }
   Attachment attachment =
       new Attachment()
           .withContentType(contentType)
           .withName(name)
           .withInputStreamSupplier(inputStreamSupplier);
   return attachment;
 }
コード例 #4
0
 private void deleteBlob(final Long blobId) {
   blobstore.deleteBlob(blobId);
 }