-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathSocketIO.java
More file actions
84 lines (76 loc) · 1.91 KB
/
SocketIO.java
File metadata and controls
84 lines (76 loc) · 1.91 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* Copyright (c) 2007 Jython Developers */
package org.python.core.io;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import org.python.core.Py;
/**
* Raw I/O implementation for sockets.
*
* @author Philip Jenvey
*/
public class SocketIO extends SocketIOBase<SocketChannel> {
/**
* Construct a SocketIO for the given SocketChannel.
*
* @param socketChannel a SocketChannel to wrap
* @param mode a raw io socket mode String
*/
public SocketIO(SocketChannel socketChannel, String mode) {
super(socketChannel, mode);
}
@Override
public int readinto(ByteBuffer buf) {
checkClosed();
checkReadable();
try {
return socketChannel.read(buf);
} catch (IOException ioe) {
throw Py.IOError(ioe);
}
}
/**
* Read bytes into each of the specified ByteBuffers via scatter
* i/o.
*
* @param bufs {@inheritDoc}
* @return {@inheritDoc}
*/
@Override
public long readinto(ByteBuffer[] bufs) {
checkClosed();
checkReadable();
try {
return socketChannel.read(bufs);
} catch (IOException ioe) {
throw Py.IOError(ioe);
}
}
@Override
public int write(ByteBuffer buf) {
checkClosed();
checkWritable();
try {
return socketChannel.write(buf);
} catch (IOException ioe) {
throw Py.IOError(ioe);
}
}
/**
* Writes bytes from each of the specified ByteBuffers via gather
* i/o.
*
* @param bufs {@inheritDoc}
* @return {@inheritDoc}
*/
@Override
public long write(ByteBuffer[] bufs) {
checkClosed();
checkWritable();
try {
return socketChannel.write(bufs);
} catch (IOException ioe) {
throw Py.IOError(ioe);
}
}
}