Solved

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

Posted on 2008-11-02
3
428 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

717 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