List of usage examples for org.apache.hadoop.io DataInputBuffer reset
public void reset(byte[] input, int length)
From source file:com.asakusafw.runtime.value.DecimalOptionTest.java
License:Apache License
/** * heavy read./*www . j av a 2 s . c o m*/ * @throws Exception if failed */ @Test public void stress_read() throws Exception { int count = 10000000; DecimalOption value = new DecimalOption(new BigDecimal("3.14")); byte[] bytes = toBytes(value); DecimalOption buf = new DecimalOption(); DataInputBuffer in = new DataInputBuffer(); for (int i = 0; i < count; i++) { in.reset(bytes, bytes.length); buf.readFields(in); if (i == 0) { assertThat(buf, is(value)); } } }
From source file:com.asakusafw.runtime.value.DecimalOptionTest.java
License:Apache License
/** * heavy read.// ww w .j av a 2 s. c o m * @throws Exception if failed */ @Test public void stress_read_large() throws Exception { int count = 10000000; DecimalOption value = new DecimalOption(new BigDecimal(Long.MAX_VALUE).multiply(BigDecimal.TEN)); byte[] bytes = toBytes(value); DecimalOption buf = new DecimalOption(); DataInputBuffer in = new DataInputBuffer(); for (int i = 0; i < count; i++) { in.reset(bytes, bytes.length); buf.readFields(in); if (i == 0) { assertThat(buf, is(value)); } } }
From source file:com.dasasian.chok.testutil.AbstractWritableTest.java
License:Apache License
protected Writable readWritable(DataOutputBuffer out, Writable writable) throws IOException { DataInputBuffer inputBuffer = new DataInputBuffer(); inputBuffer.reset(out.getData(), out.getData().length); writable.readFields(inputBuffer);//from www .j a v a 2s .c o m return writable; }
From source file:com.datasalt.pangool.io.TestBitField.java
License:Apache License
static void serDeCheck(BitField bf) throws IOException { DataOutputBuffer dob = new DataOutputBuffer(); DataInputBuffer dib = new DataInputBuffer(); bf.ser(dob);/* w w w .ja v a2s .com*/ dib.reset(dob.getData(), dob.getData().length); // Checking DataInput deser BitField newbf = new BitField(); newbf.set(1000); newbf.deser(dib); assertEquals(bf.toString() + " vs " + newbf.toString(), 0, bf.compareTo(newbf)); // Asserting that the rightmost bit is always 0. Important for comparisons byte[] arr = newbf.getBackingArray(); for (int i = 0; i < arr.length; i++) { assertEquals(0, arr[i] & 1); } //Checking byte array deserialization newbf = new BitField(); newbf.set(1000); newbf.deser(dob.getData(), 0); assertEquals(bf.toString() + " vs " + newbf.toString(), 0, bf.compareTo(newbf)); // Asserting that the rightmost bit is always 0. Important for comparisons arr = newbf.getBackingArray(); for (int i = 0; i < arr.length; i++) { assertEquals(0, arr[i] & 1); } }
From source file:com.datasalt.pangool.io.TestBitField.java
License:Apache License
static void checkReturnOfDeser(int bits) throws IOException { BitField bf = new BitField(); bf.set(bits - 1);/*from w w w . j a v a 2 s .c o m*/ DataOutputBuffer dob = new DataOutputBuffer(); DataInputBuffer dib = new DataInputBuffer(); bf.ser(dob); dib.reset(dob.getData(), dob.getData().length); // Checking DataInput deser BitField newbf = new BitField(); int read = newbf.deser(dib); assertEquals("For bits " + bits, ((bits - 1) / 7) + 1, read); //Checking byte array deserialization newbf = new BitField(); read = newbf.deser(dob.getData(), 0); assertEquals("For bits " + bits, ((bits - 1) / 7) + 1, read); }
From source file:com.datasalt.utils.io.Serialization.java
License:Apache License
public <T> T deser(Object obj, byte[] datum, int offset, int length) throws IOException { Deserializer deSer = serialization.getDeserializer(obj.getClass()); DataInputBuffer baIs = cachedInputStream.get(); baIs.reset(datum, length); deSer.open(baIs);/* ww w .j ava 2 s.co m*/ obj = deSer.deserialize(obj); deSer.close(); baIs.close(); return (T) obj; }
From source file:com.ibm.jaql.io.hadoop.SelectSplitInputFormat.java
License:Apache License
@Override public void configure(JobConf conf) { Class<? extends InputFormat> inputFormatCls = conf.getClass(INPUT_FORMAT, null, InputFormat.class); iFormat = ReflectionUtils.newInstance(inputFormatCls, conf); Class<? extends InputSplit> splitCls = conf.getClass(SPLIT_CLASS, null, InputSplit.class); split = ReflectionUtils.newInstance(splitCls, conf); byte[] bytes = ConfUtil.readBinary(conf, SPLIT); DataInputBuffer buffer = new DataInputBuffer(); buffer.reset(bytes, bytes.length); try {//from ww w. ja v a 2 s.com split.readFields(buffer); } catch (IOException e) { throw new UndeclaredThrowableException(e); } }
From source file:com.mongodb.hadoop.io.BSONWritable.java
License:Apache License
/** * Used by child copy constructors.//from ww w . ja v a 2s . c om */ protected synchronized void copy(final Writable other) { if (other != null) { try { DataOutputBuffer out = new DataOutputBuffer(); other.write(out); DataInputBuffer in = new DataInputBuffer(); in.reset(out.getData(), out.getLength()); readFields(in); } catch (IOException e) { throw new IllegalArgumentException("map cannot be copied: " + e.getMessage()); } } else { throw new IllegalArgumentException("source map cannot be null"); } }
From source file:com.netflix.suro.input.thrift.MessageSetSerDe.java
License:Apache License
@Override public TMessageSet deserialize(byte[] payload) { DataInputBuffer inBuffer = new DataInputBuffer(); inBuffer.reset(payload, payload.length); try {//from w w w. j av a 2s . co m String app = inBuffer.readUTF(); int numMessages = inBuffer.readInt(); byte compression = inBuffer.readByte(); long crc = inBuffer.readLong(); byte[] messages = new byte[inBuffer.readInt()]; inBuffer.read(messages); return new TMessageSet(app, numMessages, compression, crc, ByteBuffer.wrap(messages)); } catch (Exception e) { throw new RuntimeException("Failed to de-serialize payload into TMessageSet: " + e.getMessage(), e); } finally { Closeables.closeQuietly(inBuffer); } }
From source file:com.salesforce.phoenix.client.TestClientKeyValueLocal.java
License:Apache License
private void validate(KeyValue kv, byte[] row, byte[] family, byte[] qualifier, long ts, Type type, byte[] value) throws IOException { DataOutputBuffer out = new DataOutputBuffer(); kv.write(out);//from www. ja v a 2 s . c o m out.close(); byte[] data = out.getData(); // read it back in KeyValue read = new KeyValue(); DataInputBuffer in = new DataInputBuffer(); in.reset(data, data.length); read.readFields(in); in.close(); // validate that its the same assertTrue("Row didn't match!", Bytes.equals(row, read.getRow())); assertTrue("Family didn't match!", Bytes.equals(family, read.getFamily())); assertTrue("Qualifier didn't match!", Bytes.equals(qualifier, read.getQualifier())); assertTrue("Value didn't match!", Bytes.equals(value, read.getValue())); assertEquals("Timestamp didn't match", ts, read.getTimestamp()); assertEquals("Type didn't match", type.getCode(), read.getType()); }