1 package org.sapia.ubik.net.nio; 2 3 import java.io.IOException ; 4 import java.nio.ByteBuffer ; 5 6 15 public class TestReadChannel extends TestChannel{ 16 17 private byte[] _data, _buf; 18 private int _pos = 0; 19 20 public TestReadChannel(byte[] data, int batchSize){ 21 _data = data; 22 _buf = new byte[batchSize]; 23 } 24 25 public int read(ByteBuffer to) throws IOException { 26 if(_pos < _data.length){ 27 int remaining = to.remaining(); 28 int count = 0; 29 while(_pos < _data.length && 30 count < remaining && 31 count < _buf.length){ 32 _buf[count++] = _data[_pos++]; 33 } 34 to.put(_buf, 0, count); 35 return count; 36 } 37 else{ 38 return 0; 39 } 40 } 41 42 } 43 | Popular Tags |