• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Transform one object BufferedReader into pdf file

 
Ranch Hand
Posts: 455
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: 4223
47
  • 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: 455
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: 5776
146
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: 4223
47
  • 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: 10539
224
  • 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: 4223
47
  • 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: 10539
224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Dana Ucaed
Ranch Hand
Posts: 455
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: 455
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your hints were very helpful.

 
Won't you be my neighbor? - Fred Rogers. tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!