Error while getting Bytearray from.3gp file on Android/Java

Asked

Viewed 34 times

0

I am trying to convert a file from audio.3gp for string Base64 and send to the server using Volley, but for all I know, I need to transform the audio.3gp in Bytearray and transform that array string bytes Base64.

I don’t get any kind of error or warning in the compiler, only the return is hard to understand...

Example of byte return

[] = ������ ftyp3gp4��������isom3gp4���� �moov������lmvhd���������> ��

My code to turn File into Bytearray

File file1 = new File(path);
    FileInputStream fis = null;

    try {
        fis = new FileInputStream(file1);

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        while (fis.available() > 0) {
            bos.write(fis.read());
        }
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    byte[] bytes = bos.toByteArray();
    String msgDecode = new String(bytes);
    System.out.print("BYTES ==== " + msgDecode);

Already tried to change the output charset, but did not solve...

1 answer

0

This is normal - not all data types are created to have a textual representation.

In this case, you are dealing with a binary file type - any value can have a value of 0 up to 255, which does not necessarily correspond to a printable character, and even if it does, it does not have to have any sequence that makes sense.

The idea of converting to "Base64" is precisely to re-encode this data, so that it can be transmitted using 100% printable characters - This ensures that network protocols and filters designed to handle text will not interfere with the nature of the data.

If you print your data after converting it to Base64, you will see that all characters are successfully printed - but the output will still make no sense - the data is simply not encoded as text.

summing up There is no error up to the point where you are - do the Base64 encoding and sending to the server step now, and don’t try to check if "it’s going well" by looking at the printed data.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.