本文整理了Java中io.vertx.core.buffer.Buffer.copy()
方法的一些代码示例,展示了Buffer.copy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.copy()
方法的具体详情如下:
包路径:io.vertx.core.buffer.Buffer
类名称:Buffer
方法名:copy
暂无
代码示例来源:origin: eclipse-vertx/vert.x
public GoAway(GoAway that) {
errorCode = that.errorCode;
lastStreamId = that.lastStreamId;
debugData = that.debugData != null ? that.debugData.copy() : null;
}
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public Buffer transform(Buffer b) {
return b.copy();
}
代码示例来源:origin: eclipse-vertx/vert.x
public AddressResolverOptions(AddressResolverOptions other) {
this.hostsPath = other.hostsPath;
this.hostsValue = other.hostsValue != null ? other.hostsValue.copy() : null;
this.servers = other.servers != null ? new ArrayList<>(other.servers) : null;
this.optResourceEnabled = other.optResourceEnabled;
this.cacheMinTimeToLive = other.cacheMinTimeToLive;
this.cacheMaxTimeToLive = other.cacheMaxTimeToLive;
this.cacheNegativeTimeToLive = other.cacheNegativeTimeToLive;
this.queryTimeout = other.queryTimeout;
this.maxQueries = other.maxQueries;
this.rdFlag = other.rdFlag;
this.searchDomains = other.searchDomains != null ? new ArrayList<>(other.searchDomains) : null;
this.ndots = other.ndots;
this.rotateServers = other.rotateServers;
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCopy() throws Exception {
Buffer buff = TestUtils.randomBuffer(100);
assertEquals(buff, buff.copy());
Buffer copy = buff.getBuffer(0, buff.length());
assertEquals(buff, copy);
//Make sure they don't share underlying buffer
Buffer copy2 = buff.copy();
buff.setInt(0, 1);
assertEquals(copy, copy2);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testClientWebsocketReceivePingExceedsMaxFrameSize() {
String pingBody = randomAlphaString(113);
Integer maxFrameSize = 64;
Buffer ping1 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(0, maxFrameSize));
Buffer ping2 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(maxFrameSize, pingBody.length()));
server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST).setMaxWebsocketFrameSize(maxFrameSize));
server.websocketHandler(ws -> {
}).listen(onSuccess(v -> {
client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> {
List<Buffer> pongs = new ArrayList<>();
ws.pongHandler(pong -> {
pongs.add(pong);
if (pongs.size() == 2) {
assertEquals(pongs, Arrays.asList(ping1, ping2));
testComplete();
}
});
try {
ws.writeFrame(new WebSocketFrameImpl(FrameType.PING, ping1.copy().getByteBuf(), false));
ws.writeFrame(new WebSocketFrameImpl(FrameType.PING, ping2.copy().getByteBuf(), true));
} catch(Throwable t) {
fail(t);
}
});
}));
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testClientWebsocketReceivePongExceedsMaxFrameSize() {
String pingBody = randomAlphaString(113);
Integer maxFrameSize = 64;
Buffer ping1 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(0, maxFrameSize));
Buffer ping2 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(maxFrameSize, pingBody.length()));
server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST).setMaxWebsocketFrameSize(maxFrameSize));
server.websocketHandler(ws -> {
try {
ws.writeFrame(new WebSocketFrameImpl(FrameType.PONG, ping1.copy().getByteBuf(), false));
ws.writeFrame(new WebSocketFrameImpl(FrameType.PONG, ping2.copy().getByteBuf(), true));
} catch(Throwable t) {
fail(t);
}
}).listen(v -> {
client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> {
List<Buffer> pongs = new ArrayList<>();
ws.pongHandler(pong -> {
pongs.add(pong);
if (pongs.size() == 2) {
assertEquals(pongs, Arrays.asList(ping1, ping2));
testComplete();
}
});
});
});
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testServerWebsocketReceivePongExceedsMaxFrameSize() {
String pingBody = randomAlphaString(113);
Integer maxFrameSize = 64;
Buffer ping1 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(0, maxFrameSize));
Buffer ping2 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(maxFrameSize, pingBody.length()));
server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST).setMaxWebsocketFrameSize(maxFrameSize));
server.websocketHandler(ws -> {
List<Buffer> pongs = new ArrayList<>();
ws.pongHandler(pong -> {
pongs.add(pong);
if (pongs.size() == 2) {
assertEquals(pongs, Arrays.asList(ping1, ping2));
testComplete();
}
});
}).listen(v -> {
client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> {
try {
ws.writeFrame(new WebSocketFrameImpl(FrameType.PONG, ping1.copy().getByteBuf(), false));
ws.writeFrame(new WebSocketFrameImpl(FrameType.PONG, ping2.copy().getByteBuf(), true));
} catch(Throwable t) {
fail(t);
}
});
});
await();
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testServerWebsocketReceivePingExceedsMaxFrameSize() {
String pingBody = randomAlphaString(113);
Integer maxFrameSize = 64;
Buffer ping1 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(0, maxFrameSize));
Buffer ping2 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(maxFrameSize, pingBody.length()));
server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST).setMaxWebsocketFrameSize(maxFrameSize));
server.websocketHandler(ws -> {
}).listen(onSuccess(v -> {
client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> {
List<Buffer> pongs = new ArrayList<>();
ws.pongHandler(pong -> {
pongs.add(pong);
if (pongs.size() == 2) {
assertEquals(pongs, Arrays.asList(ping1, ping2));
testComplete();
}
});
try {
ws.writeFrame(new WebSocketFrameImpl(FrameType.PING, ping1.copy().getByteBuf(), false));
ws.writeFrame(new WebSocketFrameImpl(FrameType.PING, ping2.copy().getByteBuf(), true));
} catch(Throwable t) {
fail(t);
}
});
}));
await();
}
代码示例来源:origin: io.vertx/vertx-core
public GoAway(GoAway that) {
errorCode = that.errorCode;
lastStreamId = that.lastStreamId;
debugData = that.debugData != null ? that.debugData.copy() : null;
}
代码示例来源:origin: io.vertx/vertx-core
@Override
public Buffer transform(Buffer b) {
return b.copy();
}
代码示例来源:origin: io.vertx/vertx-core
public AddressResolverOptions(AddressResolverOptions other) {
this.hostsPath = other.hostsPath;
this.hostsValue = other.hostsValue != null ? other.hostsValue.copy() : null;
this.servers = other.servers != null ? new ArrayList<>(other.servers) : null;
this.optResourceEnabled = other.optResourceEnabled;
this.cacheMinTimeToLive = other.cacheMinTimeToLive;
this.cacheMaxTimeToLive = other.cacheMaxTimeToLive;
this.cacheNegativeTimeToLive = other.cacheNegativeTimeToLive;
this.queryTimeout = other.queryTimeout;
this.maxQueries = other.maxQueries;
this.rdFlag = other.rdFlag;
this.searchDomains = other.searchDomains != null ? new ArrayList<>(other.searchDomains) : null;
this.ndots = other.ndots;
this.rotateServers = other.rotateServers;
}
代码示例来源:origin: eclipse-vertx/vert.x
void drainingServer(Handler<AsyncResult<NetServer>> listenHandler) {
server.connectHandler(sock -> {
assertFalse(sock.writeQueueFull());
sock.setWriteQueueMaxSize(1000);
Buffer buff = TestUtils.randomBuffer(10000);
//Send data until the buffer is full
vertx.setPeriodic(1, id -> {
sock.write(buff.copy());
if (sock.writeQueueFull()) {
vertx.cancelTimer(id);
sock.drainHandler(v -> {
assertFalse(sock.writeQueueFull());
// End test after a short delay to give the client some time to read the data
vertx.setTimer(100, id2 -> testComplete());
});
// Tell the client to resume
vertx.eventBus().send("client_resume", "");
}
});
}).listen(testAddress, listenHandler);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testClientDrainHandler() {
pausingServer((s) -> {
client.connect(testAddress, onSuccess(sock -> {
assertFalse(sock.writeQueueFull());
sock.setWriteQueueMaxSize(1000);
Buffer buff = TestUtils.randomBuffer(10000);
vertx.setPeriodic(1, id -> {
sock.write(buff.copy());
if (sock.writeQueueFull()) {
vertx.cancelTimer(id);
sock.drainHandler(v -> {
assertFalse(sock.writeQueueFull());
testComplete();
});
// Tell the server to resume
vertx.eventBus().send("server_resume", "");
}
});
}));
});
await();
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testCopy() throws Exception {
Buffer buff = TestUtils.randomBuffer(100);
assertEquals(buff, buff.copy());
Buffer copy = buff.getBuffer(0, buff.length());
assertEquals(buff, copy);
//Make sure they don't share underlying buffer
Buffer copy2 = buff.copy();
buff.setInt(0, 1);
assertEquals(copy, copy2);
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testClientWebsocketReceivePingExceedsMaxFrameSize() {
String pingBody = randomAlphaString(113);
Integer maxFrameSize = 64;
Buffer ping1 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(0, maxFrameSize));
Buffer ping2 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(maxFrameSize, pingBody.length()));
server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST).setMaxWebsocketFrameSize(maxFrameSize));
server.websocketHandler(ws -> {
}).listen(onSuccess(v -> {
client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> {
List<Buffer> pongs = new ArrayList<>();
ws.pongHandler(pong -> {
pongs.add(pong);
if (pongs.size() == 2) {
assertEquals(pongs, Arrays.asList(ping1, ping2));
testComplete();
}
});
try {
ws.writeFrame(new WebSocketFrameImpl(FrameType.PING, ping1.copy().getByteBuf(), false));
ws.writeFrame(new WebSocketFrameImpl(FrameType.PING, ping2.copy().getByteBuf(), true));
} catch(Throwable t) {
fail(t);
}
});
}));
await();
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testServerWebsocketReceivePongExceedsMaxFrameSize() {
String pingBody = randomAlphaString(113);
Integer maxFrameSize = 64;
Buffer ping1 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(0, maxFrameSize));
Buffer ping2 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(maxFrameSize, pingBody.length()));
server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST).setMaxWebsocketFrameSize(maxFrameSize));
server.websocketHandler(ws -> {
List<Buffer> pongs = new ArrayList<>();
ws.pongHandler(pong -> {
pongs.add(pong);
if (pongs.size() == 2) {
assertEquals(pongs, Arrays.asList(ping1, ping2));
testComplete();
}
});
}).listen(v -> {
client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> {
try {
ws.writeFrame(new WebSocketFrameImpl(FrameType.PONG, ping1.copy().getByteBuf(), false));
ws.writeFrame(new WebSocketFrameImpl(FrameType.PONG, ping2.copy().getByteBuf(), true));
} catch(Throwable t) {
fail(t);
}
});
});
await();
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testClientWebsocketReceivePongExceedsMaxFrameSize() {
String pingBody = randomAlphaString(113);
Integer maxFrameSize = 64;
Buffer ping1 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(0, maxFrameSize));
Buffer ping2 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(maxFrameSize, pingBody.length()));
server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST).setMaxWebsocketFrameSize(maxFrameSize));
server.websocketHandler(ws -> {
try {
ws.writeFrame(new WebSocketFrameImpl(FrameType.PONG, ping1.copy().getByteBuf(), false));
ws.writeFrame(new WebSocketFrameImpl(FrameType.PONG, ping2.copy().getByteBuf(), true));
} catch(Throwable t) {
fail(t);
}
}).listen(v -> {
client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> {
List<Buffer> pongs = new ArrayList<>();
ws.pongHandler(pong -> {
pongs.add(pong);
if (pongs.size() == 2) {
assertEquals(pongs, Arrays.asList(ping1, ping2));
testComplete();
}
});
});
});
await();
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testServerWebsocketReceivePingExceedsMaxFrameSize() {
String pingBody = randomAlphaString(113);
Integer maxFrameSize = 64;
Buffer ping1 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(0, maxFrameSize));
Buffer ping2 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(maxFrameSize, pingBody.length()));
server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST).setMaxWebsocketFrameSize(maxFrameSize));
server.websocketHandler(ws -> {
}).listen(onSuccess(v -> {
client.websocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", ws -> {
List<Buffer> pongs = new ArrayList<>();
ws.pongHandler(pong -> {
pongs.add(pong);
if (pongs.size() == 2) {
assertEquals(pongs, Arrays.asList(ping1, ping2));
testComplete();
}
});
try {
ws.writeFrame(new WebSocketFrameImpl(FrameType.PING, ping1.copy().getByteBuf(), false));
ws.writeFrame(new WebSocketFrameImpl(FrameType.PING, ping2.copy().getByteBuf(), true));
} catch(Throwable t) {
fail(t);
}
});
}));
await();
}
代码示例来源:origin: io.vertx/vertx-core
void drainingServer(Handler<AsyncResult<NetServer>> listenHandler) {
server.connectHandler(sock -> {
assertFalse(sock.writeQueueFull());
sock.setWriteQueueMaxSize(1000);
Buffer buff = TestUtils.randomBuffer(10000);
//Send data until the buffer is full
vertx.setPeriodic(1, id -> {
sock.write(buff.copy());
if (sock.writeQueueFull()) {
vertx.cancelTimer(id);
sock.drainHandler(v -> {
assertFalse(sock.writeQueueFull());
// End test after a short delay to give the client some time to read the data
vertx.setTimer(100, id2 -> testComplete());
});
// Tell the client to resume
vertx.eventBus().send("client_resume", "");
}
});
}).listen(testAddress, listenHandler);
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testClientDrainHandler() {
pausingServer((s) -> {
client.connect(testAddress, onSuccess(sock -> {
assertFalse(sock.writeQueueFull());
sock.setWriteQueueMaxSize(1000);
Buffer buff = TestUtils.randomBuffer(10000);
vertx.setPeriodic(1, id -> {
sock.write(buff.copy());
if (sock.writeQueueFull()) {
vertx.cancelTimer(id);
sock.drainHandler(v -> {
assertFalse(sock.writeQueueFull());
testComplete();
});
// Tell the server to resume
vertx.eventBus().send("server_resume", "");
}
});
}));
});
await();
}
内容来源于网络,如有侵权,请联系作者删除!