public ArrayWritable(string[] strings) : this(typeof(UTF8), new IWritable[strings.Length]) { for (int i = 0; i < strings.Length; i++) { values[i] = new UTF8(strings[i]); } }
//end Internal subclass declaration /* * @see org.apache.hadoop.io.Writable#write(java.io.BinaryWriter) */ /// <exception cref="System.IO.IOException"/> public virtual void Write(BinaryWriter writer) { // write componentType UTF8.WriteString(writer, _componentType.FullName); // write length writer.Write(_length); // do the inner loop. Walk the decision tree only once. switch (_componentType.Name) { case "Boolean": WriteBooleanArray(writer); break; case "Char": WriteCharArray(writer); break; case "Byte": WriteByteArray(writer); break; case "Int16": WriteShortArray(writer); break; case "Int32": WriteIntArray(writer); break; case "Int64": WriteLongArray(writer); break; case "Single": WriteFloatArray(writer); break; case "Double": WriteDoubleArray(writer); break; default: throw new IOException("Component type " + _componentType + " is set as the output type, but no encoding is implemented for this type."); } }
/* * @see org.apache.hadoop.io.Writable#readFields(java.io.BinaryReader) */ /// <exception cref="System.IO.IOException"/> public virtual void ReadFields(BinaryReader reader) { // read and set the component type of the array string className = UTF8.ReadString(reader); Type componentType = GetPrimitiveClass(className); if (componentType == null) { throw new IOException("encoded array component type " + className + " is not a candidate primitive type"); } CheckDeclaredComponentType(componentType); this._componentType = componentType; // read and set the length of the array int length = reader.Read(); if (length < 0) { throw new IOException("encoded array length is negative " + length); } this._length = length; // construct and read in the array _value = System.Array.CreateInstance(componentType, length); // do the inner loop. Walk the decision tree only once. switch (componentType.Name) { case "Boolean": ReadBooleanArray(reader); break; case "Char": ReadCharArray(reader); break; case "Byte": ReadByteArray(reader); break; case "Int16": ReadShortArray(reader); break; case "Int32": ReadIntArray(reader); break; case "Int64": ReadLongArray(reader); break; case "Single": ReadFloatArray(reader); break; case "Double": ReadDoubleArray(reader); break; default: throw new IOException("Encoded type " + className + " converted to valid component type " + componentType + " but no encoding is implemented for this type."); } }