K2Informatics.Erlnet.OtpInputStream.read_compressed C# (CSharp) Method

read_compressed() public method

public read_compressed ( ) : OtpErlangObject
return OtpErlangObject
        public OtpErlangObject read_compressed()
        {
            int tag = read1skip_version();

            if (tag != OtpExternal.compressedTag)
            {
                throw new OtpErlangDecodeException("Wrong tag encountered, expected "
                                   + OtpExternal.compressedTag + ", got " + tag);
            }

            int size = read4BE();
            byte[] buf = new byte[size];
            DeflateStream dos = new DeflateStream(this, CompressionMode.Decompress, true);
            try
            {
                int dsize = dos.Read(buf, 0, size);
                if (dsize != size)
                {
                    throw new OtpErlangDecodeException("Decompression gave " + dsize + " bytes, not " + size);
                }
            }
            catch (OtpErlangDecodeException)
            {
                throw;
            }
            catch (InvalidDataException e)
            {
                throw new OtpErlangDecodeException(e.Message);
            }

            OtpInputStream ois = new OtpInputStream(buf, flags);
            return ois.read_any();
        }