Get wrong result after converting byte array to String and back in Java

I got a chain of workers that work with byte array, but they have to receive and translate String and char array to the work method work(@NotNull Object data, @NotNull Object prev) as well. So I convert byte array in one worker to String nextWorker.work(new String(result, "UTF-16BE"),this); and translate it to another worker in work method where it converts back to byte array if(data instanceof String){workingData = ((String)data).getBytes("UTF-16BE");}, but result is wrong in some cases ( i pass byte arr size of N and get after byte arr size of N - 2 or something like that, and missed bytes are not from the begining or ending of that array). Can anybody help me to solve this problem or give advise why it happens.


Ответы (0 шт):