### Question:
DataBuffer { public static <T> DataBuffer<T> resample(DataBuffer<T> buffer, Dimension from, Dimension to) { DataBuffer resampled = create(to.width()*to.height(), buffer.datatype()); resampled.buffer().order(buffer.buffer().order()); double xratio = from.width() / (double)to.width(); double yratio = from.height() / (double)to.height(); int px, py ; for (int j = 0; j < to.height(); j++) { int offset = j*to.width(); for (int i = 0; i < to.width(); i++ ) { px = (int) Math.floor(i*xratio); py = (int) Math.floor(j*yratio); resampled.put(offset+i, buffer.get(py*from.width()+px)); } } return resampled.rewind(); } DataBuffer(ByteBuffer buffer, DataType datatype); static DataBuffer create(ByteBuffer buffer, DataType datatype); static DataBuffer create(int size, DataType datatype); static DataBuffer<T> resample(DataBuffer<T> buffer, Dimension from, Dimension to); ByteBuffer buffer(); abstract T get(); T get(int i); DataBuffer<T> put(Object val); DataBuffer<T> put(int i, T val); DataBuffer<T> flip(); DataBuffer<T> rewind(); DataBuffer<T> word(); int size(); DataType datatype();  }### Answer:
@Test public void testResample() { DataBuffer nbuf = DataBuffer.create(4, DataType.INT); nbuf.put(1).put(2).put(3).put(4); DataBuffer rbuf = DataBuffer.resample(nbuf, new Dimension(2, 2), new Dimension(4,4)); assertEquals(1, rbuf.get()); assertEquals(1, rbuf.get()); assertEquals(2, rbuf.get()); assertEquals(2, rbuf.get()); assertEquals(1, rbuf.get()); assertEquals(1, rbuf.get()); assertEquals(2, rbuf.get()); assertEquals(2, rbuf.get()); assertEquals(3, rbuf.get()); assertEquals(3, rbuf.get()); assertEquals(4, rbuf.get()); assertEquals(4, rbuf.get()); assertEquals(3, rbuf.get()); assertEquals(3, rbuf.get()); assertEquals(4, rbuf.get()); assertEquals(4, rbuf.get()); try { rbuf.get(); fail(); } catch(BufferUnderflowException e) { } }