本文整理汇总了Java中io.protostuff.Output.writeByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java Output.writeByteArray方法的具体用法?Java Output.writeByteArray怎么用?Java Output.writeByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.protostuff.Output
的用法示例。
在下文中一共展示了Output.writeByteArray方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTo
import io.protostuff.Output; //导入方法依赖的package包/类
@Override
public void writeTo(Output output, int number, short[] value,
boolean repeated) throws IOException
{
writes++;
byte[] buffer = new byte[value.length * 2];
for (int i = 0, offset = 0; i < value.length; i++)
{
short s = value[i];
buffer[offset++] = (byte) ((s >>> 8) & 0xFF);
buffer[offset++] = (byte) ((s >>> 0) & 0xFF);
}
output.writeByteArray(number, buffer, repeated);
}
示例2: writeTo
import io.protostuff.Output; //导入方法依赖的package包/类
@Override
public void writeTo(Output output, Message message) throws IOException {
// Write headers
if (!message.headers().isEmpty()) {
for (Map.Entry<String, String> headerEntry : message.headers().entrySet()) {
if (headerEntry.getKey() != null && headerEntry.getValue() != null) {
output.writeString(HEADER_KEYS_FIELD_NUMBER, headerEntry.getKey(), true);
output.writeString(HEADER_VALUES_FIELD_NUMBER, headerEntry.getValue(), true);
}
}
}
// Write data
Object originalData = message.data();
if (originalData != null) {
if (originalData instanceof byte[]) {
// Write data byte array as is
output.writeByteArray(DATA_FIELD_NUMBER, (byte[]) originalData, false);
} else {
// Write data class as an additional header
Class<?> dataClass = originalData.getClass();
output.writeString(HEADER_KEYS_FIELD_NUMBER, Message.HEADER_DATA_TYPE, true);
output.writeString(HEADER_VALUES_FIELD_NUMBER, dataClass.getName(), true);
// Write data as serialized byte array
Schema dataSchema = RuntimeSchema.getSchema(dataClass);
try (RecyclableLinkedBuffer rlb = recyclableLinkedBuffer.get()) {
byte[] array = ProtostuffIOUtil.toByteArray(originalData, dataSchema, rlb.buffer());
output.writeByteArray(DATA_FIELD_NUMBER, array, false);
}
}
}
// Write sender
Address sender = message.sender();
if (sender != null) {
output.writeString(SENDER_HOST_FIELD_NUMBER, sender.host(), false);
output.writeInt32(SENDER_PORT_FIELD_NUMBER, sender.port(), false);
}
}
示例3: writeTo
import io.protostuff.Output; //导入方法依赖的package包/类
@Override
public void writeTo(Output output, Object value) throws IOException
{
byte[][] array = (byte[][]) value;
output.writeUInt32(ID_ARRAY_LEN, array.length, false);
int nullCount = 0;
for (int i = 0, len = array.length; i < len; i++)
{
byte[] v = array[i];
if (v != null)
{
if (nullCount != 0)
{
output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
nullCount = 0;
}
output.writeByteArray(ID_ARRAY_DATA, v, true);
}
else if (ALLOW_NULL_ARRAY_ELEMENT)
{
nullCount++;
}
}
// if last element is null
if (nullCount != 0)
output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
}
示例4: writeTo
import io.protostuff.Output; //导入方法依赖的package包/类
@Override
public void writeTo(Output output, Object value) throws IOException
{
byte[][] array = (byte[][]) value;
output.writeInt32(ID_ARRAY_LEN, array.length, false);
int nullCount = 0;
for (int i = 0, len = array.length; i < len; i++)
{
byte[] v = array[i];
if (v != null)
{
if (nullCount != 0)
{
output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
nullCount = 0;
}
output.writeByteArray(ID_ARRAY_DATA, v, true);
}
else if (allowNullArrayElement)
{
nullCount++;
}
}
// if last element is null
if (nullCount != 0)
output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
}
示例5: writeTo
import io.protostuff.Output; //导入方法依赖的package包/类
@Override
public void writeTo(Output output, int number, byte[] value,
boolean repeated) throws IOException
{
output.writeByteArray(number, value, repeated);
}