1 4 package com.tc.util.io; 5 6 import java.io.IOException ; 7 import java.nio.ByteBuffer ; 8 import java.nio.channels.ReadableByteChannel ; 9 10 14 public class MockReadableByteChannel extends MockChannel implements ReadableByteChannel { 15 16 private long maxReadCount = Long.MAX_VALUE; 17 18 public final synchronized int read(ByteBuffer dst) throws IOException { 19 checkOpen(); 20 dst.isReadOnly(); int readCount = 0; 22 while (dst.hasRemaining() && readCount < getMaxReadCount()) { 23 dst.put((byte) 0x00); 24 ++readCount; 25 } 26 return readCount; 27 } 28 29 synchronized final void setMaxReadCount(long maxBytesToReadAtOnce) { 30 maxReadCount = maxBytesToReadAtOnce; 31 } 32 33 protected final synchronized long getMaxReadCount() { 34 return maxReadCount; 35 } 36 37 } 38 | Popular Tags |