Эти несколько строк кода дают мне исключение "java.lang.ArrayIndexOutOfBoundsException", может кто-нибудь взглянет и укажет, почему (исключение вызывается во втором вызове arraycopy ()):
byte [] newContentBytes = EntityUtils.toByteArray((serverResponse.getEntity()));
newContent = new String(newContentBytes);
System.out.println( newContent);
byte [] headerBytes = headers.getBytes();
byte[] res = new byte[newContentBytes.length + headerBytes.length];
//headerBytes.
System.arraycopy(headerBytes, 0, res, 0, headerBytes.length);
System.out.println( "length: " + newContentBytes.length);
System.arraycopy(newContentBytes, 0, res, newContentBytes.length , newContentBytes.length);
Проблема заключается в выделении размера res, например, если я пишу
новый байт [newContentBytes.length + headerBytes.length + 2000] вместо этого исключения не происходит, так какой должен быть точный размер?