本文整理了Java中com.couchbase.client.deps.io.netty.buffer.ByteBuf.readBytes()
方法的一些代码示例,展示了ByteBuf.readBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.readBytes()
方法的具体详情如下:
包路径:com.couchbase.client.deps.io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:readBytes
[英]Transfers this buffer's data to a newly created buffer starting at the current readerIndex and increases the readerIndexby the number of the transferred bytes (= length). The returned buffer's readerIndex and writerIndex are 0 and length respectively.
[中]将此缓冲区的数据传输到从当前readerIndex开始的新创建的缓冲区,并将readerIndex增加传输的字节数(=长度)。返回的缓冲区的readerIndex和writerIndex分别为0和length。
代码示例来源:origin: apache/nifi
public static String getStringContent(Object content) {
if (content instanceof String) {
return (String) content;
} else if (content instanceof byte[]) {
return new String((byte[]) content, StandardCharsets.UTF_8);
} else if (content instanceof ByteBuf) {
final ByteBuf byteBuf = (ByteBuf) content;
byte[] bytes = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(bytes);
byteBuf.release();
return new String(bytes, StandardCharsets.UTF_8);
}
return content.toString();
}
代码示例来源:origin: apache/nifi
private <V> V deserialize(BinaryDocument doc, Deserializer<V> valueDeserializer) throws IOException {
if (doc == null) {
return null;
}
final ByteBuf byteBuf = doc.content();
final byte[] bytes = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(bytes);
byteBuf.release();
return valueDeserializer.deserialize(bytes);
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testBasicConvert() throws Exception {
Schema dataRecordSchema = SchemaBuilder.record("Data")
.fields()
.name("data").type().bytesType().noDefault()
.name("flags").type().intType().noDefault()
.endRecord();
Schema schema = SchemaBuilder.record("TestRecord")
.fields()
.name("key").type().stringType().noDefault()
.name("data").type(dataRecordSchema).noDefault()
.endRecord();
GenericData.Record testRecord = new GenericData.Record(schema);
String testContent = "hello world";
GenericData.Record dataRecord = new GenericData.Record(dataRecordSchema);
dataRecord.put("data", ByteBuffer.wrap(testContent.getBytes(Charset.forName("UTF-8"))));
dataRecord.put("flags", 0);
testRecord.put("key", "hello");
testRecord.put("data", dataRecord);
Converter<Schema, String, GenericRecord, TupleDocument> recordConverter = new AvroToCouchbaseTupleConverter();
TupleDocument returnDoc = recordConverter.convertRecord("", testRecord, null).iterator().next();
byte[] returnedBytes = new byte[returnDoc.content().value1().readableBytes()];
returnDoc.content().value1().readBytes(returnedBytes);
Assert.assertEquals(returnedBytes, testContent.getBytes(Charset.forName("UTF-8")));
int returnedFlags = returnDoc.content().value2();
Assert.assertEquals(returnedFlags, 0);
}
代码示例来源:origin: apache/incubator-gobblin
returnDoc.content().value1().readBytes(returnedBytes);
Assert.assertEquals(returnedBytes, testContent.getBytes(Charset.forName("UTF-8")));
代码示例来源:origin: com.couchbase.client/core-io
@Override
public ByteBuf readBytes(ByteBuf dst, int dstIndex, int length) {
buf.readBytes(dst, dstIndex, length);
return this;
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public ByteBuf readBytes(byte[] dst) {
buf.readBytes(dst);
return this;
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public ByteBuf readBytes(ByteBuf dst, int dstIndex, int length) {
buf.readBytes(dst, dstIndex, length);
return this;
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public ByteBuf readBytes(ByteBuf dst) {
buf.readBytes(dst);
return this;
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public ByteBuf readBytes(ByteBuf dst, int length) {
buf.readBytes(dst, length);
return this;
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public ByteBuf readBytes(OutputStream out, int length) throws IOException {
buf.readBytes(out, length);
return this;
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public ByteBuf readBytes(ByteBuf dst) {
buf.readBytes(dst);
return this;
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public ByteBuf readBytes(ByteBuf dst, int length) {
buf.readBytes(dst, length);
return this;
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public ByteBuf readBytes(OutputStream out, int length) throws IOException {
buf.readBytes(out, length);
return this;
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public ByteBuf readBytes(byte[] dst) {
checkReadableBytes(dst.length);
buffer.readBytes(dst);
return this;
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public ByteBuf readBytes(ByteBuf dst, int dstIndex, int length) {
checkReadableBytes(length);
buffer.readBytes(dst, dstIndex, length);
return this;
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public int read(byte[] dst, int dstIndex, int length) throws IOException {
int available = available();
if (available == 0) {
return -1;
}
length = Math.min(available, length);
buffer.readBytes(dst, dstIndex, length);
return length;
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public ByteBuf readBytes(int length) {
checkReadableBytes(length);
return buffer.readBytes(length);
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
public void readFully(byte[] b, int off, int len) throws IOException {
checkAvailable(len);
buffer.readBytes(b, off, len);
}
代码示例来源:origin: com.couchbase.client/core-io
@Override
protected void doWriteBytes(ByteBuf buf) throws Exception {
OutputStream os = this.os;
if (os == null) {
throw new NotYetConnectedException();
}
buf.readBytes(os, buf.readableBytes());
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
protected ByteArrayDocument doDecode(String id, ByteBuf content, long cas, int expiry, int flags,
ResponseStatus status) throws Exception {
if (!TranscoderUtils.hasBinaryFlags(flags)) {
throw new TranscodingException("Flags (0x" + Integer.toHexString(flags) + ") indicate non-binary " +
"document for id " + id + ", could not decode.");
}
byte[] data = new byte[content.readableBytes()];
content.readBytes(data);
return newDocument(id, expiry, data, cas);
}
内容来源于网络,如有侵权,请联系作者删除!