Package com.mku.salmonfs.sequence
Class FileSequencer
- java.lang.Object
-
- com.mku.salmonfs.sequence.FileSequencer
-
- All Implemented Interfaces:
INonceSequencer
- Direct Known Subclasses:
WinFileSequencer
public class FileSequencer extends java.lang.Object implements INonceSequencer
Generates nonces based on a sequencer backed by a file.
-
-
Constructor Summary
Constructors Constructor Description FileSequencer(IFile sequenceFile, INonceSequenceSerializer serializer)Instantiate a nonce file sequencer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close this file sequencer.voidcreateSequence(java.lang.String driveId, java.lang.String authId)Create a sequence for the drive ID and auth ID provided.protected java.lang.StringgetContents()Get the contents of a sequence file.NonceSequencegetSequence(java.lang.String driveId)Get the sequence by the drive ID.IFilegetSequenceFile()Get the file used by this sequencer.voidinitializeSequence(java.lang.String driveId, java.lang.String authId, byte[] startNonce, byte[] maxNonce)Initialize the sequence.byte[]nextNonce(java.lang.String driveId)Get the next nonce.voidrevokeSequence(java.lang.String driveId)Revoke the current sequence for a specific drive.protected voidsaveContents(java.lang.String contents)Save the contents of the fileprotected voidsaveSequenceFile(java.util.HashMap<java.lang.String,NonceSequence> sequences)Save the sequence file.voidsetMaxNonce(java.lang.String driveId, java.lang.String authId, byte[] maxNonce)Set the maximum nonce.
-
-
-
Constructor Detail
-
FileSequencer
public FileSequencer(IFile sequenceFile, INonceSequenceSerializer serializer) throws java.io.IOException
Instantiate a nonce file sequencer.- Parameters:
sequenceFile- The sequence file.serializer- The serializer to be used.- Throws:
java.io.IOException- Thrown if there is an IO error.SequenceException- Thrown if there is an error with the nonce sequence
-
-
Method Detail
-
getSequenceFile
public IFile getSequenceFile()
Get the file used by this sequencer.- Returns:
- The file.
-
createSequence
public void createSequence(java.lang.String driveId, java.lang.String authId)Create a sequence for the drive ID and auth ID provided.- Specified by:
createSequencein interfaceINonceSequencer- Parameters:
driveId- The drive ID.authId- The authorization ID of the drive.- Throws:
SequenceException- Thrown if there is an error with the nonce sequence
-
initializeSequence
public void initializeSequence(java.lang.String driveId, java.lang.String authId, byte[] startNonce, byte[] maxNonce) throws java.io.IOExceptionInitialize the sequence.- Specified by:
initializeSequencein interfaceINonceSequencer- Parameters:
driveId- The drive ID.authId- The auth ID of the device for the drive.startNonce- The starting nonce.maxNonce- The maximum nonce.- Throws:
SequenceException- Thrown if there is an error with the nonce sequencejava.io.IOException- Thrown if there is an IO error.
-
setMaxNonce
public void setMaxNonce(java.lang.String driveId, java.lang.String authId, byte[] maxNonce)Set the maximum nonce.- Specified by:
setMaxNoncein interfaceINonceSequencer- Parameters:
driveId- The drive ID.authId- The auth ID of the device for the drive.maxNonce- The maximum nonce.- Throws:
SequenceException- Thrown if there is an error with the nonce sequence
-
nextNonce
public byte[] nextNonce(java.lang.String driveId)
Get the next nonce.- Specified by:
nextNoncein interfaceINonceSequencer- Parameters:
driveId- The drive ID.- Returns:
- The next nonce
- Throws:
SequenceException- Thrown if there is an error with the nonce sequenceRangeExceededException- Thrown if the nonce exceeds its range
-
getContents
protected java.lang.String getContents()
Get the contents of a sequence file.- Returns:
- The contents
- Throws:
SequenceException- Thrown if there is an error with the nonce sequence
-
revokeSequence
public void revokeSequence(java.lang.String driveId)
Revoke the current sequence for a specific drive.- Specified by:
revokeSequencein interfaceINonceSequencer- Parameters:
driveId- The drive ID.- Throws:
SequenceException- Thrown if there is an error with the nonce sequence
-
getSequence
public NonceSequence getSequence(java.lang.String driveId)
Get the sequence by the drive ID.- Specified by:
getSequencein interfaceINonceSequencer- Parameters:
driveId- The drive ID.- Returns:
- The sequence
- Throws:
SequenceException- Thrown if there is an error with the nonce sequence
-
close
public void close()
Close this file sequencer.- Specified by:
closein interfaceINonceSequencer
-
saveSequenceFile
protected void saveSequenceFile(java.util.HashMap<java.lang.String,NonceSequence> sequences)
Save the sequence file.- Parameters:
sequences- The sequences.- Throws:
SequenceException- Thrown if there is an error with the nonce sequence
-
saveContents
protected void saveContents(java.lang.String contents)
Save the contents of the file- Parameters:
contents- The contents
-
-