ByteArrayOutPutSteam to Byte[] not working properly with Upload-Component

I need to make a Byte out of a ByteArrayOutPutStream, but this is not working. When I log the outcome of baos.toByteArray(); it only shows me eleven characters, no matter which file I try to upload, the log entry looks like this: [B@544641ab

This is the code:

final ByteArrayOutputStream baos = new ByteArrayOutputStream(); // Stream to write to
upload = new Upload();
upload.setReceiver(new Upload.Receiver() {
public OutputStream receiveUpload(String filename, String mimeType) {

            return baos; // Return the output stream to write to
    upload.addSucceededListener(new Upload.SucceededListener() {
        public void uploadSucceeded(Upload.SucceededEvent succeededEvent) {
            System.out.println ( baos.toByteArray().toString());

[/code]Why is this not working and why is it giving me this strange 11 characters sized Array instead of the usual Byte-Array of the uploaded file?
Is there any better way to get to the byte-array of the uploaded file? I need to store the file in a database, and to do so I need the byte array of it.

What you are printing ([B@544641ab) is not the content of the byte array but the string representation of a byte array object ([ indicates it is an array, B is for byte and the number is the hashcode, see Object.toString and Class.getName javadocs for further info).
If you want to print the string representation of the contents of the array you can use Arrays.toString(…).

BTW using baos.toByteArray() should be correct to store the file in the db blob field.


Yes, thank you for pointing it out.

.toByteArray() returns a correct Byte, but the .toString() cannot be used the way I did it here.