第一次匹配后如何终止grep管道

时间:2018-10-08 11:59:48

标签: c grep

我试图在我的C程序中执行以下代码,但-m1开关似乎无法终止管道。结果,程序将继续读取整个16 GB的文件。任何帮助都是可观的。

   public KeyStore generateSampleKeyStoreWith509Certificate() throws KeyStoreException, NoSuchAlgorithmException,
        CertificateException, IOException, UnrecoverableEntryException {

    X509Certificate cert;
    PrivateKey caKey;

    try {
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", "BC");
        keyPairGenerator.initialize(1024, new SecureRandom());
        KeyPair keyPair = keyPairGenerator.generateKeyPair();
        caKey = keyPair.getPrivate();

        Date notBefore = new Date();
        Date notAfter = new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 365);
        SubjectPublicKeyInfo spkInfo = SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded());
        X509v3CertificateBuilder newGen = new X509v3CertificateBuilder(new X500Name(issuer), serial, notBefore,
                notAfter, new X500Name(subject), spkInfo);
        ContentSigner sigGen = new JcaContentSignerBuilder("SHA256WithRSAEncryption").setProvider("BC")
                .build(caKey);
        X509CertificateHolder certHolder = newGen.build(sigGen);
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        InputStream is1 = new ByteArrayInputStream(certHolder.getEncoded());
        cert = (X509Certificate) cf.generateCertificate(is1);
        is1.close();

    } catch (OperatorCreationException | CertificateException | IOException | NoSuchProviderException
            | NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }

    KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    keyStore.load(null, password);
    keyStore.setCertificateEntry("SelfSigned", cert);

    return keyStore;
}

0 个答案:

没有答案