01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.util.io;
05:
06: import java.io.IOException;
07: import java.nio.ByteBuffer;
08: import java.nio.channels.ScatteringByteChannel;
09:
10: /**
11: * dev-zero implementation of a readable channel.
12: */
13: public class MockScatteringByteChannel extends MockReadableByteChannel
14: implements ScatteringByteChannel {
15:
16: public long read(ByteBuffer[] dsts, int offset, int length)
17: throws IOException {
18: throw new IOException("Not yet implemented");
19: }
20:
21: public long read(ByteBuffer[] dsts) throws IOException {
22: checkOpen();
23: if (dsts == null) {
24: throw new IOException(
25: "null ByteBuffer[] passed in to read(ByteBuffer[])");
26: }
27: checkNull(dsts);
28: long bytesRead = 0;
29: for (int pos = 0; pos < dsts.length
30: && bytesRead < getMaxReadCount(); ++pos) {
31: ByteBuffer buffer = dsts[pos];
32: while (buffer.hasRemaining()
33: && bytesRead < getMaxReadCount()) {
34: buffer.put((byte) 0x00);
35: ++bytesRead;
36: }
37: }
38: return bytesRead;
39: }
40:
41: private void checkNull(ByteBuffer[] srcs) throws IOException {
42: for (int pos = 0; pos < srcs.length; ++pos) {
43: if (srcs[pos] == null) {
44: throw new IOException(
45: "Null ByteBuffer at array position[" + pos
46: + "]");
47: }
48: }
49: }
50: }
|