List of usage examples for org.apache.hadoop.io BooleanWritable BooleanWritable
public BooleanWritable()
From source file:org.apache.pig.impl.io.NullableBooleanWritable.java
License:Apache License
public NullableBooleanWritable() { mValue = new BooleanWritable(); }
From source file:org.bgi.flexlab.gaea.data.mapreduce.writable.DuplicationKeyWritable.java
License:Open Source License
public DuplicationKeyWritable() { LB = new Text(); chrIndex = new IntWritable(); position = new IntWritable(); forward = new BooleanWritable(); }
From source file:org.openflamingo.mapreduce.aggregator.BooleanAndAggregator.java
License:Apache License
@Override public BooleanWritable createAggregatedValue() { return new BooleanWritable(); }
From source file:org.pentaho.hadoop.mapreduce.converter.converters.KettleTypeToBooleanWritableConverter.java
License:Apache License
@Override public BooleanWritable convert(ValueMetaInterface meta, Object obj) throws TypeConversionException { try {//from w w w. jav a2 s .c o m BooleanWritable result = new BooleanWritable(); result.set(meta.getBoolean(obj)); return result; } catch (Exception ex) { throw new TypeConversionException(BaseMessages.getString(TypeConverterFactory.class, "ErrorConverting", BooleanWritable.class.getSimpleName(), obj), ex); } }
From source file:org.shaf.core.util.IOUtils.java
License:Apache License
/** * Reads an {@link Object} of the specified type from the {@link DataInput}. * /*from w w w . j a v a 2 s . co m*/ * @param cls * the type of the reading object. * @param in * the data input stream. * @return the read object. * @throws IOException * if I/O error occurs. */ public static final Object readObject(Class<?> cls, DataInput in) throws IOException { try { if (cls == null) { throw new IOException("Reading class is not defined: null."); } else if (ClassUtils.isBoolean(cls)) { BooleanWritable obj = new BooleanWritable(); obj.readFields(in); return obj.get(); } else if (ClassUtils.isByte(cls)) { ByteWritable obj = new ByteWritable(); obj.readFields(in); return obj.get(); } else if (ClassUtils.isShort(cls)) { ShortWritable obj = new ShortWritable(); obj.readFields(in); return obj.get(); } else if (ClassUtils.isInteger(cls)) { IntWritable obj = new IntWritable(); obj.readFields(in); return obj.get(); } else if (ClassUtils.isLong(cls)) { LongWritable obj = new LongWritable(); obj.readFields(in); return obj.get(); } else if (ClassUtils.isFloat(cls)) { FloatWritable obj = new FloatWritable(); obj.readFields(in); return obj.get(); } else if (ClassUtils.isDouble(cls)) { DoubleWritable obj = new DoubleWritable(); obj.readFields(in); return obj.get(); } else if (ClassUtils.isString(cls)) { return Text.readString(in); } else if (ClassUtils.isEnum(cls)) { IntWritable obj = new IntWritable(); obj.readFields(in); return cls.getEnumConstants()[obj.get()]; } else if (ClassUtils.isArray(cls)) { int length = (int) readObject(int.class, in); Object array = Array.newInstance(cls.getComponentType(), length); for (int j = 0; j < length; j++) { Object a = readObject(cls.getComponentType(), in); Array.set(array, j, a); } return array; } else { Object obj = cls.newInstance(); ((Writable) obj).readFields(in); return obj; } } catch (IllegalArgumentException | InstantiationException | IllegalAccessException exc) { throw new IOException(exc); } }
From source file:org.shaf.core.util.IOUtilsTest.java
License:Apache License
/** * Test writing of {@code boolean} value. *//* w w w . ja v a 2s. c om*/ @Test public void testWriteBoolean() { byte[] buf = null; // Tests write for boolean "false". boolean value = false; try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos);) { IOUtils.writeObject(value, out); buf = baos.toByteArray(); } catch (IOException exc) { fail(exc.getMessage()); } try (ByteArrayInputStream bais = new ByteArrayInputStream(buf); DataInputStream in = new DataInputStream(bais);) { BooleanWritable probe = new BooleanWritable(); probe.readFields(in); assertFalse(probe.get()); } catch (IOException exc) { fail(exc.getMessage()); } // Tests write for boolean "true". value = true; try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos);) { IOUtils.writeObject(value, out); buf = baos.toByteArray(); } catch (IOException exc) { fail(exc.getMessage()); } try (ByteArrayInputStream bais = new ByteArrayInputStream(buf); DataInputStream in = new DataInputStream(bais);) { BooleanWritable probe = new BooleanWritable(); probe.readFields(in); assertTrue(probe.get()); } catch (IOException exc) { fail(exc.getMessage()); } }