List of usage examples for org.apache.hadoop.io UTF8 readString
public static String readString(DataInput in) throws IOException
From source file:com.chinamobile.bcbsp.comm.BSPMessage.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { this.dstPartition = in.readInt(); int a = in.readInt(); this.data = new byte[a]; in.readFully(data, 0, this.data.length); this.dstVertex = UTF8.readString(in); }
From source file:com.cloudera.recordbreaker.learnstructure.InferredType.java
License:Open Source License
public void readFields(DataInput in) throws IOException { // instance-specific this.sampleStrs = new ArrayList<String>(); int numSamples = in.readInt(); for (int i = 0; i < numSamples; i++) { sampleStrs.add(UTF8.readString(in).toString()); }// w w w. ja v a 2 s . c o m this.tokenClassIdentifier = in.readInt(); if (in.readBoolean()) { this.tokenParameter = UTF8.readString(in); } else { this.tokenParameter = null; } this.schema = computeAvroSchema(); }
From source file:com.nebulousnews.io.ObjectSerializableWritable.java
License:Apache License
/** Read a {@link Writable}, {@link String}, primitive type, or an array of * the preceding. *//*from w ww . java 2s . c om*/ @SuppressWarnings("unchecked") public static Object readObject(DataInput in, ObjectSerializableWritable objectWritable, Configuration conf) throws IOException { String className = UTF8.readString(in); Class<?> declaredClass = PRIMITIVE_NAMES.get(className); if (declaredClass == null) { try { declaredClass = conf.getClassByName(className); } catch (ClassNotFoundException e) { throw new RuntimeException("readObject can't find class " + className, e); } } Object instance; if (declaredClass.isPrimitive()) { // primitive types if (declaredClass == Boolean.TYPE) { // boolean instance = Boolean.valueOf(in.readBoolean()); } else if (declaredClass == Character.TYPE) { // char instance = Character.valueOf(in.readChar()); } else if (declaredClass == Byte.TYPE) { // byte instance = Byte.valueOf(in.readByte()); } else if (declaredClass == Short.TYPE) { // short instance = Short.valueOf(in.readShort()); } else if (declaredClass == Integer.TYPE) { // int instance = Integer.valueOf(in.readInt()); } else if (declaredClass == Long.TYPE) { // long instance = Long.valueOf(in.readLong()); } else if (declaredClass == Float.TYPE) { // float instance = Float.valueOf(in.readFloat()); } else if (declaredClass == Double.TYPE) { // double instance = Double.valueOf(in.readDouble()); } else if (declaredClass == Void.TYPE) { // void instance = null; } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isArray()) { // array int length = in.readInt(); instance = Array.newInstance(declaredClass.getComponentType(), length); for (int i = 0; i < length; i++) { Array.set(instance, i, readObject(in, conf)); } } else if (declaredClass == String.class) { // String instance = UTF8.readString(in); } else if (declaredClass.isEnum()) { // enum instance = Enum.valueOf((Class<? extends Enum>) declaredClass, UTF8.readString(in)); } else if (Serializable.class.isAssignableFrom(declaredClass)) { //Serializable ObjectInputStream input = new ObjectInputStream((InputStream) in); try { instance = input.readObject(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block throw new IllegalArgumentException("ClassNotFound: " + declaredClass); } } else { // Writable (or fail, this is dangerous) Class instanceClass = null; String str = ""; try { str = UTF8.readString(in); instanceClass = conf.getClassByName(str); } catch (ClassNotFoundException e) { throw new RuntimeException("readObject can't find class " + str, e); } Writable writable = WritableFactories.newInstance(instanceClass, conf); writable.readFields(in); instance = writable; if (instanceClass == NullInstance.class) { // null declaredClass = ((NullInstance) instance).declaredClass; instance = null; } } if (objectWritable != null) { // store values objectWritable.declaredClass = declaredClass; objectWritable.instance = instance; } return instance; }
From source file:utils.ArrayPrimitiveWritable.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { // read and set the component type of the array @SuppressWarnings("deprecation") String className = UTF8.readString(in); Class<?> componentType = getPrimitiveClass(className); if (componentType == null) { throw new IOException( "encoded array component type " + className + " is not a candidate primitive type"); }//from ww w. j ava 2 s . co m checkDeclaredComponentType(componentType); this.componentType = componentType; // read and set the length of the array int length = in.readInt(); if (length < 0) { throw new IOException("encoded array length is negative " + length); } this.length = length; // construct and read in the array value = Array.newInstance(componentType, length); // do the inner loop. Walk the decision tree only once. if (componentType == Boolean.TYPE) { // boolean readBooleanArray(in); } else if (componentType == Character.TYPE) { // char readCharArray(in); } else if (componentType == Byte.TYPE) { // byte readByteArray(in); } else if (componentType == Short.TYPE) { // short readShortArray(in); } else if (componentType == Integer.TYPE) { // int readIntArray(in); } else if (componentType == Long.TYPE) { // long readLongArray(in); } else if (componentType == Float.TYPE) { // float readFloatArray(in); } else if (componentType == Double.TYPE) { // double readDoubleArray(in); } else { throw new IOException("Encoded type " + className + " converted to valid component type " + componentType.toString() + " but no encoding is implemented for this type."); } }