public byte[] toBytes() throws IOException { DataOutputBuffer out = new DataOutputBuffer(); extent.write(out); out.writeLong(timestamp); out.writeUTF(server); out.writeUTF(filename); return Arrays.copyOf(out.getData(), out.getLength()); }
/** * Write an operation to the output stream * * @param op The operation to write * @throws IOException if an error occurs during writing. */ public void writeOp(FSEditLogOp op) throws IOException { int start = buf.getLength(); // write the op code first to make padding and terminator verification // work buf.writeByte(op.opCode.getOpCode()); buf.writeInt(0); // write 0 for the length first buf.writeLong(op.txid); op.writeFields(buf); int end = buf.getLength(); // write the length back: content of the op + 4 bytes checksum - op_code int length = end - start - 1; buf.writeInt(length, start + 1); checksum.reset(); checksum.update(buf.getData(), start, end-start); int sum = (int)checksum.getValue(); buf.writeInt(sum); } }
private void setSizeInternal(int size) { this.size = Math.max(1, size); try { seed = maskSeed(seed, this.size); dob.reset(); dob.writeLong(seed); } catch (IOException e) { throw new RuntimeException(e); } }
public byte[] toBytes() throws IOException { DataOutputBuffer out = new DataOutputBuffer(); extent.write(out); out.writeLong(timestamp); out.writeUTF(server); out.writeUTF(filename); return Arrays.copyOf(out.getData(), out.getLength()); }
public byte[] toBytes() throws IOException { DataOutputBuffer out = new DataOutputBuffer(); extent.write(out); out.writeLong(timestamp); out.writeUTF(server); out.writeUTF(filename); out.write(tabletId); out.write(logSet.size()); for (String s : logSet) { out.writeUTF(s); } return Arrays.copyOf(out.getData(), out.getLength()); }
/** * Write an operation to the output stream * * @param op The operation to write * @throws IOException if an error occurs during writing. */ public void writeOp(FSEditLogOp op) throws IOException { int start = buf.getLength(); buf.writeByte(op.opCode.getOpCode()); buf.writeLong(op.txid); op.writeFields(buf); int end = buf.getLength(); Checksum checksum = FSEditLog.getChecksumForWrite(); checksum.reset(); checksum.update(buf.getData(), start, end-start); int sum = (int)checksum.getValue(); buf.writeInt(sum); } }
@Override public byte[] serialize(TMessageSet payload) { DataOutputBuffer outBuffer = new DataOutputBuffer(); try { outBuffer.reset(); outBuffer.writeUTF(payload.getApp()); outBuffer.writeInt(payload.getNumMessages()); outBuffer.writeByte(payload.getCompression()); outBuffer.writeLong(payload.getCrc()); outBuffer.writeInt(payload.getMessages().length); outBuffer.write(payload.getMessages()); return ByteBuffer.wrap(outBuffer.getData(), 0, outBuffer.getLength()).array(); } catch (Exception e) { throw new RuntimeException("Failed to serialize TMessageSet: "+e.getMessage(), e); } finally { Closeables.closeQuietly(outBuffer); } }
/** * Write an operation to the output stream * * @param op The operation to write * @throws IOException if an error occurs during writing. */ public void writeOp(FSEditLogOp op) throws IOException { int start = buf.getLength(); // write the op code first to make padding and terminator verification // work buf.writeByte(op.opCode.getOpCode()); buf.writeInt(0); // write 0 for the length first buf.writeLong(op.txid); op.writeFields(buf); int end = buf.getLength(); // write the length back: content of the op + 4 bytes checksum - op_code int length = end - start - 1; buf.writeInt(length, start + 1); checksum.reset(); checksum.update(buf.getData(), start, end-start); int sum = (int)checksum.getValue(); buf.writeInt(sum); } }
/** * Write an operation to the output stream * * @param op The operation to write * @throws IOException if an error occurs during writing. */ public void writeOp(FSEditLogOp op) throws IOException { int start = buf.getLength(); // write the op code first to make padding and terminator verification // work buf.writeByte(op.opCode.getOpCode()); buf.writeInt(0); // write 0 for the length first buf.writeLong(op.txid); op.writeFields(buf); int end = buf.getLength(); // write the length back: content of the op + 4 bytes checksum - op_code int length = end - start - 1; buf.writeInt(length, start + 1); checksum.reset(); checksum.update(buf.getData(), start, end-start); int sum = (int)checksum.getValue(); buf.writeInt(sum); } }
DataOutputBuffer outBuf = new DataOutputBuffer(); token.writeInOldFormat(outBuf); outBuf.writeLong(42); // renewDate inBuf.reset(outBuf.getData(), 0, outBuf.getLength());
DataOutputBuffer outBuf = new DataOutputBuffer(); token.writeInOldFormat(outBuf); outBuf.writeLong(42); // renewDate inBuf.reset(outBuf.getData(), 0, outBuf.getLength()); } else {