当前位置: 首页>>代码示例>>C#>>正文


C# StreamReader.close方法代码示例

本文整理汇总了C#中System.IO.StreamReader.close方法的典型用法代码示例。如果您正苦于以下问题:C# StreamReader.close方法的具体用法?C# StreamReader.close怎么用?C# StreamReader.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.StreamReader的用法示例。


在下文中一共展示了StreamReader.close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: testRefresh10s

        public void testRefresh10s()
        {
            StringBuilder encodedData = new StringBuilder();
            TextReader dataFile = new System.IO.StreamReader(new FileInfo(System.IO.Path.Combine(policyConfigDirectory_.FullName,"testData")).OpenWrite());
            // Use "try/finally instead of "try-with-resources" or "using"
            // which are not supported before Java 7.
            try {
                String line;
                while ((line = dataFile.readLine()) != null)
                    encodedData.append(line);
            } finally {
                dataFile.close();
            }

            byte[] decodedData = net.named_data.jndn.util.Common.base64Decode(encodedData.toString());
            Data data = new Data();
            data.wireDecode(new Blob(decodedData, false));

            // This test is needed, since the KeyChain will express interests in unknown
            // certificates.
            VerificationResult vr = doVerify(policyManager_, data);

            AssertTrue(
                    "ConfigPolicyManager did not create ValidationRequest for unknown certificate",
                    vr.hasFurtherSteps_);
            AssertEquals(
                    "ConfigPolicyManager called success callback with pending ValidationRequest",
                    0, vr.successCount_);
            AssertEquals(
                    "ConfigPolicyManager called failure callback with pending ValidationRequest",
                    0, vr.failureCount_);

            // Now save the cert data to our anchor directory, and wait.
            // We have to sign it with the current identity or the policy manager will
            // create an interest for the signing certificate.
            IdentityCertificate cert = new IdentityCertificate();
            byte[] certData = net.named_data.jndn.util.Common.base64Decode(CERT_DUMP);
            cert.wireDecode(new Blob(certData, false));
            keyChain_.signByIdentity(cert, identityName_);
            Blob signedCertBlob = cert.wireEncode();
            String encodedCert = net.named_data.jndn.util.Common.base64Encode(signedCertBlob
                    .getImmutableArray());
            BufferedStream certFile = new BufferedStream(new System.IO.StreamWriter(testCertFile_.OpenRead()));
            try {
                certFile.Write(encodedCert,0,encodedCert.Substring(0,encodedCert.Length));
                certFile.flush();
            } finally {
                certFile.close();
            }

            // Still too early for refresh to pick it up.
            vr = doVerify(policyManager_, data);

            AssertTrue("ConfigPolicyManager refresh occured sooner than specified",
                    vr.hasFurtherSteps_);
            AssertEquals(
                    "ConfigPolicyManager called success callback with pending ValidationRequest",
                    0, vr.successCount_);
            AssertEquals(
                    "ConfigPolicyManager called failure callback with pending ValidationRequest",
                    0, vr.failureCount_);

            ILOG.J2CsMapping.Threading.ThreadWrapper.sleep(6000);

            // Now we should find it.
            vr = doVerify(policyManager_, data);

            AssertFalse("ConfigPolicyManager did not refresh certificate store",
                    vr.hasFurtherSteps_);
            AssertEquals("Verification success called " + vr.successCount_
                    + " times instead of 1", 1, vr.successCount_);
            AssertEquals("ConfigPolicyManager did not verify valid signed data", 0,
                    vr.failureCount_);
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:74,代码来源:TestPolicyManager.cs


注:本文中的System.IO.StreamReader.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。