Solved

How to get out the byte[] in a ByteArrayDataSource ?

Posted on 2008-11-02
3
419 Views
Last Modified: 2012-05-05
My code looks as follow:

...
com.sun.istack.ByteArrayDataSource byteArrayDataSource = (com.sun.istack.ByteArrayDataSource) erstelleAntragResponse.getPdfDokument().getPdfData().getDataSource();
...

By debugging the byteArrayDataSource looks as follow:

"byteArrayDataSource" = ByteArrayDataSource
  buf=byte[64727]
    [0...99999]
      [0...99]
        [0]=37
        [0]=80
        [0]=68
        [0]=70
        [0]=45
        [0]=49
        [0]=46
...

My question:
1.
How can I get the 'buf'?

2.
The values of "37, 80, 68, 70, 45, 49, 46..." means "%PDF....".

How can I convert it from number to ASCII?
0
Comment
Question by:chenwei
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
Comment Utility
Try calling getInputStream on it and writing into a ByeArrayOutputStream (you can find 'IOUtils' at http://www.technojeeves.com/joomla/index.php/free/51-copying-streams ) :
ByteArrayOutputStream out = new ByteArrayOutputStream();

IOUtils.copyStream(dataSource.getInputStream(), out);

byte[] content = out.toByteArray();

Open in new window

0
 

Author Comment

by:chenwei
Comment Utility
Hi cehj,

many thanks!
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
:-)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now