@Override public void write(DataOutput out) throws IOException { final byte[] segmentsBytes = HadoopDruidIndexerConfig.JSON_MAPPER.writeValueAsBytes(segments); out.writeInt(segmentsBytes.length); out.write(segmentsBytes); out.writeInt(locations.length); for (String location : locations) { out.writeUTF(location); } }
/** * Writes a boolean as a typed bytes sequence. * * @param b * the boolean to be written * @throws IOException */ public void writeBool(boolean b) throws IOException { out.write(Type.BOOL.code); out.writeBoolean(b); }
public void writeTo(DataOutput out) throws Exception { if(ip_addr != null) { byte[] address=ip_addr.getAddress(); // 4 bytes (IPv4) or 16 bytes (IPv6) out.writeByte(address.length); // 1 byte out.write(address, 0, address.length); if(ip_addr instanceof Inet6Address) out.writeInt(((Inet6Address)ip_addr).getScopeId()); } else { out.writeByte(0); } out.writeShort(port); }
public static void objectToStream(Object obj, DataOutput out) throws Exception { if(obj == null) { out.write(TYPE_NULL); return; out.write(TYPE_STREAMABLE); writeGenericStreamable((Streamable)obj,out); out.write(type); switch(type) { case TYPE_BOOLEAN: out.writeBoolean((Boolean)obj); break; case TYPE_BYTE: out.writeByte((Byte)obj); break; case TYPE_CHAR: if(Util.isAsciiString(str)) { int len=str.length(); out.write(TYPE_STRING); out.writeInt(len); for(int i=0; i < len; i++) out.write((byte)str.charAt(i)); out.write(TYPE_UTF_STRING); out.writeUTF(str); case TYPE_BYTEARRAY: byte[] buf=(byte[])obj;
protected void looseMarshalByteArray(OpenWireFormat wireFormat, byte[] data, DataOutput dataOut) throws IOException { dataOut.writeBoolean(data != null); if (data != null) { dataOut.writeInt(data.length); dataOut.write(data); } }
Integer.toHexString(flags)); out.writeShort(flags); out.writeShort(this.bits); out.write(this.distributedSystemId); if (versionIsShort) { out.writeShort(this.entryVersion & 0xffff); } else { out.writeInt(this.entryVersion); out.writeShort(this.regionVersionHighBytes); out.writeInt(this.regionVersionLowBytes); InternalDataSerializer.writeUnsignedVL(this.timeStamp, out); if (this.memberID != null && includeMember) {
@Override public void toData(DataOutput out) throws IOException { out.writeInt(this.managerPid); out.writeInt(this.managerStatus); out.writeInt(this.port); if (this.bindAddress == null) { out.writeByte(0); } else { byte[] address = this.bindAddress.getAddress(); out.writeByte(address.length); out.write(address, 0, address.length); } }
public static void writeDatum(DataOutput out, Object val) throws IOException { out.write(type); switch (type) { case DataType.LIST: List<?> list = (List<?>) val; int sz = list.size(); out.writeInt(sz); for (int i = 0; i < sz; i++) { writeDatum(out, list.get(i)); out.writeBoolean((Boolean) val); return; out.writeByte((Byte) val); return; String s = (String) val; byte[] utfBytes = s.getBytes(ReaderWriter.UTF8); out.writeInt(utfBytes.length); out.write(utfBytes); return; byte[] ba = (byte[]) val; out.writeInt(ba.length); out.write(ba); return;
/** * Write the contents of a buffer to an output stream. The bytes are copied from the current position * in the buffer. * @param out The output to write to * @param buffer The buffer to write from * @param length The number of bytes to write * @throws IOException For any errors writing to the output */ public static void writeTo(DataOutput out, ByteBuffer buffer, int length) throws IOException { if (buffer.hasArray()) { out.write(buffer.array(), buffer.position() + buffer.arrayOffset(), length); } else { int pos = buffer.position(); for (int i = pos; i < length + pos; i++) out.writeByte(buffer.get(i)); } }
public void write(DataOutput out) throws IOException { out.writeUTF(index); out.writeInt(shardId); out.writeBoolean(slice != null); if (slice != null) { out.writeInt(slice.id); out.writeInt(slice.max); } out.writeBoolean(serializedSettings != null); if (serializedSettings != null) { // same goes for settings byte[] utf = StringUtils.toUTF(serializedSettings); out.writeInt(utf.length); out.write(utf); } out.writeBoolean(serializedMapping != null); if (serializedMapping != null) { // avoid using writeUTF since the mapping can be longer than 65K byte[] utf = StringUtils.toUTF(serializedMapping); out.writeInt(utf.length); out.write(utf); } out.writeInt(locations.length); for (String location : locations) { out.writeUTF(location); } }
@Override public final void get(DataOutput out, int offset, int length) throws IOException { if (address <= addressLimit) { if (heapMemory != null) { out.write(heapMemory, offset, length); } else { while (length >= 8) { out.writeLong(getLongBigEndian(offset)); offset += 8; length -= 8; } while (length > 0) { out.writeByte(get(offset)); offset++; length--; } } } else { throw new IllegalStateException("segment has been freed"); } }
@Override public void toData(DataOutput out) throws IOException { out.writeBoolean(this.hasKeys); if (this.objectTypeArray != null) { int numObjects = this.objects.size(); out.writeInt(numObjects); for (int index = 0; index < numObjects; ++index) { Object value = this.objects.get(index); out.writeByte(KEY_NOT_AT_SERVER); } else if (objectType == EXCEPTION) { out.writeByte(EXCEPTION); } else { out.writeByte(OBJECT); out.write((byte[]) value); } else if (objectType == EXCEPTION) { out.writeInt(0);
/** * Writes a short as a typed bytes sequence. * * @param s * the short to be written * @throws IOException */ public void writeShort(short s) throws IOException { out.write(Type.SHORT.code); out.writeShort(s); }
public void marshal(DataOutput dataOut) throws IOException { if (arrayLimit < 64) { dataOut.writeByte(arrayLimit); } else if (arrayLimit < 256) { // max value of unsigned byte dataOut.writeByte(0xC0); dataOut.writeByte(arrayLimit); } else { dataOut.writeByte(0x80); dataOut.writeShort(arrayLimit); } dataOut.write(data, 0, arrayLimit); clear(); }
private int writeString(final DataOutput output, String string, final IdentityIntMap<Object> seen, final HashMap<String, String> stringCache, final int cnt) throws IOException { if (string == null) { output.write(ST_NULL); return cnt; } // make sure we never duplicate a string string = stringCache.computeIfAbsent(string, Function.identity()); final int idx = seen.get(string, - 1); final int distance = cnt - idx; if (idx == -1 || distance > (1 << 14) - 1) { seen.put(string, cnt); output.write(ST_NEW_STRING); output.writeUTF(string); return cnt + 1; } else { if (distance < 127) { output.writeByte(ST_BACKREF_NEAR | distance); } else { assert distance <= 0x3fff; output.writeByte(ST_BACKREF_FAR | distance >> 8); output.writeByte(distance); } return cnt; } }
public static void writeGenericStreamable(Streamable obj, DataOutput out) throws Exception { short magic_number; String classname; if(obj == null) { out.write(0); return; } out.write(1); magic_number=ClassConfigurator.getMagicNumber(obj.getClass()); out.writeShort(magic_number); if(magic_number == -1) { classname=obj.getClass().getName(); out.writeUTF(classname); } obj.writeTo(out); // write the contents }
/** * Write a binary representation of this feature vector to the given data output. * * @param out * the DataOutputStream or RandomAccessFile in which to write the binary representation of the feature vector. * @throws IOException * IOException */ public void writeTo(DataOutput out) throws IOException { if (byteValuedDiscreteFeatures != null) { out.write(byteValuedDiscreteFeatures); } if (shortValuedDiscreteFeatures != null) { for (int i = 0; i < shortValuedDiscreteFeatures.length; i++) { out.writeShort(shortValuedDiscreteFeatures[i]); } } if (continuousFeatures != null) { for (int i = 0; i < continuousFeatures.length; i++) { out.writeFloat(continuousFeatures[i]); } } }