本文整理了Java中java.io.DataOutputStream.writeLong()
方法的一些代码示例,展示了DataOutputStream.writeLong()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataOutputStream.writeLong()
方法的具体详情如下:
包路径:java.io.DataOutputStream
类名称:DataOutputStream
方法名:writeLong
[英]Writes a long
to the underlying output stream as eight bytes, high byte first. In no exception is thrown, the counter written
is incremented by 8
.
[中]将long
作为八个字节写入基础输出流,高字节优先。在没有引发异常的情况下,计数器written
将递增8
。
代码示例来源:origin: apache/kafka
static void writeHeader(DataOutputStream out, long offset, int size) throws IOException {
out.writeLong(offset);
out.writeInt(size);
}
代码示例来源:origin: redisson/redisson
public void write(DataOutputStream out) throws IOException {
out.writeByte(tag);
out.writeLong(value);
}
代码示例来源:origin: stackoverflow.com
ByteArrayOutputStream ba = new ByteArrayOutputStream(16);
DataOutputStream da = new DataOutputStream(ba);
da.writeLong(uuid.getMostSignificantBits());
da.writeLong(uuid.getLeastSignificantBits());
return ba.toByteArray();
代码示例来源:origin: apache/geode
public GFSnapshotExporter(File out, String region, InternalCache cache) throws IOException {
this.cache = cache;
FileOutputStream fos = new FileOutputStream(out);
fc = fos.getChannel();
dos = new DataOutputStream(new BufferedOutputStream(fos));
// write snapshot version
dos.writeByte(SNAP_VER_2);
// write format type
dos.write(SNAP_FMT);
// write temporary pdx location in bytes 4-11
dos.writeLong(-1);
// write region name
dos.writeUTF(region);
}
代码示例来源:origin: greenrobot/essentials
@Test
public void testUpdateLong() throws Exception {
long input = Long.MIN_VALUE + 123456789;
ByteArrayOutputStream out = new ByteArrayOutputStream();
new DataOutputStream(out).writeLong(input);
long expected = getHashAndReset(out);
primitiveDataChecksum.updateLong(input);
Assert.assertEquals(expected, primitiveDataChecksum.getValue());
}
代码示例来源:origin: google/j2objc
/**
* Writes this {@code BloomFilter} to an output stream, with a custom format (not Java
* serialization). This has been measured to save at least 400 bytes compared to regular
* serialization.
*
* <p>Use {@linkplain #readFrom(InputStream, Funnel)} to reconstruct the written BloomFilter.
*/
public void writeTo(OutputStream out) throws IOException {
// Serial form:
// 1 signed byte for the strategy
// 1 unsigned byte for the number of hash functions
// 1 big endian int, the number of longs in our bitset
// N big endian longs of our bitset
DataOutputStream dout = new DataOutputStream(out);
dout.writeByte(SignedBytes.checkedCast(strategy.ordinal()));
dout.writeByte(UnsignedBytes.checkedCast(numHashFunctions)); // note: checked at the c'tor
dout.writeInt(bits.data.length());
for (int i = 0; i < bits.data.length(); i++) {
dout.writeLong(bits.data.get(i));
}
}
代码示例来源:origin: apache/nifi
@Override
public void serialize(final Long value, final OutputStream out) throws SerializationException, IOException {
final DataOutputStream dos = new DataOutputStream(out);
dos.writeLong(value);
}
代码示例来源:origin: btraceio/btrace
private static void writeLdc(LdcInsnNode lin, DataOutputStream dos) throws IOException {
Object o = lin.cst;
if (o instanceof Integer) {
dos.writeShort(1);
dos.writeInt((Integer)o);
} else if (o instanceof Float) {
dos.writeShort(2);
dos.writeFloat((Float)o);
} else if (o instanceof Long) {
dos.writeShort(3);
dos.writeLong((Long)o);
} else if (o instanceof Double) {
dos.writeShort(4);
dos.writeDouble((Double)o);
} else if (o instanceof String) {
dos.writeShort(5);
dos.writeUTF((String)o);
} else if (o instanceof Type) {
dos.writeShort(6);
dos.writeUTF(((Type)o).getDescriptor());
} else {
dos.writeShort(0);
}
}
代码示例来源:origin: apache/kafka
out.writeInt((int) (crc & 0xffffffffL));
out.writeByte(magic);
out.writeByte(attributes);
out.writeLong(timestamp);
out.writeInt(-1);
} else {
int size = key.remaining();
out.writeInt(size);
Utils.writeTo(out, key, size);
代码示例来源:origin: apache/nifi
@Override
public <K, V> boolean replace(AtomicCacheEntry<K, V, Long> entry, Serializer<K> keySerializer, Serializer<V> valueSerializer) throws IOException {
return withCommsSession(session -> {
validateProtocolVersion(session, 2);
final DataOutputStream dos = new DataOutputStream(session.getOutputStream());
dos.writeUTF("replace");
serialize(entry.getKey(), keySerializer, dos);
dos.writeLong(entry.getRevision().orElse(0L));
serialize(entry.getValue(), valueSerializer, dos);
dos.flush();
// read response
final DataInputStream dis = new DataInputStream(session.getInputStream());
return dis.readBoolean();
});
}
代码示例来源:origin: robovm/robovm
output.writeUTF(classDesc.getName());
output.writeLong(classDesc.getSerialVersionUID());
byte flags = classDesc.getFlags();
output.writeByte(flags);
if ((SC_ENUM | SC_SERIALIZABLE) != classDesc.getFlags()) {
writeFieldDescriptors(classDesc, externalizable);
代码示例来源:origin: stackoverflow.com
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
dos.writeLong(someLong);
dos.close();
byte[] longBytes = baos.toByteArray();
代码示例来源:origin: apache/incubator-druid
/**
* Serialize a bloom filter
*
* @param out output stream to write to
* @param bloomFilter BloomKFilter that needs to be seralized
*/
public static void serialize(OutputStream out, BloomKFilter bloomFilter) throws IOException
{
/**
* Serialized BloomKFilter format:
* 1 byte for the number of hash functions.
* 1 big endian int(That is how OutputStream works) for the number of longs in the bitset
* big endina longs in the BloomKFilter bitset
*/
DataOutputStream dataOutputStream = new DataOutputStream(out);
dataOutputStream.writeByte(bloomFilter.k);
dataOutputStream.writeInt(bloomFilter.getBitSet().length);
for (long value : bloomFilter.getBitSet()) {
dataOutputStream.writeLong(value);
}
}
代码示例来源:origin: typ0520/fastdex
private static <T> T talkToServiceWithinPortForward(Communicator<T> communicator, int localPort) throws IOException {
Socket socket = new Socket(LOCAL_HOST, localPort);
DataInputStream input = new DataInputStream(socket.getInputStream());
DataOutputStream output = new DataOutputStream(socket.getOutputStream());
output.writeLong(ProtocolConstants.PROTOCOL_IDENTIFIER);
output.writeInt(ProtocolConstants.PROTOCOL_VERSION);
socket.setSoTimeout(2 * 1000); // Allow up to 2 seconds before timing out
int version = input.readInt();
if (version != ProtocolConstants.PROTOCOL_VERSION) {
String msg = String.format(Locale.US, "Client and server protocol versions don't match (%1$d != %2$d)", version, ProtocolConstants.PROTOCOL_VERSION);
throw new IOException(msg);
}
socket.setSoTimeout(communicator.getTimeout());
T value = communicator.communicate(input, output);
output.writeInt(ProtocolConstants.MESSAGE_EOF);
return value;
}
}
代码示例来源:origin: apache/incubator-pinot
public static void persistCreationMeta(File indexDir, long crc, long creationTime)
throws IOException {
File segmentDir = SegmentDirectoryPaths.findSegmentDirectory(indexDir);
File creationMetaFile = new File(segmentDir, V1Constants.SEGMENT_CREATION_META);
try (DataOutputStream output = new DataOutputStream(new FileOutputStream(creationMetaFile))) {
output.writeLong(crc);
output.writeLong(creationTime);
}
}
代码示例来源:origin: apache/nifi
@Override
public void serializeRecord(final StateMapUpdate record, final DataOutputStream out) throws IOException {
out.writeUTF(record.getComponentId());
out.writeUTF(record.getUpdateType().name());
if (record.getUpdateType() == UpdateType.DELETE) {
return;
}
final StateMap stateMap = record.getStateMap();
final long recordVersion = stateMap.getVersion();
out.writeLong(recordVersion);
final Map<String, String> map = stateMap.toMap();
out.writeInt(map.size());
for (final Map.Entry<String, String> entry : map.entrySet()) {
final boolean hasKey = entry.getKey() != null;
final boolean hasValue = entry.getValue() != null;
out.writeBoolean(hasKey);
if (hasKey) {
out.writeUTF(entry.getKey());
}
out.writeBoolean(hasValue);
if (hasValue) {
out.writeUTF(entry.getValue());
}
}
}
代码示例来源:origin: apache/drill
private void writeAdditionalPayload(final DataOutputStream out) throws IOException {
boolean isFileIdLong = fileKey instanceof Long, isFileIdWritable = fileKey instanceof Writable;
int flags = (hasBase ? BASE_FLAG : 0) |
(isOriginal ? ORIGINAL_FLAG : 0) |
(hasFooter ? FOOTER_FLAG : 0) |
(isFileIdLong ? HAS_LONG_FILEID_FLAG : 0) |
(isFileIdWritable ? HAS_SYNTHETIC_FILEID_FLAG : 0);
out.writeByte(flags);
out.writeInt(deltas.size());
for(AcidInputFormat.DeltaMetaData delta: deltas) {
delta.write(out);
}
if (hasFooter) {
OrcProto.FileTail fileTail = orcTail.getMinimalFileTail();
byte[] tailBuffer = fileTail.toByteArray();
int tailLen = tailBuffer.length;
WritableUtils.writeVInt(out, tailLen);
out.write(tailBuffer);
}
if (isFileIdLong) {
out.writeLong(((Long)fileKey).longValue());
} else if (isFileIdWritable) {
((Writable)fileKey).write(out);
}
out.writeLong(fileLen);
}
代码示例来源:origin: org.javassist/javassist
@Override
public void write(DataOutputStream out) throws IOException
{
out.writeByte(tag);
out.writeLong(value);
}
代码示例来源:origin: EngineHub/WorldEdit
private void writeLongArrayTagPayload(LongArrayTag tag) throws IOException {
long[] data = tag.getValue();
os.writeInt(data.length);
for (long aData : data) {
os.writeLong(aData);
}
}
代码示例来源:origin: addthis/stream-lib
public static byte[] serialize(CountMinSketch sketch) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream s = new DataOutputStream(bos);
try {
s.writeLong(sketch.size);
s.writeInt(sketch.depth);
s.writeInt(sketch.width);
for (int i = 0; i < sketch.depth; ++i) {
s.writeLong(sketch.hashA[i]);
for (int j = 0; j < sketch.width; ++j) {
s.writeLong(sketch.table[i][j]);
}
}
return bos.toByteArray();
} catch (IOException e) {
// Shouldn't happen
throw new RuntimeException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!