String CreateTweetTable = "CREATE TABLE if not exists Messages ("+
"user varchar,"+
" interaction_time timeuuid,"+
" tweet varchar,"+
" image blob," +
" imagelength int,"+
" PRIMARY KEY (user,interaction_time)"+
") WITH CLUSTERING ORDER BY (interaction_time DESC);";
Our image will be in the blob field and we also store the size of the image for reference. We can load a picture from a file on the local machines hard disk like this:
FileInputStream fis=new FileInputStream("/Users/Administrator/Desktop/mystery.png");
byte[] b= new byte[fis.available()+1];
int length=b.length;
fis.read(b);
We now need to convert the byte array into a bytebuffer:
ByteBuffer buffer =ByteBuffer.wrap(b);
Writing the record becomes simply:
PreparedStatement ps = session.prepare("insert into Messages ( image, user, interaction_time,imagelength) values(?,?,?,?)");
BoundStatement boundStatement = new BoundStatement(ps);
session.execute( boundStatement.bind( buffer, "Andy", convertor.getTimeUUID(),length));
Getting the image back is simple. Use a Select to get the result set:
PreparedStatement ps = session.prepare("select user,image,imagelength from Messages where user =?");
BoundStatement boundStatement = new BoundStatement(ps);
ResultSet rs =session.execute ( boundStatement.bind("Andy"));
We can now loop through the result set (here we are assuming only one image comes back)
ByteBuffer bImage=null;
for (Row row : rs) {
bImage = row.getBytes("image") ;
length=row.getInt("imagelength");
}
However to display the image we will need it as a byte array. We can’t use bImage.get() as this reaches down in to the raw buffer (see: https://groups.google.com/a/lists.datastax.com/forum/#!searchin/java-driver-user/blob$20ByteBuffer/java-driver-user/4_KegVX0teo/2OOZ8YOwtBcJ for details ) Instead we can use :
byte image[]= new byte[length];
image=Bytes.getArray(bImage);
In the servlet we can return this image in one of 2 ways:
OutputStream out = response.getOutputStream();
response.setContentType("image/png");
response.setContentLength(image.length);
out.write(Image);
Writes the image as a single lump which may use too much memory. You might be better using a bufferedinput stream (http://stackoverflow.com/questions/2979758/writing-image-to-servlet-response-with-best-performance)
InputStream is = new ByteArrayInputStream(Image);
BufferedInputStream input = new BufferedInputStream(is);
byte[] buffer = new byte[8192];
for (int length = 0; (length = input.read(buffer)) > 0;) {
out.write(buffer, 0, length);
}
out.close();
Nice post. It is really interesting. Thanks for sharing the post!
ReplyDeletefridge online
buy fridge online
buy refrigerator online
Washing Machine Online
Washing Machine Offers
Buy Washing Machine Online
Online Shopping
Nice post. It is really interesting. Thanks for sharing.
ReplyDeleteHotels in Tuticorin, Hotels in Thoothukudi, Best Hotel in Tuticorin
Great Post,really it was very helpful for us.
ReplyDeleteThanks a lot for sharing!
I found this blog to be very useful!!
Web Design and Development training in Bangalore
Why ByteBuffer instead of ByteArray?
ReplyDeleteVery nice article,thanks for sharing.
ReplyDeleteMatriculation School in Trichy,Matriculation School in Punganur
This comment has been removed by the author.
ReplyDeleteNice Post
ReplyDelete"Sanjary Academy provides excellent training for Piping design course. Best Piping Design Training Institute in Hyderabad,
Telangana. We have offer professional Engineering Course like Piping Design Course,QA / QC Course,document Controller
course,pressure Vessel Design Course, Welding Inspector Course, Quality Management Course, #Safety officer course."
Piping Design Course in India
Piping Design Course in Hyderabad
Piping Design Course in Hyderabad
QA / QC Course
QA / QC Course in india
QA / QC Course in Hyderabad
Document Controller course
Pressure Vessel Design Course
Welding Inspector Course
Quality Management Course
Quality Management Course in india
Safety officer course
Thanks for sharing
ReplyDeleteYaaron Studios is one of the rapidly growing editing studios in Hyderabad. We are the best Video Editing services in Hyderabad. We provides best graphic works like logo reveals, corporate presentation Etc. And also we gives the best Outdoor/Indoor shoots and Ad Making services.
Best video editing services in Hyderabad,ameerpet
Best Graphic Designing services in Hyderabad,ameerpet
Best Ad Making services in Hyderabad,ameerpet
Nice blog! i'm also working with a Digital marketing company in gurgaon
ReplyDeletewebsite designing in gurgaon
best website design services in gurgaon
web company in delhi
web desiging company
web design & development banner
web design & development company
web design & development services
web design agency delhi
web design agency in delhi
web design and development services
web design companies in delhi
web design company delhi
web design company in delhi
web design company in gurgaon
web design company in noida
web design company list
web design company services
web design company website
web design delhi
web design development company
web design development services
web design in delhi
web design service
web design services company
web design services in delhi
web designer company
web designer delhi
web designer in delhi
web designers delhi
web designers in delhi
web designing & development
web designing advertisement
web designing and development
web designing and development company
web designing and development services
web designing companies in delhi
web designing company delhi
web designing company in delhi
web designing company in gurgaon
web designing company in new delhi
web designing company in noida
web designing company logo
web designing company sites
web designing company websites
web designing delhi
web designing in delhi
web designing in gurgaon
web designing in gurgaon
web designing service
web designing services
web designing services delhi
Hello, i am glad to read the whole content of this blog and am very excited and happy to say that the webmaster has done a very good job here to put all the information content and information at one place. More info please visit :-
ReplyDeleteTop IT Company in Delhi NCR
Graphic Designing Company Delhi NCR
Website Designing Delhi NCR
Dynamic Website Design Delhi NCR
logo Design in Delhi NCR
Customized Design in Delhi NCR
Web Development in Delhi NCR
solutions.brother.com/windows
ReplyDeletesolutions.brother.com/windows
canon.com/ijsetup
canon.com/ijsetup
Wohh I love it, I mean this blog is just awesome. I personally love this informative article… Keep Posting such information… Keep Going!
ReplyDeleteUK VPS Hosting
Very Nice Blog, You are spreading very good information among us… Yes Web Hosting plays very important role in business world. And it is important to have the best hosting services.
ReplyDeleteUK VPS Hosting
I really appreciate this post and I like this very much. I am waiting for new post here and Please keep it up in future.
ReplyDeleteCloudBox99 offers you with the best Cloud server hosting service in Hyderabad and facilitates enterprises to transform digitally. We keep you covered in terms of all your IT requirements with unmatched expertise and deep domain knowledge
Very Great article it was quite beneficial to us.
ReplyDeleteThank you for sharing!
This site was quite helpful to me also latest technology news 2022 .
This blog is nicely written and I found the content and information very informative as well as helpful.
ReplyDeleteevs full form
raw agent full form
full form of tbh in instagram
dbs bank full form
https full form
tft full form
pco full form
kra full form in hr
tbh full form in instagram story
epc full form
This blog has wonderful content, I liked that. you wrote such nice content. Totally Impressive. Keep it up!! I have come up with very important information about Web Hosting if you won't know about it then click on WordPress Web Hosting .
ReplyDeleteweb designing is one of the best and top developing IT training course at this point. Learning web designing will help you to understand the concepts of HTML, CSS and JAVASCRIPT. After understanding all the concepts a web developer can be able to create his own website from scratch.
ReplyDeleteA2N Academy, one of the top-tier IT Skill Development Institutes in Bangalore, offers the best Web Designing course. Our skilled trainers recruited by the academy offer quality-based Web Designing Courses. Steadily, we guide our students to get placed in prominent web design companies through our online web designing course.
With a determined goal to nurture students for their skills and placement, we focus on developing web designing skills in students through our web designing course with a learning-by-doing approach and creating responsive websites from scratch for all platforms.
web designing course
Really a very helpful article thanks for sharing and keep on sharing!
ReplyDeleteBSC 1st Year Result 2021 | BSC 2nd Year Result 2021 | BSC 3rd Year Result 2021.
epl Fixtures 20 August 2022
ReplyDeleteepl Fixtures 21 August 2022
epl Fixtures 22 August 2022
epl Fixtures 27 August 2022
epl Fixtures 28 August 2022
epl Fixtures 30 August 2022
epl Fixtures 31 August 2022