本文整理汇总了Java中io.netty.buffer.ByteBuf.resetWriterIndex方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.resetWriterIndex方法的具体用法?Java ByteBuf.resetWriterIndex怎么用?Java ByteBuf.resetWriterIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.resetWriterIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: persist
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public void persist(String exchangeName, Binding binding) throws BrokerException {
Connection connection = null;
PreparedStatement statement = null;
try {
connection = getConnection();
statement = connection.prepareStatement(RDBMSConstants.PS_INSERT_BINDING);
statement.setString(1, exchangeName);
statement.setString(2, binding.getQueue().getName());
statement.setString(3, binding.getRoutingKey());
FieldTable arguments = binding.getArguments();
byte[] bytes = new byte[(int) arguments.getSize()];
ByteBuf byteBuf = Unpooled.wrappedBuffer(bytes);
byteBuf.resetWriterIndex();
arguments.write(byteBuf);
statement.setBytes(4, bytes);
statement.executeUpdate();
connection.commit();
} catch (SQLException e) {
throw new BrokerException("Error occurred while storing binding " + binding, e);
} finally {
close(connection, statement);
}
}
示例2: prepareMetadata
import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private Metadata prepareMetadata(PreparedStatement metadataStmt, Message message) throws SQLException {
Metadata metadata = message.getMetadata();
metadataStmt.setLong(1, metadata.getInternalId());
metadataStmt.setString(2, metadata.getExchangeName());
metadataStmt.setString(3, metadata.getRoutingKey());
metadataStmt.setLong(4, metadata.getContentLength());
long size = metadata.getProperties().getSize() + metadata.getHeaders().getSize();
byte[] bytes = new byte[(int) size];
ByteBuf buffer = Unpooled.wrappedBuffer(bytes);
try {
buffer.resetWriterIndex();
metadata.getProperties().write(buffer);
metadata.getHeaders().write(buffer);
metadataStmt.setBytes(5, bytes);
metadataStmt.addBatch();
} finally {
buffer.release();
}
return metadata;
}