public static void processFile()

in src/java/org/apache/fulcrum/jce/crypto/cli/CLI.java [126:162]


    public static void processFile(String cipherMode, char[] password, File sourceFile, File targetFile)
        throws Exception
    {
        try (FileInputStream fis = new FileInputStream(sourceFile)) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
    
            if( cipherMode.equals("dec") )
            {
                System.out.println("Decrypting " + sourceFile.getAbsolutePath() );
                CryptoUtil.getInstance().decrypt( fis, baos, password );
                fis.close();
    
                ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
                FileOutputStream fos = new FileOutputStream(targetFile);
                StreamUtil.copy(bais,fos);
                bais.close();
                fos.close();
            }
            else if( cipherMode.equals("enc") )
            {
                System.out.println("Encrypting " + sourceFile.getAbsolutePath() );
                CryptoUtil.getInstance().encrypt( fis, baos, password );
                fis.close();
    
                ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
                FileOutputStream fos = new FileOutputStream(targetFile);
                StreamUtil.copy(bais,fos);
                bais.close();
                fos.close();
            }
            else
            {
                String msg = "Don't know what to do with : " + cipherMode;
                throw new IllegalArgumentException(msg);
            }
        }
    }