• Post Reply Bookmark Topic Watch Topic
  • New Topic

OutputStream System.out to String BLOB

 
Imre Tokai
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!


I have a piece of code:

where byteArray is a BLOB type.
This is working fine.

Instead of the output stream, i want to convert bytes to string. So, i need sg like StringOutputStrem.


What classes should i use and how?

Regards
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imre: i want to convert bytes to string. So, i need sg like StringOutputStrem.


Streams are not the ones dealing with characters. If you want to handle characters then its better to use a writer and a OutputStreamWriter will do just fine.

Just make sure that you use an appropriate encoding.

BTW, if your only intention is to convert a byte[] to a string, This string constructor will be enough!
[ December 15, 2008: Message edited by: Nitesh Kant ]
 
Imre Tokai
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your answer Nitesh!


The problem is that i have byte array, which is BLOB indeed. I succeed to write it on console, but i want to write it in String or StringBuffer, because i want to use it in further code.

new String(byte[]) is not good, because of BLOB type (that's sg like pointer -i suppose?)

I know that there is difference between Writers(chars) and Streams(bytes).


For now, i'm writing out the content into a new file, and i'm opening and reading that file right after that. I believe that there is BETTER solution than this?

Maybe to make a connection between Output and Input Stream? How? I tried with several examples, but they worked only for simple String and not for bytes...
If i can flush text on console, there must be a way to keep it in the code? ow?


Regards
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you justify this? Why is it not good?
Are you going to change the String value after this?
Originally posted by Imre Tokai:

new String(byte[]) is not good, because of BLOB type (that's sg like pointer -i suppose?)

[ December 15, 2008: Message edited by: Duc Vo ]
 
Imre Tokai
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i use new String(byte[]) i get sg like:

I suppose that this is the reference to the value. It's related to BLOB type in the database.

So i see the appropriate value only after flushing byte array on the stream. I'd flush it in, some way, to a String. And i don't want to use write/read to/from file.
Later, I want to fill pdf document with value from byte array via String.


Regards
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case you can write it to ByteArrayOutputStream, then use the toString method to get the string value.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!