#vulnerable code 
                                public void clearSign(InputStream input, OutputStream output) throws IOException, PGPException, GeneralSecurityException {
        int digest = PGPUtil.SHA1;
        
        PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(new BcPGPContentSignerBuilder(privateKey.getPublicKeyPacket().getAlgorithm(), digest));
        signatureGenerator.init(PGPSignature.CANONICAL_TEXT_DOCUMENT, privateKey);
        
        ArmoredOutputStream armoredOutput = new ArmoredOutputStream(output);
        armoredOutput.beginClearText(digest);
        
        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        
        String line;
        while ((line = reader.readLine()) != null) {
            // trailing spaces must be removed for signature calculation (see http://tools.ietf.org/html/rfc4880#section-7.1)
            byte[] data = trim(line).getBytes("UTF-8");
            
            armoredOutput.write(data);
            armoredOutput.write(EOL);
            
            signatureGenerator.update(data);
            signatureGenerator.update(EOL);
        }

        armoredOutput.endClearText();
        
        PGPSignature signature = signatureGenerator.generate();
        signature.encode(new BCPGOutputStream(armoredOutput));
        
        armoredOutput.close();
    } 
                            #location 22 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                public void clearSign(InputStream input, OutputStream output) throws IOException, PGPException, GeneralSecurityException {
        int digest = PGPUtil.SHA1;
        
        PGPSignatureGenerator signatureGenerator = new PGPSignatureGenerator(new BcPGPContentSignerBuilder(privateKey.getPublicKeyPacket().getAlgorithm(), digest));
        signatureGenerator.init(PGPSignature.CANONICAL_TEXT_DOCUMENT, privateKey);
        
        ArmoredOutputStream armoredOutput = new ArmoredOutputStream(output);
        armoredOutput.beginClearText(digest);
        
        LineIterator iterator = new LineIterator(new InputStreamReader(input));
        
        while (iterator.hasNext()) {
            String line = iterator.nextLine();
            
            // trailing spaces must be removed for signature calculation (see http://tools.ietf.org/html/rfc4880#section-7.1)
            byte[] data = trim(line).getBytes("UTF-8");
            
            armoredOutput.write(data);
            armoredOutput.write(EOL);
            
            signatureGenerator.update(data);
            if (iterator.hasNext()) {
                signatureGenerator.update(EOL);
            }
        }

        armoredOutput.endClearText();
        
        PGPSignature signature = signatureGenerator.generate();
        signature.encode(new BCPGOutputStream(armoredOutput));
        
        armoredOutput.close();
    }