Skip to content

DataStax-Examples/blobs-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Querying Blobs in Java

Binary Large Objects ( Blobs ) can be useful when the data doesn't fit into a standard Cassandra data type. Some examples of common Blob usage are for images or large files. Be careful of the size of your blobs, though: it's best to break them up so that each blob cell is 1 MB or less.

Contributor(s): Olivier Michallat, Tomasz Lelek - derived from here

Objectives

  • Demonstrate how to write and read these blob data type columns in a Java application

Project Layout

How this Sample Works

By default, the Java DataStax Driver maps blob types to java.nio.ByteBuffer. The ByteBuffer API is a bit tricky to use at times, so we will show common pitfalls as well. We strongly recommend that you read the java.nio.Buffer and ByteBuffer API docs and become familiar with the capacity, limit, and position properties. This tutorial is also useful.

Setup and Running

Prerequisites

  • JDK 14
  • A Cassandra cluster is running and accessible through the contacts points and data center identified in application.conf

Running

Building

At the project root level

mvn clean package

This builds the JAR file located at target/storing-and-retrieving-blobs-1.0.jar

Run the program

java -jar target/storing-and-retrieving-blobs-1.0.jar

This will produce output similar to the following:

Writing retrieved buffer to /var/folders/v5/f93lqcsx2fj4__41f7l5w5j80000gn/T/blob6758286736353817789.png

About

Write and read blobs with Cassandra using the Java DataStax Driver

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages