To achieve the effect of resizing a byte array without losing content, several solutions have already been mentioned in Java:
1) ArrayList<Byte> (see answers by a.ch. and kgiannakakis)
2) System.arraycopy() (. jimpic, kgiannakakis UVM)
- :
byte[] bytes = new byte[1024];
//
// Do some operations with array bytes
//
byte[] bytes2 = new byte[2024];
System.arraycopy(bytes,0,bytes2,0,bytes.length);
//
// Do some further operations with array bytes2 which contains
// the same first 1024 bytes as array bytes
3) , , , : Arrays.copyOfRange()
byte[] bytes = new byte[1024];
//
// Do some operations with array bytes
//
bytes = Arrays.copyOfRange(bytes,0,2024);
//
// Do some further operations with array bytes whose first 1024 bytes
// didn't change and whose remaining bytes are padded with 0
, (, ). , .