Solved

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

Posted on 2008-11-02
3
426 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
ID: 22862992
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
ID: 22869027
Hi cehj,

many thanks!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22869128
:-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

839 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