Solved

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

Posted on 2008-11-02
3
424 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping1 challenge 7 73
groovy example issue 10 90
Java Message handling in Service Layer 3 58
JDeveloper 12c for 32 bit 4 71
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

863 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

23 Experts available now in Live!

Get 1:1 Help Now