### Question:
KeyStoreEncryptionFactory extends
        EncryptionTransformFactory<BasicEncryptionOutputTransform, BasicEncryptionInputTransform> { @Override public BasicEncryptionOutputTransform getOutputTransform( OutputStream streamToEncodeTo, Map<String, String> metadataToEncode) throws IOException, TransformException { KeyPair asymmetricKey = getKeyPair(masterEncryptionKeyAlias); return new BasicEncryptionOutputTransform(streamToEncodeTo, metadataToEncode, masterEncryptionKeyFingerprint, asymmetricKey, encryptionTransform, keySize, provider); } KeyStoreEncryptionFactory(KeyStore keyStore,
            String masterEncryptionKeyAlias, 
            char[] keyStorePassword);  KeyStoreEncryptionFactory(KeyStore keyStore,
            String masterEncryptionKeyAlias, char[] masterKeyPassword, Provider provider); @Override Map<String, String> rekey(Map<String, String> metadata); @Override BasicEncryptionOutputTransform getOutputTransform(
            OutputStream streamToEncodeTo, Map<String, String> metadataToEncode); @Override BasicEncryptionOutputTransform getOutputTransform(
            InputStream streamToEncode, Map<String, String> metadataToEncode); @Override BasicEncryptionInputTransform getInputTransform(
            String transformConfig, InputStream streamToDecode,
            Map<String, String> metadata); String getMasterEncryptionKeyAlias(); void setMasterEncryptionKeyAlias(String alias);  }### Answer:
@Test public void testGetOutputTransform() throws Exception { KeyStoreEncryptionFactory factory = new KeyStoreEncryptionFactory(keystore, keyAlias, keystorePassword.toCharArray(), provider); ByteArrayOutputStream out = new ByteArrayOutputStream(); Map<String, String> metadata = new HashMap<String, String>(); metadata.put("name1", "value1"); metadata.put("name2", "value2"); BasicEncryptionOutputTransform outTransform = factory .getOutputTransform(out, metadata); InputStream classin = this.getClass().getClassLoader() .getResourceAsStream("uncompressed.txt"); ByteArrayOutputStream classByteStream = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int c = 0; while ((c = classin.read(buffer)) != -1) { classByteStream.write(buffer, 0, c); } byte[] uncompressedData = classByteStream.toByteArray(); classin.close(); OutputStream encryptedStream = outTransform.getEncodedOutputStream(); encryptedStream.write(uncompressedData); try { outTransform.getEncodedMetadata(); fail("Should not be able to get encoded metadata until stream is closed"); } catch (IllegalStateException e) { } encryptedStream.close(); Map<String, String> objectData = outTransform.getEncodedMetadata(); assertEquals("Uncompressed digest incorrect", "027e997e6b1dfc97b93eb28dc9a6804096d85873", objectData.get(TransformConstants.META_ENCRYPTION_UNENC_SHA1)); assertEquals("Uncompressed size incorrect", 2516125, Long.parseLong(objectData .get(TransformConstants.META_ENCRYPTION_UNENC_SIZE))); assertNotNull("Missing IV", objectData.get(TransformConstants.META_ENCRYPTION_IV)); assertEquals("Incorrect master encryption key ID", "e3a69d422e6d9008e3cdfcbea674ccd9ab4758c3", objectData.get(TransformConstants.META_ENCRYPTION_KEY_ID)); assertNotNull("Missing object key", objectData.get(TransformConstants.META_ENCRYPTION_OBJECT_KEY)); assertNotNull("Missing metadata signature", objectData.get(TransformConstants.META_ENCRYPTION_META_SIG)); assertEquals("name1 incorrect", "value1", objectData.get("name1")); assertEquals("name2 incorrect", "value2", objectData.get("name2")); String transformConfig = outTransform.getTransformConfig(); assertEquals("Transform config string incorrect", "ENC:AES/CBC/PKCS5Padding", transformConfig); logger.info("Encoded metadata: " + objectData); }