Class TransformedRecordSerializerJCE.Builder<M extends Message>
- java.lang.Object
-
- com.apple.foundationdb.record.provider.common.TransformedRecordSerializer.Builder<M>
-
- com.apple.foundationdb.record.provider.common.TransformedRecordSerializerJCE.Builder<M>
-
- Type Parameters:
M
- type ofMessage
that underlying records will use
- Enclosing class:
- TransformedRecordSerializerJCE<M extends Message>
public static class TransformedRecordSerializerJCE.Builder<M extends Message> extends TransformedRecordSerializer.Builder<M>
Builder class for theTransformedRecordSerializerJCE
class. The methods on this builder allows the user to specify parameters that can then be used to specify which transformations should be applied before serializing the record. It can also be used to specify parameters that will then be applied to serialized data before deserializing, though the prefix of records themselves are what specify the needed transformations.
-
-
Field Summary
Fields Modifier and Type Field Description protected String
cipherName
protected Key
encryptionKey
protected SecureRandom
secureRandom
-
Fields inherited from class com.apple.foundationdb.record.provider.common.TransformedRecordSerializer.Builder
compressionLevel, compressWhenSerializing, encryptWhenSerializing, inner
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Builder(RecordSerializer<M> inner)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TransformedRecordSerializerJCE<M>
build()
Construct aTransformedRecordSerializerJCE
from the parameters specified by this builder.TransformedRecordSerializerJCE.Builder<M>
clearEncryption()
Clears a previously specified key and provider that might have been passed to thisBuilder
.TransformedRecordSerializerJCE.Builder<M>
clearSecureRandom()
Clears a previously set secure random number generator that might have been passed to thisBuilder
.TransformedRecordSerializerJCE.Builder<M>
setCipherName(String cipherName)
Specifies the cipher algorithm used to encrypt or decrypt a record.TransformedRecordSerializerJCE.Builder<M>
setCompressionLevel(int level)
Compression level to use if compressing.TransformedRecordSerializerJCE.Builder<M>
setCompressWhenSerializing(boolean compressWhenSerializing)
Whether to compress records after serializing.TransformedRecordSerializerJCE.Builder<M>
setEncryptionKey(Key encryptionKey)
Specifies the encryption key used to encrypt or decrypt a record.TransformedRecordSerializerJCE.Builder<M>
setEncryptWhenSerializing(boolean encryptWhenSerializing)
Whether to encrypt records after serializing.TransformedRecordSerializerJCE.Builder<M>
setSecureRandom(SecureRandom secureRandom)
Sets the secure random number generator used during cryptographic operations.
-
-
-
Constructor Detail
-
Builder
protected Builder(@Nonnull RecordSerializer<M> inner)
-
-
Method Detail
-
setCompressWhenSerializing
public TransformedRecordSerializerJCE.Builder<M> setCompressWhenSerializing(boolean compressWhenSerializing)
Description copied from class:TransformedRecordSerializer.Builder
Whether to compress records after serializing. Should compression and encryption both be set, then the data will be compressed before they are encrypted. By default, records are not compressed. The compression level can be specified withTransformedRecordSerializer.Builder.setCompressionLevel(int)
.- Overrides:
setCompressWhenSerializing
in classTransformedRecordSerializer.Builder<M extends Message>
- Parameters:
compressWhenSerializing
-true
if records should be compressed andfalse
otherwise- Returns:
- this
Builder
-
setCompressionLevel
public TransformedRecordSerializerJCE.Builder<M> setCompressionLevel(int level)
Description copied from class:TransformedRecordSerializer.Builder
Compression level to use if compressing. These should be the same levels as used by theDeflater
class (which are the same levels as used by zlib). The higher the level, the better the compression will be but the slower or more CPU intensive it will be. The default level if none is set here is 9. Setting this does not automatically enable compression when serializing.- Overrides:
setCompressionLevel
in classTransformedRecordSerializer.Builder<M extends Message>
- Parameters:
level
- the compression level (0-9)- Returns:
- this
Builder
- See Also:
Deflater
-
setEncryptWhenSerializing
public TransformedRecordSerializerJCE.Builder<M> setEncryptWhenSerializing(boolean encryptWhenSerializing)
Whether to encrypt records after serializing. Should compression and encryption both be set, then data will be compressed before they are encrypted. If enabled, the user must also callsetEncryptionKey(Key)
to specify the encryption key.- Overrides:
setEncryptWhenSerializing
in classTransformedRecordSerializer.Builder<M extends Message>
- Parameters:
encryptWhenSerializing
-true
if records should be encrypted andfalse
otherwise- Returns:
- this
Builder
-
setEncryptionKey
public TransformedRecordSerializerJCE.Builder<M> setEncryptionKey(@Nonnull Key encryptionKey)
Specifies the encryption key used to encrypt or decrypt a record. If this is not specified and encryption when serializing is enabled, then this builder will fail to build. If this is not specified, and records are not to be encrypted when serialized but an encrypted record is encountered when attempting to deserialize a record, then deserialization will fail with aRecordSerializationException
.- Parameters:
encryptionKey
- key to supply to encryption method- Returns:
- this
Builder
-
setCipherName
public TransformedRecordSerializerJCE.Builder<M> setCipherName(@Nonnull String cipherName)
Specifies the cipher algorithm used to encrypt or decrypt a record. If this is not specified, the default isAES/CBC/PKCS5Padding
.- Parameters:
cipherName
- name of the cipher algorithm to use- Returns:
- this
Builder
-
clearEncryption
public TransformedRecordSerializerJCE.Builder<M> clearEncryption()
Clears a previously specified key and provider that might have been passed to thisBuilder
.- Returns:
- this
Builder
-
setSecureRandom
public TransformedRecordSerializerJCE.Builder<M> setSecureRandom(@Nonnull SecureRandom secureRandom)
Sets the secure random number generator used during cryptographic operations. If none is specified but encryption is enabled, then a new one will be created when theTransformedRecordSerializerJCE
is built.- Parameters:
secureRandom
- a secure random number generator- Returns:
- this
Builder
-
clearSecureRandom
public TransformedRecordSerializerJCE.Builder<M> clearSecureRandom()
Clears a previously set secure random number generator that might have been passed to thisBuilder
.- Returns:
- this
Builder
-
build
public TransformedRecordSerializerJCE<M> build()
Construct aTransformedRecordSerializerJCE
from the parameters specified by this builder. If one has enabled encryption at serialization time, then this will fail with anRecordCoreArgumentException
.- Overrides:
build
in classTransformedRecordSerializer.Builder<M extends Message>
- Returns:
- a
TransformedRecordSerializerJCE
from thisBuilder
- Throws:
RecordCoreArgumentException
- if encryption is enabled when serializing but no encryption is specified
-
-