/** {@inheritDoc} */ @Override public void close() throws IgniteCheckedException { ser.close(); } }
/** * Write key-value pair. * * @param key Key. * @param val Value. * @return Whether flush is needed. * @throws IgniteCheckedException If failed. */ public boolean write(Object key, Object val) throws IgniteCheckedException { keySer.write(out, key); valSer.write(out, val); cnt++; return out.readyForFlush(); }
/** * Tests read/write of Integer via native JavaleSerialization. * @throws Exception If fails. */ @Test public void testIntJavaSerialization() throws Exception { HadoopSerialization ser = new HadoopSerializationWrapper(new JavaSerialization(), Integer.class); ByteArrayOutputStream buf = new ByteArrayOutputStream(); DataOutput out = new DataOutputStream(buf); ser.write(out, 3); ser.write(out, -5); ser.close(); DataInput in = new DataInputStream(new ByteArrayInputStream(buf.toByteArray())); assertEquals(3, ((Integer)ser.read(in, null)).intValue()); assertEquals(-5, ((Integer)ser.read(in, null)).intValue()); } }
/** * Tests read/write of IntWritable via native WritableSerialization. * @throws Exception If fails. */ @Test public void testIntWritableSerialization() throws Exception { HadoopSerialization ser = new HadoopSerializationWrapper(new WritableSerialization(), IntWritable.class); ByteArrayOutputStream buf = new ByteArrayOutputStream(); DataOutput out = new DataOutputStream(buf); ser.write(out, new IntWritable(3)); ser.write(out, new IntWritable(-5)); assertEquals("[0, 0, 0, 3, -1, -1, -1, -5]", Arrays.toString(buf.toByteArray())); DataInput in = new DataInputStream(new ByteArrayInputStream(buf.toByteArray())); assertEquals(3, ((IntWritable)ser.read(in, null)).get()); assertEquals(-5, ((IntWritable)ser.read(in, null)).get()); }
/** * @param in Data input. * @param reuse Reusable key. * @return Key. * @throws IgniteCheckedException If failed. */ @Override public Key addKey(DataInput in, @Nullable Key reuse) throws IgniteCheckedException { KeyImpl k = reuse == null ? new KeyImpl() : (KeyImpl)reuse; k.tmpKey = keySer.read(in, k.tmpKey); k.meta = add(k.tmpKey, null); return k; }
/** {@inheritDoc} */ @Override public Key addKey(DataInput in, @Nullable Key reuse) throws IgniteCheckedException { KeyImpl k = reuse == null ? new KeyImpl() : (KeyImpl)reuse; k.tmpKey = keySer.read(in, k.tmpKey); k.meta = add(k.tmpKey, null); return k; }
/** * @param ptr Pointer. * @param size Object size. * @return Object. */ protected Object read(long ptr, long size) throws IgniteCheckedException { in.buffer().set(ptr, size); tmp = ser.read(in, tmp); return tmp; }
/** * @param off Offset. * @param o Object. * @return Page pointer. * @throws IgniteCheckedException If failed. */ protected long write(int off, Object o, HadoopSerialization ser) throws IgniteCheckedException { writeStart = fixAlignment(); if (off != 0) out.move(off); ser.write(out, o); return writeStart; }