/// <summary>Used by child copy constructors.</summary> protected internal virtual void Copy(IWritable other) { lock (this) { if (other != null) { try { var memoryStream = new MemoryStream(); var binaryWriter = new BinaryWriter(memoryStream); DataOutputBuffer outputBuffer = new DataOutputBuffer(); other.Write(binaryWriter); DataInputBuffer inputBuffer = new DataInputBuffer(); inputBuffer.Reset(outputBuffer.GetData(), outputBuffer.GetLength()); ReadFields(inputBuffer); } catch (IOException e) { throw new ArgumentException("map cannot be copied: " + e.Message); } } else { throw new ArgumentException("source map cannot be null"); } } }
/// STATIC UTILITIES FROM HERE DOWN /// These are probably not used much anymore, and might be removed... /// <summary>Convert a string to a UTF-8 encoded byte array.</summary> /// <seealso cref="Runtime.GetBytesForString(string)"/> public static byte[] GetBytes(string @string) { byte[] result = new byte[Utf8Length(@string)]; try { // avoid sync'd allocations DataOutputBuffer obuf = ObufFactory.Get(); obuf.Reset(); WriteChars(obuf, @string, 0, @string.Length); System.Array.Copy(obuf.GetData(), 0, result, 0, obuf.GetLength()); } catch (IOException e) { throw new RuntimeException(e); } return(result); }