• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Transform one object BufferedReader into pdf file

 
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a dilemma with my code:






How can save the response from http post to a pdf file?

Thanks in advance,





 
Master Rancher
Posts: 4663
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the response currently?
Is it a PDF file that comes back?
 
Dana Ucaed
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yep, it is a pdf file.

Practically I want to transform a string to a pdf file.

 
Saloon Keeper
Posts: 6588
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reader and Writer work with character data - which PDFs are not. They are binary data, for which you need to use streams.
 
Dave Tolls
Master Rancher
Posts: 4663
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep.
As Tim says, you are working with a binary file.
In any case, you aren't processing it, you just want to save it to the disk (or wherever), so you ought to use the stream directly.
Read a chunk of bytes, write the chunk of bytes...repeat until you reach the end of the file stream.
 
Saloon Keeper
Posts: 12253
259
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reading and writing chunks of data is very Java 1.6.

If you're on Java 11, use HttpClient with BodyHandlers.ofFile(). Otherwise, use Files.copy().
 
Dave Tolls
Master Rancher
Posts: 4663
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, don't dis my style, daddio...
I'm hip and down with the kids, me!

(aka, I knew that but was typing on automatic...)
 
Stephan van Hulst
Saloon Keeper
Posts: 12253
259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Dana Ucaed
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Reading and writing chunks of data is very Java 1.6.

If you're on Java 11, use HttpClient with BodyHandlers.ofFile(). Otherwise, use Files.copy().



So, I am obsolete.(:-))

Thanks, I use Java 8, not Java 11.

 
Dana Ucaed
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your hints were very helpful.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic