Created
April 3, 2013 17:05
-
-
Save okram/5303124 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void write(final Map<String, Object> properties, final DataOutput out) throws IOException { | |
if (null == properties) { | |
WritableUtils.writeVInt(out, 0); | |
} else { | |
WritableUtils.writeVInt(out, properties.size()); | |
for (final Map.Entry<String, Object> entry : properties.entrySet()) { | |
out.writeUTF(entry.getKey()); | |
final Class valueClass = entry.getValue().getClass(); | |
final Object valueObject = entry.getValue(); | |
if (valueClass.equals(Integer.class)) { | |
out.writeByte(PropertyType.INT.val); | |
WritableUtils.writeVInt(out, (Integer) valueObject); | |
} else if (valueClass.equals(Long.class)) { | |
out.writeByte(PropertyType.LONG.val); | |
WritableUtils.writeVLong(out, (Long) valueObject); | |
} else if (valueClass.equals(Float.class)) { | |
out.writeByte(PropertyType.FLOAT.val); | |
out.writeFloat((Float) valueObject); | |
} else if (valueClass.equals(Double.class)) { | |
out.writeByte(PropertyType.DOUBLE.val); | |
out.writeDouble((Double) valueObject); | |
} else if (valueClass.equals(String.class)) { | |
out.writeByte(PropertyType.STRING.val); | |
WritableUtils.writeString(out, (String) valueObject); | |
} else if (valueClass.equals(Boolean.class)) { | |
out.writeByte(PropertyType.BOOLEAN.val); | |
out.writeBoolean((Boolean) valueObject); | |
} else { | |
throw new IOException("Property value type of " + valueClass + " is not supported"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment