// ----------------------------------------------------- Instance Variables
- protected DataInputStream randomIS=null;
- protected String devRandomSource="/dev/urandom";
+ protected DataInputStream randomIS = null;
+ protected String devRandomSource = "/dev/urandom";
+ protected boolean devRandomSourceIsValid = true;
/**
* The default message digest algorithm to use if we cannot use
@Override
public DataInputStream run(){
+ devRandomSourceIsValid = true;
try {
File f=new File( devRandomSource );
- if( ! f.exists() ) return null;
+ if( ! f.exists() ) {
+ devRandomSourceIsValid = false;
+ return null;
+ }
randomIS= new DataInputStream( new FileInputStream(f));
randomIS.readLong();
if( log.isDebugEnabled() )
log.warn("Failed to close randomIS.");
}
}
- devRandomSource = null;
+ devRandomSourceIsValid = false;
randomIS=null;
return null;
}
* - so use it if available.
*/
public void setRandomFile( String s ) {
+ // Assume the source is valid until proved otherwise
+ devRandomSourceIsValid = true;
// as a hack, you can use a static file - and generate the same
// session ids ( good for strange debugging )
if (Globals.IS_SECURITY_ENABLED){
try{
devRandomSource=s;
File f=new File( devRandomSource );
- if( ! f.exists() ) return;
+ if (!f.exists()) {
+ devRandomSourceIsValid = false;
+ return;
+ }
randomIS= new DataInputStream( new FileInputStream(f));
randomIS.readLong();
if( log.isDebugEnabled() )
log.warn("Failed to close randomIS.");
}
}
- devRandomSource = null;
+ devRandomSourceIsValid = false;
randomIS=null;
}
}
protected void getRandomBytes(byte bytes[]) {
// Generate a byte array containing a session identifier
- if (devRandomSource != null && randomIS == null) {
+ if (devRandomSourceIsValid && randomIS == null) {
setRandomFile(devRandomSource);
}
if (randomIS != null) {
} catch (Exception ex) {
// Ignore
}
- devRandomSource = null;
+ devRandomSourceIsValid = false;
try {
randomIS.close();