public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(2+grantedQos.length); os.writeShort(messageId); os.write(grantedQos); MQTTFrame frame = new MQTTFrame(); frame.commandType(TYPE); return frame.buffer(os.toBuffer()); } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }
public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(); QoS qos = qos(); if(qos != QoS.AT_MOST_ONCE) { os.writeShort(messageId); } for(Topic topic: topics) { MessageSupport.writeUTF(os, topic.name()); os.writeByte(topic.qos().ordinal()); } MQTTFrame frame = new MQTTFrame(); frame.header(header()); frame.commandType(TYPE); return frame.buffer(os.toBuffer()); } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }
static protected void writeUTF(DataByteArrayOutputStream os, Buffer buffer) throws IOException { os.writeShort(buffer.length); os.write(buffer); }
public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(2); os.writeByte(0); os.writeByte(code.ordinal()); MQTTFrame frame = new MQTTFrame(); frame.commandType(TYPE); return frame.buffer(os.toBuffer()); } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }
private void writePageFileHeader(int freePageExtent) throws IOException { DataByteArrayOutputStream os = new DataByteArrayOutputStream(); os.write(HAWT_DB_PAGE_FILE_MAGIC); os.writeInt(freePageExtent); os.writeInt(headerSize); os.writeShort(pageSize); os.close(); mappedFileFactory.getMemoryMappedFile().write(0, os.toBuffer()); }
public MQTTFrame encode() { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(2); os.writeShort(messageId); MQTTFrame frame = new MQTTFrame(); frame.commandType(messageType()); return frame.buffer(os.toBuffer()); } catch (IOException e) { throw new RuntimeException("The impossible happened"); } }
Location perform(RandomAccessFile file, ReplicationTarget replicator, boolean checksum) throws IOException { DataByteArrayOutputStream buffer = new DataByteArrayOutputStream(size); boolean forceToDisk = false; WriteCommand latest = null; buffer.reset(); buffer.writeInt(BATCH_CONTROL_RECORD_SIZE); buffer.writeByte(Location.BATCH_CONTROL_RECORD_TYPE); buffer.writeInt(0); buffer.write(BATCH_CONTROL_RECORD_MAGIC); buffer.writeLong(0); WriteCommand current = commands.next(); forceToDisk |= current.sync; buffer.writeInt(current.location.getSize()); buffer.writeByte(current.location.getType()); buffer.write(current.data.getData(), current.data.getOffset(), current.data.getLength()); latest = current; Buffer sequence = buffer.toBuffer(); buffer.reset(); buffer.skip(Journal.HEADER_SIZE); buffer.writeInt(sequence.getLength() - Journal.HEADER_SIZE - Journal.BATCH_SIZE); buffer.skip(Journal.BATCH_CONTROL_RECORD_MAGIC.length); if (checksum) { Checksum adler32 = new Adler32(); adler32.update(sequence.getData(), sequence.getOffset() + Journal.BATCH_CONTROL_RECORD_SIZE, sequence.getLength() - Journal.BATCH_CONTROL_RECORD_SIZE); buffer.writeLong(adler32.getValue());
Buffer encode() { try { os.reset(); os.write(magic); os.writeLong(base_revision); os.writeInt(page_size); os.writeInt(free_list_page); os.writeInt(pessimistic_recovery_page); os.writeInt(optimistic_recovery_page); int length = os.position(); byte[] data = os.getData(); CRC32 checksum = new CRC32(); checksum.update(data, 0, length); os.position((FILE_HEADER_SIZE / 2) - 8); os.writeLong(checksum.getValue()); System.arraycopy(data, 0, data, FILE_HEADER_SIZE / 2, length); os.position(FILE_HEADER_SIZE / 2 - 8); os.writeLong(checksum.getValue()); return os.toBuffer(); } catch (IOException e) { throw new RuntimeException(e); } }
private MessagePB.Bean createMessagePB(Message message, long messageKey) throws IOException { DataByteArrayOutputStream mos = new DataByteArrayOutputStream(); mos.writeBoolean(TIGHT_ENCODING); mos.writeVarInt(OPENWIRE_VERSION); wireformat.marshal(message, mos); MessagePB.Bean messageRecord = new MessagePB.Bean(); messageRecord.setCodec(codec_id); messageRecord.setMessageKey(messageKey); messageRecord.setSize(message.getSize()); messageRecord.setValue(mos.toBuffer()); return messageRecord; }
public int hashNode(N node, int i) { try { DataByteArrayOutputStream os = new DataByteArrayOutputStream(); nodeCodec.encode(node, os); os.write(':'); os.writeInt(i); return hash(os.toBuffer()); } catch (IOException e) { throw new RuntimeException(e); } }
public Buffer marshallKey(String key) throws IOException { DataByteArrayOutputStream baos = new DataByteArrayOutputStream(); keyCodec.encode(key, baos); return baos.toBuffer(); }
protected void looseMarshalByteArray(OpenWireFormat wireFormat, byte[] data, DataByteArrayOutputStream dataOut) throws IOException { dataOut.writeBoolean(data != null); if (data != null) { dataOut.writeInt(data.length); dataOut.write(data); } }
protected void looseMarshalString(UTF8Buffer value, DataByteArrayOutputStream dataOut) throws IOException { dataOut.writeBoolean(value != null); if (value != null) { dataOut.writeShort(value.length); dataOut.write(value); } }
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataByteArrayOutputStream dataOut) throws IOException { BaseCommand info = (BaseCommand)o; super.looseMarshal(wireFormat, o, dataOut); dataOut.writeInt(info.getCommandId()); dataOut.writeBoolean(info.isResponseRequired()); } }
public void tightMarshalLong2(OpenWireFormat wireFormat, long o, DataByteArrayOutputStream dataOut, BooleanStream bs) throws IOException { if (bs.readBoolean()) { if (bs.readBoolean()) { dataOut.writeLong(o); } else { dataOut.writeInt((int)o); } } else { if (bs.readBoolean()) { dataOut.writeShort((int)o); } } }
public static void marshalPrimitiveList(List list, DataByteArrayOutputStream out) throws IOException { out.writeInt(list.size()); for (Iterator iter = list.iterator(); iter.hasNext();) { Object element = (Object) iter.next(); marshalPrimitive(out, element); } }
@Override protected void encode(Object value) throws IOException { MQTTFrame frame = (MQTTFrame) value; nextWriteBuffer.write(frame.header()); int remaining = 0; for(Buffer buffer : frame.buffers) { remaining += buffer.length; } do { byte digit = (byte) (remaining & 0x7F); remaining >>>= 7; if (remaining > 0) { digit |= 0x80; } nextWriteBuffer.write(digit); } while (remaining > 0); for(Buffer buffer : frame.buffers) { nextWriteBuffer.write(buffer.data, buffer.offset, buffer.length); } }