コード例 #1
0
        /// <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");
                }
            }
        }
コード例 #2
0
        /// <summary>Convert a UTF-8 encoded byte array back into a string.</summary>
        /// <exception cref="System.IO.IOException">if the byte array is invalid UTF8</exception>
        public static string FromBytes(byte[] bytes)
        {
            DataInputBuffer dbuf = new DataInputBuffer();

            dbuf.Reset(bytes, 0, bytes.Length);
            StringBuilder buf = new StringBuilder(bytes.Length);

            ReadChars(dbuf, buf, bytes.Length);
            return(buf.ToString());
        }