Sha256: 479780dd42a99d099d138a0c7a952a464eada1056fa9f5f621a9b29b8760cf48
Contents?: true
Size: 1.79 KB
Versions: 16
Compression:
Stored size: 1.79 KB
Contents
package org.embulk.executor.mapreduce; import java.io.IOException; import java.io.DataOutput; import java.io.DataInput; import org.apache.hadoop.io.WritableComparable; import org.apache.hadoop.io.WritableUtils; import org.apache.hadoop.io.WritableComparator; import org.embulk.spi.Buffer; public class BufferWritable implements WritableComparable<BufferWritable> { private Buffer buffer; public BufferWritable() { } public void set(Buffer buffer) { this.buffer = buffer; } public Buffer get() { return buffer; } @Override public void write(DataOutput out) throws IOException { WritableUtils.writeVInt(out, buffer.limit()); out.write(buffer.array(), buffer.offset(), buffer.limit()); } @Override public void readFields(DataInput in) throws IOException { int size = WritableUtils.readVInt(in); byte[] bytes = new byte[size]; // TODO usa buffer allocator? in.readFully(bytes, 0, size); Buffer newBuffer = Buffer.wrap(bytes); if (buffer != null) { buffer.release(); } buffer = newBuffer; } @Override public int compareTo(BufferWritable o) { return WritableComparator.compareBytes( buffer.array(), buffer.offset(), buffer.limit(), o.buffer.array(), o.buffer.offset(), o.buffer.limit()); } @Override public boolean equals(Object other) { if (!(other instanceof BufferWritable)) { return false; } BufferWritable o = (BufferWritable) other; if (buffer == null) { return o.buffer == null; } return buffer.equals(o.buffer); } @Override public int hashCode() { return buffer.hashCode(); } }
Version data entries
16 entries across 16 versions & 1 rubygems