I want to use the put method of the java nio ByteBuffer in the following way:
ByteBuffer small = ByteBuffer.allocate(SMALL_AMOUNT_OF_BYTES);
ByteBuffer big = getAllData();
while (big.hasRemaining()){
small.put(big);
send(small);
}
the method put will throw buffer overflow exception, so what i does to fix it was:
ByteBuffer small = ByteBuffer.allocate(SMALL_AMOUNT_OF_BYTES);
ByteBuffer big = getAllData();
while (big.hasRemaining()){
while (small.hasRemaining() && big.hasRemaining()){
small.put(big.get());
}
send(small);
}
my question is - is there a better way to do so or at least an efficient way to do what i want?