1 4 package com.tc.util.io; 5 6 import java.io.IOException ; 7 import java.nio.ByteBuffer ; 8 import java.nio.channels.ScatteringByteChannel ; 9 10 13 public class MockScatteringByteChannel extends MockReadableByteChannel implements ScatteringByteChannel { 14 15 public long read(ByteBuffer [] dsts, int offset, int length) throws IOException { 16 throw new IOException ("Not yet implemented"); 17 } 18 19 public long read(ByteBuffer [] dsts) throws IOException { 20 checkOpen(); 21 if (dsts == null) { throw new IOException ("null ByteBuffer[] passed in to read(ByteBuffer[])"); } 22 checkNull(dsts); 23 long bytesRead = 0; 24 for (int pos = 0; pos < dsts.length && bytesRead < getMaxReadCount(); ++pos) { 25 ByteBuffer buffer = dsts[pos]; 26 while (buffer.hasRemaining() && bytesRead < getMaxReadCount()) { 27 buffer.put((byte) 0x00); 28 ++bytesRead; 29 } 30 } 31 return bytesRead; 32 } 33 34 private void checkNull(ByteBuffer [] srcs) throws IOException { 35 for (int pos = 0; pos < srcs.length; ++pos) { 36 if (srcs[pos] == null) { throw new IOException ("Null ByteBuffer at array position[" + pos + "]"); } 37 } 38 } 39 } 40 | Popular Tags |