本文整理了Java中io.vertx.core.buffer.Buffer.setByte()
方法的一些代码示例,展示了Buffer.setByte()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.setByte()
方法的具体详情如下:
包路径:io.vertx.core.buffer.Buffer
类名称:Buffer
方法名:setByte
[英]Sets the byte at position pos in the Buffer to the value b.
The buffer will expand as necessary to accommodate any value written.
[中]将缓冲区中位置pos处的字节设置为值b。
缓冲区将根据需要扩展以容纳任何写入的值。
代码示例来源:origin: eclipse-vertx/vert.x
private void testSetByte(Buffer buff) throws Exception {
for (int i = 0; i < numSets; i++) {
buff.setByte(i, (byte) i);
}
for (int i = 0; i < numSets; i++) {
assertEquals(i, buff.getByte(i));
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testSetBytesWithOffsetAndLen() throws Exception {
int bytesLen = 100;
byte[] bytes = TestUtils.randomByteArray(bytesLen);
int len = bytesLen - 2;
Buffer b = Buffer.buffer();
b.setByte(0, (byte) '0');
b.setBytes(1, bytes, 1, len);
assertEquals(b.length(), len + 1);
byte[] copy = new byte[len];
System.arraycopy(bytes, 1, copy, 0, len);
assertTrue(TestUtils.byteArraysEqual(copy, b.getBytes(1, b.length())));
b.setBytes(b.length(), bytes, 1, len);
assertEquals(b.length(), 2 * len + 1);
assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, (byte[]) null));
assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, null, 1, len));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testSetOutOfBounds() throws Exception {
Buffer b = Buffer.buffer(numSets);
assertIndexOutOfBoundsException(() -> b.setByte(-1, (byte) 0));
assertIndexOutOfBoundsException(() -> b.setInt(-1, 0));
assertIndexOutOfBoundsException(() -> b.setLong(-1, 0));
assertIndexOutOfBoundsException(() -> b.setDouble(-1, 0));
assertIndexOutOfBoundsException(() -> b.setFloat(-1, 0));
assertIndexOutOfBoundsException(() -> b.setShort(-1, (short) 0));
assertIndexOutOfBoundsException(() -> b.setBuffer(-1, b));
assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, -1, 0));
assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, 0, -1));
assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1)));
assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), -1, 0));
assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), 0, -1));
assertIndexOutOfBoundsException(() -> b.setString(-1, ""));
assertIndexOutOfBoundsException(() -> b.setString(-1, "", "UTF-8"));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testAppendByte2() throws Exception {
int bytesLen = 100;
Buffer b = Buffer.buffer(TestUtils.randomByteArray(bytesLen));
b.setByte(b.length(), (byte) 9);
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testSetBytesWithOffsetAndLen() throws Exception {
int bytesLen = 100;
byte[] bytes = TestUtils.randomByteArray(bytesLen);
int len = bytesLen - 2;
Buffer b = Buffer.buffer();
b.setByte(0, (byte) '0');
b.setBytes(1, bytes, 1, len);
assertEquals(b.length(), len + 1);
byte[] copy = new byte[len];
System.arraycopy(bytes, 1, copy, 0, len);
assertTrue(TestUtils.byteArraysEqual(copy, b.getBytes(1, b.length())));
b.setBytes(b.length(), bytes, 1, len);
assertEquals(b.length(), 2 * len + 1);
assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, (byte[]) null));
assertNullPointerException(() -> Buffer.buffer(150).setBytes(0, null, 1, len));
}
代码示例来源:origin: eclipse-vertx/vert.x
private void testSetBufferWithOffsetAndLen(Function<byte[], Buffer> bufferFactory) throws Exception {
int bytesLen = 100;
byte[] bytes = TestUtils.randomByteArray(bytesLen);
Buffer src = bufferFactory.apply(bytes);
int len = bytesLen - 2;
Buffer b = Buffer.buffer();
b.setByte(0, (byte) '0');
b.setBuffer(1, src, 1, len);
assertEquals(b.length(), len + 1);
byte[] copy = new byte[len];
System.arraycopy(bytes, 1, copy, 0, len);
assertTrue(TestUtils.byteArraysEqual(copy, b.getBytes(1, b.length())));
b.setBuffer(b.length(), src, 1, len);
assertEquals(b.length(), 2 * len + 1);
assertNullPointerException(() -> b.setBuffer(1, null));
assertNullPointerException(() -> b.setBuffer(1, null, 0, len));
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testSetOutOfBounds() throws Exception {
Buffer b = Buffer.buffer(numSets);
assertIndexOutOfBoundsException(() -> b.setByte(-1, (byte) 0));
assertIndexOutOfBoundsException(() -> b.setInt(-1, 0));
assertIndexOutOfBoundsException(() -> b.setLong(-1, 0));
assertIndexOutOfBoundsException(() -> b.setDouble(-1, 0));
assertIndexOutOfBoundsException(() -> b.setFloat(-1, 0));
assertIndexOutOfBoundsException(() -> b.setShort(-1, (short) 0));
assertIndexOutOfBoundsException(() -> b.setBuffer(-1, b));
assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, -1, 0));
assertIndexOutOfBoundsException(() -> b.setBuffer(0, b, 0, -1));
assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1)));
assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), -1, 0));
assertIndexOutOfBoundsException(() -> b.setBytes(-1, TestUtils.randomByteArray(1), 0, -1));
assertIndexOutOfBoundsException(() -> b.setString(-1, ""));
assertIndexOutOfBoundsException(() -> b.setString(-1, "", "UTF-8"));
}
代码示例来源:origin: io.vertx/vertx-core
private void testSetByte(Buffer buff) throws Exception {
for (int i = 0; i < numSets; i++) {
buff.setByte(i, (byte) i);
}
for (int i = 0; i < numSets; i++) {
assertEquals(i, buff.getByte(i));
}
}
代码示例来源:origin: com.jukusoft/vertx-binary-serializer
buf.setByte(_pos, (byte) (bool ? 0x01 : 0x02));
_pos += 1;
} else if (clazz == SChar.class) {
buf.setByte(_pos, b);
_pos += 1;
} else if (clazz == SBytes.class) {
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testAppendByte2() throws Exception {
int bytesLen = 100;
Buffer b = Buffer.buffer(TestUtils.randomByteArray(bytesLen));
b.setByte(b.length(), (byte) 9);
}
代码示例来源:origin: vert-x3/vertx-rx
/**
* Sets the <code>byte</code> at position <code>pos</code> in the Buffer to the value <code>b</code>.<p>
* The buffer will expand as necessary to accommodate any value written.
* @param pos
* @param b
* @return
*/
public io.vertx.rxjava.core.buffer.Buffer setByte(int pos, byte b) {
delegate.setByte(pos, b);
return this;
}
代码示例来源:origin: apiman/apiman
@Override
public void set(int index, byte b) {
nativeBuffer.setByte(index, b);
}
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* Sets the <code>byte</code> at position <code>pos</code> in the Buffer to the value <code>b</code>.<p>
* The buffer will expand as necessary to accommodate any value written.
* @param pos
* @param b
* @return
*/
public io.vertx.rxjava.core.buffer.Buffer setByte(int pos, byte b) {
delegate.setByte(pos, b);
return this;
}
代码示例来源:origin: net.consensys.cava/cava-bytes
@Override
public void set(int i, byte b) {
buffer.setByte(i, b);
}
代码示例来源:origin: pmlopes/vertx-bson-codec
public static void setByte(Buffer buffer, int pos, byte value) {
buffer.setByte(pos, value);
}
代码示例来源:origin: io.vertx/vertx-core
private void testSetBufferWithOffsetAndLen(Function<byte[], Buffer> bufferFactory) throws Exception {
int bytesLen = 100;
byte[] bytes = TestUtils.randomByteArray(bytesLen);
Buffer src = bufferFactory.apply(bytes);
int len = bytesLen - 2;
Buffer b = Buffer.buffer();
b.setByte(0, (byte) '0');
b.setBuffer(1, src, 1, len);
assertEquals(b.length(), len + 1);
byte[] copy = new byte[len];
System.arraycopy(bytes, 1, copy, 0, len);
assertTrue(TestUtils.byteArraysEqual(copy, b.getBytes(1, b.length())));
b.setBuffer(b.length(), src, 1, len);
assertEquals(b.length(), 2 * len + 1);
assertNullPointerException(() -> b.setBuffer(1, null));
assertNullPointerException(() -> b.setBuffer(1, null, 0, len));
}
代码示例来源:origin: com.jukusoft/vertx-binary-serializer
public static final Buffer serialize (SerializableObject obj) {
Buffer buf = Buffer.buffer();
if (obj.getClass().getAnnotation(MessageType.class) == null) {
throw new NoMessageTypeException("No message type annotation was found in class '" + obj.getClass().getCanonicalName() + "'!");
}
if (obj.getClass().getAnnotation(ProtocolVersion.class) == null) {
throw new NoProtocolVersionException("No protocol version annotation was found in class '" + obj.getClass().getCanonicalName() + "'!");
}
int _pos = 0;
MessageType msgType = obj.getClass().getAnnotation(MessageType.class);
if (msgType.type() == 0x00) {
throw new IllegalStateException("message type cannot 0x00, please correct annotation @MessageType in class '" + obj.getClass().getCanonicalName()+ "'!");
}
//add message type
buf.setByte(_pos, msgType.type());
_pos += 1;
//add message extended type
buf.setByte(_pos, msgType.extendedType());
_pos += 1;
//add protocol version
ProtocolVersion version = obj.getClass().getAnnotation(ProtocolVersion.class);
buf.setShort(_pos, version.value());
_pos += 2;
final int pos = _pos;
ExceptionUtils.executeWithoutIllegalAccessException(() -> serializeFields(buf, obj, pos));
return buf;
}
代码示例来源:origin: PegaSysEng/pantheon
/**
* Checks that modifying a wrapped array modifies the value itself, but only if within the wrapped
* slice.
*/
@Test
public void wrapBufferSliceReflectsUpdates() {
final Buffer buffer = Buffer.buffer(new byte[] {1, 2, 3, 4, 5});
final BytesValue value = wrapBuffer(buffer, 2, 2);
final BytesValue copy = value.copy();
assertEquals(2, value.size());
assertArrayEquals(Arrays.copyOfRange(buffer.getBytes(), 2, 4), value.extractArray());
// Modify within the wrapped slice. This should have modified the wrapped value but not its copy
buffer.setByte(2, (byte) 127);
buffer.setByte(3, (byte) 127);
assertArrayEquals(Arrays.copyOfRange(buffer.getBytes(), 2, 4), value.extractArray());
assertFalse(Arrays.equals(Arrays.copyOfRange(buffer.getBytes(), 2, 4), copy.extractArray()));
final BytesValue newCopy = value.copy();
// Modify the bytes outside of the wrapped slice and check this doesn't affect the value (that
// it is still equal to the copy from before the updates)
buffer.setByte(0, (byte) 127);
assertEquals(newCopy, value);
}
代码示例来源:origin: PegaSysEng/pantheon
/** Checks that modifying a wrapped buffer modifies the value itself. */
@Test
public void wrapBufferReflectsUpdates() {
final Buffer buffer = Buffer.buffer(new byte[] {1, 2, 3, 4, 5});
final BytesValue value = wrapBuffer(buffer);
assertEquals(buffer.length(), value.size());
assertArrayEquals(buffer.getBytes(), value.extractArray());
buffer.setByte(1, (byte) 127);
buffer.setByte(3, (byte) 127);
assertEquals(buffer.length(), value.size());
assertArrayEquals(buffer.getBytes(), value.extractArray());
}
内容来源于网络,如有侵权,请联系作者删除!