#vulnerable code 
                                public void printFile(byte[] bytes) throws Exception {
        InputStream in;

        if(encrypt){
            cipher.init(Cipher.ENCRYPT_MODE, key);

            byte[] encryptedBytes = cipher.doFinal(bytes);
            in = new ByteArrayInputStream(encryptedBytes);
        }
        else
            in = new ByteArrayInputStream(bytes);

        FileOutputStream out = new FileOutputStream(filename);
        

        byte[] input = new byte[1024];
        int bytesRead;
        while ((bytesRead = in.read(input)) != -1) {
            out.write(input, 0, bytesRead);
            out.flush();
        }

        out.close();
        in.close();
    } 
                            #location 9 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                public void printFile(byte[] bytes) throws IOException {
        if (encrypt) {
            byte[] encryptedBytes = new byte[0];

            try {
                cipher.init(Cipher.ENCRYPT_MODE, key);

                encryptedBytes = cipher.doFinal(bytes);
            } catch (BadPaddingException e) {
                logger.error("Invalid Key to decrypt users file.", e);
            } catch (IllegalBlockSizeException e) {
                logger.error("Users file \"{}\" is corrupted.", filename, e);
            } catch (InvalidKeyException e) {
                logger.error("Invalid Key to decrypt users file.", e);
            }

            printFileAux(encryptedBytes);
        } else {
            printFileAux(bytes);
        }
    }