1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.io.channels;
19
20 import java.io.IOException;
21 import java.nio.ByteBuffer;
22 import java.nio.channels.FileChannel;
23 import java.nio.channels.ReadableByteChannel;
24
25
26
27
28 class NonBlockingFileChannelProxy extends FileChannelProxy {
29
30 boolean toggleRead0;
31
32 NonBlockingFileChannelProxy(final FileChannel fileChannel) {
33 super(fileChannel);
34 }
35
36 private boolean flipState() {
37 return toggleRead0 = !toggleRead0;
38 }
39
40 @Override
41 public int read(final ByteBuffer dst) throws IOException {
42 return flipState() ? 0 : super.read(dst);
43 }
44
45 @Override
46 public int read(final ByteBuffer dst, final long position) throws IOException {
47 flipState();
48 return flipState() ? 0 : super.read(dst, position);
49 }
50
51 @Override
52 public long read(final ByteBuffer[] dsts, final int offset, final int length) throws IOException {
53 return flipState() ? 0 : super.read(dsts, offset, length);
54 }
55 }