1 /* |
1 /* |
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
77 src.position(p).limit(l); |
77 src.position(p).limit(l); |
78 return copy; |
78 return copy; |
79 } |
79 } |
80 |
80 |
81 public static DummyWebSocketServer serverWithCannedData(int... data) { |
81 public static DummyWebSocketServer serverWithCannedData(int... data) { |
|
82 return serverWithCannedDataAndAuthentication(null, null, data); |
|
83 } |
|
84 |
|
85 public static DummyWebSocketServer serverWithCannedDataAndAuthentication( |
|
86 String username, |
|
87 String password, |
|
88 int... data) |
|
89 { |
82 byte[] copy = new byte[data.length]; |
90 byte[] copy = new byte[data.length]; |
83 for (int i = 0; i < data.length; i++) { |
91 for (int i = 0; i < data.length; i++) { |
84 copy[i] = (byte) data[i]; |
92 copy[i] = (byte) data[i]; |
85 } |
93 } |
86 return serverWithCannedData(copy); |
94 return serverWithCannedDataAndAuthentication(username, password, copy); |
87 } |
95 } |
88 |
96 |
89 public static DummyWebSocketServer serverWithCannedData(byte... data) { |
97 public static DummyWebSocketServer serverWithCannedData(byte... data) { |
|
98 return serverWithCannedDataAndAuthentication(null, null, data); |
|
99 } |
|
100 |
|
101 public static DummyWebSocketServer serverWithCannedDataAndAuthentication( |
|
102 String username, |
|
103 String password, |
|
104 byte... data) |
|
105 { |
90 byte[] copy = Arrays.copyOf(data, data.length); |
106 byte[] copy = Arrays.copyOf(data, data.length); |
91 return new DummyWebSocketServer() { |
107 return new DummyWebSocketServer(username, password) { |
92 @Override |
108 @Override |
93 protected void write(SocketChannel ch) throws IOException { |
109 protected void write(SocketChannel ch) throws IOException { |
94 int off = 0; int n = 1; // 1 byte at a time |
110 int off = 0; int n = 1; // 1 byte at a time |
95 while (off + n < copy.length + n) { |
111 while (off + n < copy.length + n) { |
96 // try { |
112 // try { |