@Override public void readFields(DataInput in) throws IOException { if (in instanceof DataInputBuffer) { byte[] bytes = ((DataInputBuffer) in).getData(); int pos = ((DataInputBuffer) in).getPosition(); int length = ((DataInputBuffer) in).getLength(); int bytesRemaining = length - pos; if (writeLength) { dos.write(bytes, pos, bytesRemaining); } else { dos.write(bytes, pos + 4, bytesRemaining - 4); } in.skipBytes(bytesRemaining); } else { int length = in.readInt(); if (writeLength) { dos.writeInt(length); } int numRead = 0; int toRead = Math.min(BUFFER_SIZE, length); byte[] buffer = new byte[BUFFER_SIZE]; while (toRead > 0) { in.readFully(buffer, 0, toRead); dos.write(buffer, 0, toRead); numRead += toRead; toRead = Math.min(BUFFER_SIZE, length - numRead); } } dos.flush(); }
public static int compare(DataInputBuffer buf1, DataInputBuffer buf2) { byte[] b1 = buf1.getData(); byte[] b2 = buf2.getData(); int s1 = buf1.getPosition(); int s2 = buf2.getPosition(); int l1 = buf1.getLength(); int l2 = buf2.getLength(); return FastByteComparisons.compareTo(b1, s1, l1, b2, s2, l2); }
public void reset(DataInputBuffer clone) { byte[] data = clone.getData(); int start = clone.getPosition(); int length = clone.getLength() - start; super.reset(data, start, length); }
private Object getCurrentValueObject() throws IOException, InterruptedException { DataInputBuffer ibuf = (DataInputBuffer) reader.getCurrentValue(); valueDataByteArray.set(Arrays.copyOf(ibuf.getData(), ibuf.getLength())); return config.valueConverter.bytesToObject(valueDataByteArray); } }
@SuppressWarnings("unused") public void copy(DataInputBuffer clone) { byte[] data = clone.getData(); int start = clone.getPosition(); int length = clone.getLength() - start; resize(length); System.arraycopy(data, start, buffer, 0, length); super.reset(buffer, 0, length); } }
@SuppressWarnings("unchecked") protected boolean lessThan(Object a, Object b) { DataInputBuffer key1 = ((Segment<K, V>)a).getKey(); DataInputBuffer key2 = ((Segment<K, V>)b).getKey(); int s1 = key1.getPosition(); int l1 = key1.getLength() - s1; int s2 = key2.getPosition(); int l2 = key2.getLength() - s2; return comparator.compare(key1.getData(), s1, l1, key2.getData(), s2, l2) < 0; }
@SuppressWarnings("unchecked") protected boolean lessThan(Object a, Object b) { DataInputBuffer key1 = ((Segment<K, V>)a).getKey(); DataInputBuffer key2 = ((Segment<K, V>)b).getKey(); int s1 = key1.getPosition(); int l1 = key1.getLength() - s1; int s2 = key2.getPosition(); int l2 = key2.getLength() - s2; return comparator.compare(key1.getData(), s1, l1, key2.getData(), s2, l2) < 0; }
@SuppressWarnings("unchecked") protected boolean lessThan(Object a, Object b) { DataInputBuffer key1 = ((Segment<K, V>)a).getKey(); DataInputBuffer key2 = ((Segment<K, V>)b).getKey(); int s1 = key1.getPosition(); int l1 = key1.getLength() - s1; int s2 = key2.getPosition(); int l2 = key2.getLength() - s2; return comparator.compare(key1.getData(), s1, l1, key2.getData(), s2, l2) < 0; }
@SuppressWarnings("unchecked") protected boolean lessThan(Object a, Object b) { DataInputBuffer key1 = ((Segment<K, V>)a).getKey(); DataInputBuffer key2 = ((Segment<K, V>)b).getKey(); int s1 = key1.getPosition(); int l1 = key1.getLength() - s1; int s2 = key2.getPosition(); int l2 = key2.getLength() - s2; return comparator.compare(key1.getData(), s1, l1, key2.getData(), s2, l2) < 0; }
@SuppressWarnings("unchecked") protected boolean lessThan(Object a, Object b) { DataInputBuffer key1 = ((Segment<K, V>)a).getKey(); DataInputBuffer key2 = ((Segment<K, V>)b).getKey(); int s1 = key1.getPosition(); int l1 = key1.getLength() - s1; int s2 = key2.getPosition(); int l2 = key2.getLength() - s2; return comparator.compare(key1.getData(), s1, l1, key2.getData(), s2, l2) < 0; }
@SuppressWarnings("unchecked") protected boolean lessThan(Object a, Object b) { DataInputBuffer key1 = ((Segment<K, V>)a).getKey(); DataInputBuffer key2 = ((Segment<K, V>)b).getKey(); int s1 = key1.getPosition(); int l1 = key1.getLength() - s1; int s2 = key2.getPosition(); int l2 = key2.getLength() - s2; return comparator.compare(key1.getData(), s1, l1, key2.getData(), s2, l2) < 0; }
@Override public Writable deserialize(Writable w) throws IOException { BytesWritable writable = (BytesWritable) w; if (w == null) { writable = (BytesWritable) ReflectionUtils.newInstance(writableClass, getConf()); } writable.set(dataIn.getData(), dataIn.getPosition(), dataIn.getLength() - dataIn .getPosition()); return writable; }
public static void copy(DataInputBuffer src, DataOutputBuffer dst) throws IOException { byte[] b1 = src.getData(); int s1 = src.getPosition(); int l1 = src.getLength(); dst.reset(); dst.write(b1, s1, l1 - s1); }
public void nextRawValue(DataInputBuffer value) throws IOException { final DataInputBuffer vb = kvIter.getValue(); final int vp = vb.getPosition(); final int vlen = vb.getLength() - vp; value.reset(vb.getData(), vp, vlen); bytesRead += vlen; } public long getPosition() throws IOException {
/** * Read the next value * @throws IOException */ private void readNextValue() throws IOException { DataInputBuffer nextValueBytes = in.getValue(); valueIn.reset(nextValueBytes.getData(), nextValueBytes.getPosition(), nextValueBytes.getLength()); value = valDeserializer.deserialize(value); } }
boolean nextRawKey(DataInputBuffer nextKey) throws IOException { boolean hasNext = reader.nextRawKey(nextKey); key.reset(nextKey.getData(), nextKey.getPosition(), nextKey.getLength() - nextKey.getPosition()); return hasNext; }
KeyState readRawKey(DataInputBuffer nextKey) throws IOException { KeyState keyState = reader.readRawKey(nextKey); key.reset(nextKey.getData(), nextKey.getPosition(), nextKey.getLength() - nextKey.getPosition()); return keyState; }
/** * Read the next value * @throws IOException */ private void readNextValue() throws IOException { DataInputBuffer nextValueBytes = in.getValue(); valueIn.reset(nextValueBytes.getData(), nextValueBytes.getPosition(), nextValueBytes.getLength()); value = valDeserializer.deserialize(value); } }
/** * Read the next value * @throws IOException */ private void readNextValue() throws IOException { DataInputBuffer nextValueBytes = in.getValue(); valueIn.reset(nextValueBytes.getData(), nextValueBytes.getPosition(), nextValueBytes.getLength()); value = valDeserializer.deserialize(value); } }
Assert.assertEquals(1.0f, mergeQueue.getProgress().get(), epsilon); Assert.assertTrue(mergeQueue.getKey() == null); Assert.assertEquals(0, mergeQueue.getValue().getData().length);