List of usage examples for org.apache.hadoop.io DataOutputBuffer getLength
public int getLength()
From source file:org.apache.accumulo.core.replication.ReplicationTarget.java
License:Apache License
/** * Convenience method to serialize a ReplicationTarget to {@link Text} using the {@link Writable} methods without caring about performance penalties due to * excessive object creation//from w ww .j a va2s.co m * * @return The serialized representation of the object */ public Text toText() { DataOutputBuffer buffer = new DataOutputBuffer(); try { this.write(buffer); } catch (IOException e) { throw new RuntimeException(e); } Text t = new Text(); // Throw it in a text for the mutation t.set(buffer.getData(), 0, buffer.getLength()); return t; }
From source file:org.apache.accumulo.core.replication.ReplicationTargetTest.java
License:Apache License
@Test public void writableOut() throws Exception { ReplicationTarget expected = new ReplicationTarget("foo", "bar", "1"); DataOutputBuffer buffer = new DataOutputBuffer(); expected.write(buffer);//from ww w .j a va2 s.c o m DataInputBuffer input = new DataInputBuffer(); input.reset(buffer.getData(), buffer.getLength()); ReplicationTarget actual = new ReplicationTarget(); actual.readFields(input); }
From source file:org.apache.accumulo.core.replication.ReplicationTargetTest.java
License:Apache License
@Test public void writableOutWithNulls() throws Exception { ReplicationTarget expected = new ReplicationTarget(null, null, null); DataOutputBuffer buffer = new DataOutputBuffer(); expected.write(buffer);//from w w w . ja va 2 s . com DataInputBuffer input = new DataInputBuffer(); input.reset(buffer.getData(), buffer.getLength()); ReplicationTarget actual = new ReplicationTarget(); actual.readFields(input); }
From source file:org.apache.accumulo.core.replication.ReplicationTargetTest.java
License:Apache License
@Test public void staticFromTextHelper() throws Exception { ReplicationTarget expected = new ReplicationTarget("foo", "bar", "1"); DataOutputBuffer buffer = new DataOutputBuffer(); expected.write(buffer);// www.j a va 2s . com Text t = new Text(); t.set(buffer.getData(), 0, buffer.getLength()); Assert.assertEquals(expected, ReplicationTarget.from(t)); }
From source file:org.apache.accumulo.core.replication.ReplicationTargetTest.java
License:Apache License
@Test public void staticToTextHelper() throws Exception { ReplicationTarget expected = new ReplicationTarget("foo", "bar", "1"); DataOutputBuffer buffer = new DataOutputBuffer(); expected.write(buffer);/* w ww . j a va 2 s .c o m*/ Text t = new Text(); t.set(buffer.getData(), 0, buffer.getLength()); Assert.assertEquals(t, expected.toText()); }
From source file:org.apache.accumulo.core.replication.ReplicationTargetTest.java
License:Apache License
@Test public void staticFromStringHelper() throws Exception { ReplicationTarget expected = new ReplicationTarget("foo", "bar", "1"); DataOutputBuffer buffer = new DataOutputBuffer(); expected.write(buffer);/*w w w .j a v a2 s . co m*/ Text t = new Text(); t.set(buffer.getData(), 0, buffer.getLength()); Assert.assertEquals(expected, ReplicationTarget.from(t.toString())); }
From source file:org.apache.accumulo.core.tabletserver.log.LogEntry.java
License:Apache License
public byte[] toBytes() throws IOException { DataOutputBuffer out = new DataOutputBuffer(); extent.write(out);/* w w w . j a v a 2 s .c o m*/ out.writeLong(timestamp); out.writeUTF(server); out.writeUTF(filename); return Arrays.copyOf(out.getData(), out.getLength()); }
From source file:org.apache.accumulo.master.replication.WorkMaker.java
License:Apache License
protected void addWorkRecord(Text file, Value v, Map<String, String> targets, String sourceTableId) { log.info("Adding work records for " + file + " to targets " + targets); try {//from ww w . ja v a2s .co m Mutation m = new Mutation(file); ReplicationTarget target = new ReplicationTarget(); DataOutputBuffer buffer = new DataOutputBuffer(); Text t = new Text(); for (Entry<String, String> entry : targets.entrySet()) { buffer.reset(); // Set up the writable target.setPeerName(entry.getKey()); target.setRemoteIdentifier(entry.getValue()); target.setSourceTableId(sourceTableId); target.write(buffer); // Throw it in a text for the mutation t.set(buffer.getData(), 0, buffer.getLength()); // Add it to the work section WorkSection.add(m, t, v); } try { writer.addMutation(m); } catch (MutationsRejectedException e) { log.warn("Failed to write work mutations for replication, will retry", e); } } catch (IOException e) { log.warn("Failed to serialize data to Text, will retry", e); } finally { try { writer.flush(); } catch (MutationsRejectedException e) { log.warn("Failed to write work mutations for replication, will retry", e); } } }
From source file:org.apache.accumulo.master.state.MergeInfoTest.java
License:Apache License
MergeInfo readWrite(MergeInfo info) throws Exception { DataOutputBuffer buffer = new DataOutputBuffer(); info.write(buffer);/*from w w w. j a va2 s .c o m*/ DataInputBuffer in = new DataInputBuffer(); in.reset(buffer.getData(), 0, buffer.getLength()); MergeInfo info2 = new MergeInfo(); info2.readFields(in); Assert.assertEquals(info.getExtent(), info2.getExtent()); Assert.assertEquals(info.getState(), info2.getState()); Assert.assertEquals(info.getOperation(), info2.getOperation()); return info2; }
From source file:org.apache.accumulo.server.master.state.MergeInfoTest.java
License:Apache License
private static MergeInfo readWrite(MergeInfo info) throws Exception { DataOutputBuffer buffer = new DataOutputBuffer(); info.write(buffer);/*from w w w.j ava2 s. c o m*/ DataInputBuffer in = new DataInputBuffer(); in.reset(buffer.getData(), 0, buffer.getLength()); MergeInfo info2 = new MergeInfo(); info2.readFields(in); assertEquals(info.getExtent(), info2.getExtent()); assertEquals(info.getState(), info2.getState()); assertEquals(info.getOperation(), info2.getOperation()); return info2; }