/** * Converts byte array to a double value. * * @param bytes input byte array to be considered. * @return Return double made from passed bytes. */ public static double toDouble(final byte [] bytes) { return toDouble(bytes, 0); }
/** * Converts byte array to a double value. * * @param bytes input byte array to be considered. * @return Return double made from passed bytes. */ public static double toDouble(final byte [] bytes) { return toDouble(bytes, 0); }
@SuppressWarnings("unchecked") public static <T> T fromBytes( byte[] val, Schema schema , SpecificDatumReader<T> datumReader, T object) throws IOException { Type type = schema.getType(); switch (type) { case ENUM: String symbol = schema.getEnumSymbols().get(val[0]); return (T)Enum.valueOf(ReflectData.get().getClass(schema), symbol); case STRING: return (T)new Utf8(toString(val)); case BYTES: return (T)ByteBuffer.wrap(val); case INT: return (T)Integer.valueOf(bytesToVint(val)); case LONG: return (T)Long.valueOf(bytesToVlong(val)); case FLOAT: return (T)Float.valueOf(toFloat(val)); case DOUBLE: return (T)Double.valueOf(toDouble(val)); case BOOLEAN: return (T)Boolean.valueOf(val[0] != 0); case RECORD: //fall case MAP: case ARRAY: return (T)IOUtils.deserialize(val, (SpecificDatumReader<SpecificRecord>)datumReader, (SpecificRecord)object); default: throw new RuntimeException("Unknown type: "+type); } }
@SuppressWarnings("unchecked") public static <T> T fromBytes( byte[] val, Schema schema , SpecificDatumReader<T> datumReader, T object) throws IOException { Type type = schema.getType(); switch (type) { case ENUM: String symbol = schema.getEnumSymbols().get(val[0]); return (T)Enum.valueOf(ReflectData.get().getClass(schema), symbol); case STRING: return (T)new Utf8(toString(val)); case BYTES: return (T)ByteBuffer.wrap(val); case INT: return (T)Integer.valueOf(bytesToVint(val)); case LONG: return (T)Long.valueOf(bytesToVlong(val)); case FLOAT: return (T)Float.valueOf(toFloat(val)); case DOUBLE: return (T)Double.valueOf(toDouble(val)); case BOOLEAN: return (T)Boolean.valueOf(val[0] != 0); case RECORD: //fall case MAP: case ARRAY: return (T)IOUtils.deserialize(val, (SpecificDatumReader<SpecificRecord>)datumReader, (SpecificRecord)object); default: throw new RuntimeException("Unknown type: "+type); } }