1 4 package com.tc.util.io; 5 6 import java.io.IOException ; 7 import java.nio.ByteBuffer ; 8 import java.nio.channels.WritableByteChannel ; 9 10 14 public class MockWritableByteChannel extends MockChannel implements WritableByteChannel { 15 16 private long maxWriteCount = Long.MAX_VALUE; 17 18 public final synchronized int write(ByteBuffer src) throws IOException { 19 checkOpen(); 20 if (src == null) { throw new IOException ("null ByteBuffer passed in to write(ByteBuffer)"); } 21 int writeCount = 0; 22 while (src.hasRemaining() && writeCount < getMaxWriteCount()) { 23 src.get(); 24 ++writeCount; 25 } 26 return writeCount; 27 } 28 29 synchronized final void setMaxWriteCount(long maxBytesToWriteAtOnce) { 30 maxWriteCount = maxBytesToWriteAtOnce; 31 } 32 33 protected final synchronized long getMaxWriteCount() { 34 return maxWriteCount; 35 } 36 37 } 38 | Popular Tags |