Initial commit
This commit is contained in:
commit
bfbe536886
59 files changed
+2540
No files matched your search
@@ -0,0 +1,49 @@
|
||||
package org.scribe.services;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TimestampServiceImpl implements TimestampService
|
||||
{
|
||||
|
||||
private Timer timer;
|
||||
|
||||
public TimestampServiceImpl()
|
||||
{
|
||||
timer = new Timer();
|
||||
}
|
||||
|
||||
public String getNonce()
|
||||
{
|
||||
Long ts = getTs();
|
||||
return String.valueOf(ts + timer.getRandomInteger());
|
||||
}
|
||||
|
||||
public String getTimestampInSeconds()
|
||||
{
|
||||
return String.valueOf(getTs());
|
||||
}
|
||||
|
||||
private Long getTs()
|
||||
{
|
||||
return timer.getMilis() / 1000;
|
||||
}
|
||||
|
||||
void setTimer(Timer timer)
|
||||
{
|
||||
this.timer = timer;
|
||||
}
|
||||
|
||||
static class Timer
|
||||
{
|
||||
public Long getMilis()
|
||||
{
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public Integer getRandomInteger()
|
||||
{
|
||||
return new Random().nextInt();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user