本文整理匯總了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;
}