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 void
close()
Close this file sequencer.void
createSequence(java.lang.String driveId, java.lang.String authId)
Create a sequence for the drive ID and auth ID provided.protected java.lang.String
getContents()
Get the contents of a sequence file.NonceSequence
getSequence(java.lang.String driveId)
Get the sequence by the drive ID.IFile
getSequenceFile()
Get the file used by this sequencer.void
initializeSequence(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.void
revokeSequence(java.lang.String driveId)
Revoke the current sequence for a specific drive.protected void
saveContents(java.lang.String contents)
Save the contents of the fileprotected void
saveSequenceFile(java.util.HashMap<java.lang.String,NonceSequence> sequences)
Save the sequence file.void
setMaxNonce(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:
createSequence
in 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.IOException
Initialize the sequence.- Specified by:
initializeSequence
in 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:
setMaxNonce
in 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:
nextNonce
in 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:
revokeSequence
in 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:
getSequence
in 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:
close
in 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
-
-