本文整理汇总了Java中com.addthis.basis.util.LessBytes.writeBytes方法的典型用法代码示例。如果您正苦于以下问题:Java LessBytes.writeBytes方法的具体用法?Java LessBytes.writeBytes怎么用?Java LessBytes.writeBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.addthis.basis.util.LessBytes
的用法示例。
在下文中一共展示了LessBytes.writeBytes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encode
import com.addthis.basis.util.LessBytes; //导入方法依赖的package包/类
private DatagramPacket encode() throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
MeshyServer[] members = group.getMembers();
ArrayList<MeshyServer> readyList = Lists.newArrayList(members);
LessBytes.writeInt(readyList.size(), out);
for (MeshyServer meshy : readyList) {
LessBytes.writeString(meshy.getUUID(), out);
PeerService.encodeAddress(meshy.getLocalAddress(), out);
}
if (secret != null) {
LessBytes.writeString(secret, out);
}
byte[] raw = out.toByteArray();
CRC32 crc = new CRC32();
crc.update(raw);
out = new ByteArrayOutputStream();
LessBytes.writeBytes(raw, out);
LessBytes.writeLength(crc.getValue(), out);
DatagramPacket p = new DatagramPacket(out.toByteArray(), out.size());
p.setAddress(InetAddress.getByAddress(new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 255}));
p.setPort(port);
return p;
}
示例2: test1
import com.addthis.basis.util.LessBytes; //导入方法依赖的package包/类
public static void test1(int len) throws IOException {
byte[] b = new byte[len];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
LessBytes.writeBytes(b, bos);
log.info("{} encoded to {}", b.length, bos.size());
ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray());
byte[] o = LessBytes.readBytes(bin);
log.info("decoded to {}", o.length);
}
示例3: encodeAddress
import com.addthis.basis.util.LessBytes; //导入方法依赖的package包/类
public static void encodeAddress(InetSocketAddress addr, OutputStream out) throws IOException {
LessBytes.writeBytes(addr.getAddress().getAddress(), out);
LessBytes.writeInt(addr.getPort(), out);
}
示例4: encodeValue
import com.addthis.basis.util.LessBytes; //导入方法依赖的package包/类
/**
* encode a single value to a stream
*/
public static void encodeValue(ValueObject val, OutputStream out, ClassIndexMap classIndex) throws IOException {
if (val == null) {
out.write(TYPE.NULL.val);
return;
}
ValueObject.TYPE objectType = val.getObjectType();
switch (objectType) {
case CUSTOM:
ValueCustom custom = val.asCustom();
Class<? extends ValueObject> type = custom.getClass();
Integer classID = classIndex.getObjectIndex(type);
if (classID == null) {
classID = classIndex.createObjectIndex(type);
out.write(TYPE.CUSTOM_CLASS.val);
LessBytes.writeLength(classID, out);
LessBytes.writeString(type.getName(), out);
} else {
out.write(TYPE.CUSTOM_INDEX.val);
LessBytes.writeLength(classID, out);
}
encodeValue(custom.asMap(), out, classIndex);
break;
case MAP:
ValueMap map = val.asMap();
out.write(TYPE.MAP.val);
LessBytes.writeLength(map.size(), out);
for (ValueMapEntry e : map) {
encodeValue(ValueFactory.create(e.getKey()), out, classIndex);
encodeValue(e.getValue(), out, classIndex);
}
break;
case ARRAY:
out.write(TYPE.ARRAY.val);
ValueArray arr = val.asArray();
LessBytes.writeLength(arr.size(), out);
for (ValueObject vo : arr) {
encodeValue(vo, out, classIndex);
}
break;
case STRING:
out.write(TYPE.STRING.val);
LessBytes.writeString(val.asString().asNative(), out);
break;
case BYTES:
out.write(TYPE.BYTES.val);
LessBytes.writeBytes(val.asBytes().asNative(), out);
break;
case INT:
long lv = val.asLong().getLong();
// over 2^48, direct bytes are more efficient
if (lv > 281474976710656L) {
out.write(TYPE.LONG_BIG.val);
LessBytes.writeLong(lv, out);
break;
}
if (lv >= 0) {
out.write(TYPE.LONG.val);
} else {
out.write(TYPE.LONG_NEG.val);
lv = -lv;
}
LessBytes.writeLength(lv, out);
break;
case FLOAT:
long dv = Double.doubleToLongBits(val.asDouble().getDouble());
out.write(TYPE.DOUBLE.val);
LessBytes.writeLong(dv, out);
break;
default:
log.error("Unknown object type " + objectType);
throw new IOException("Unknown object type " + objectType);
}
}
示例5: write
import com.addthis.basis.util.LessBytes; //导入方法依赖的package包/类
@Override public void write(Bundle row) throws IOException {
LessBytes.writeBytes(DataChannelCodec.encodeBundle(row, fieldMap, classMap), out);
}