aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/koushikdutta/async/ServerSocketChannelWrapper.java
blob: ee31298fc80b0e2519047243041049090d8bb7a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.koushikdutta.async;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;

import junit.framework.Assert;

class ServerSocketChannelWrapper extends ChannelWrapper {
    ServerSocketChannel mChannel;

    ServerSocketChannelWrapper(ServerSocketChannel channel) throws IOException {
        super(channel);
        mChannel = channel;
    }

    @Override
    public int read(ByteBuffer buffer) throws IOException {
        final String msg = "Can't read ServerSocketChannel";
        Assert.fail(msg);
        throw new IOException(msg);
    }

    @Override
    public boolean isConnected() {
        Assert.fail("ServerSocketChannel is never connected");
        return false;
    }

    @Override
    public int write(ByteBuffer src) throws IOException {
        final String msg = "Can't write ServerSocketChannel";
        Assert.fail(msg);
        throw new IOException(msg);

    }

    @Override
    public SelectionKey register(Selector sel) throws ClosedChannelException {
        return mChannel.register(sel, SelectionKey.OP_ACCEPT);
    }

    @Override
    public int write(ByteBuffer[] src) throws IOException {
        final String msg = "Can't write ServerSocketChannel";
        Assert.fail(msg);
        throw new IOException(msg);
    }
}