Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/nio/channels/SocketChannel/Basic.java
41154 views
1
/*
2
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/* @test
25
* @summary Unit test for socket channels
26
* @library .. /test/lib
27
* @build jdk.test.lib.Utils TestServers
28
* @run main Basic
29
*/
30
31
import java.net.*;
32
import java.nio.*;
33
import java.nio.channels.*;
34
import java.nio.charset.*;
35
36
37
public class Basic {
38
39
static java.io.PrintStream out = System.out;
40
41
static void test(TestServers.DayTimeServer daytimeServer) throws Exception {
42
InetSocketAddress isa
43
= new InetSocketAddress(daytimeServer.getAddress(),
44
daytimeServer.getPort());
45
SocketChannel sc = SocketChannel.open(isa);
46
out.println("opened: " + sc);
47
/*
48
out.println("opts: " + sc.options());
49
((SocketOpts.IP.TCP)sc.options())
50
.noDelay(true)
51
.typeOfService(SocketOpts.IP.TOS_THROUGHPUT)
52
.broadcast(true)
53
.keepAlive(true)
54
.linger(42)
55
.outOfBandInline(true)
56
.receiveBufferSize(128)
57
.sendBufferSize(128)
58
.reuseAddress(true);
59
out.println(" " + sc.options());
60
*/
61
// sc.connect(isa);
62
out.println("connected: " + sc);
63
ByteBuffer bb = ByteBuffer.allocateDirect(100);
64
int n = sc.read(bb);
65
bb.position(bb.position() - 2); // Drop CRLF
66
bb.flip();
67
CharBuffer cb = Charset.forName("US-ASCII").newDecoder().decode(bb);
68
out.println(isa + " says: \"" + cb + "\"");
69
sc.socket().shutdownInput();
70
out.println("ishut: " + sc);
71
sc.socket().shutdownOutput();
72
out.println("oshut: " + sc);
73
sc.close();
74
out.println("closed: " + sc);
75
}
76
77
public static void main(String[] args) throws Exception {
78
try (TestServers.DayTimeServer dayTimeServer
79
= TestServers.DayTimeServer.startNewServer(100)) {
80
test(dayTimeServer);
81
}
82
}
83
84
}
85
86