@Test public void testOnBytesReceivedBufferHasArray() throws IOException { RandomAccessFile file = mock(RandomAccessFile.class); ResumableRandomAccessFileListener listener = new ResumableRandomAccessFileListener(file); byte[] array = new byte[]{1, 2, 23, 33}; ByteBuffer buf = ByteBuffer.wrap(array); listener.onBytesReceived(buf); verify(file).write(array, 0, 4); }
public void onBytesReceived(ByteBuffer buffer) throws IOException { file.seek(file.length()); if (buffer.hasArray()) { file.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else { byte[] b = new byte[buffer.remaining()]; int pos = buffer.position(); buffer.get(b); buffer.position(pos); file.write(b); } }
ResumableRandomAccessFileListener implements ResumableListener { public void onBytesReceived(ByteBuffer buffer) throws IOException { file.seek(file.length()); if (buffer.hasArray()) { file.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else { byte[] b = new byte[buffer.remaining()]; int pos = buffer.position(); buffer.get(b); buffer.position(pos); file.write(b); } } }
ResumableRandomAccessFileListener implements ResumableListener { public void onBytesReceived(ByteBuffer buffer) throws IOException { file.seek(file.length()); if (buffer.hasArray()) { file.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else { byte[] b = new byte[buffer.remaining()]; int pos = buffer.position(); buffer.get(b); buffer.position(pos); file.write(b); } } ResumableRandomAccessFileListener(RandomAccessFile file); }
ResumableRandomAccessFileListener implements ResumableListener { public void onBytesReceived(ByteBuffer buffer) throws IOException { file.seek(file.length()); if (buffer.hasArray()) { file.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else { byte[] b = new byte[buffer.remaining()]; int pos = buffer.position(); buffer.get(b); buffer.position(pos); file.write(b); } } ResumableRandomAccessFileListener(RandomAccessFile file); void onBytesReceived(ByteBuffer buffer); void onAllBytesReceived(); long length(); }
ResumableRandomAccessFileListener implements ResumableListener { public void onBytesReceived(ByteBuffer buffer) throws IOException { file.seek(file.length()); if (buffer.hasArray()) { file.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining()); } else { byte[] b = new byte[buffer.remaining()]; int pos = buffer.position(); buffer.get(b); buffer.position(pos); file.write(b); } } ResumableRandomAccessFileListener(RandomAccessFile file); void onBytesReceived(ByteBuffer buffer); void onAllBytesReceived(); long length();  }