Code example for TimeUnit

Methods: convert, sleep

0
    protected String getTag() {
        return TAG;
    } 
 
    private void waitForNextRecord(long startingTime, double timestampSeconds) {
        long timestamp = TimeUnit.NANOSECONDS.convert(
                (long)(timestampSeconds * 1000), TimeUnit.MILLISECONDS);
        if(mFirstTimestamp == null) {
            mFirstTimestamp = Long.valueOf(timestamp);
            Log.d(TAG, "Storing " + mFirstTimestamp + " as the first " +
                    "timestamp of the trace file"); 
        } 
        long targetTime = startingTime + (timestamp - mFirstTimestamp);
        long sleepDuration = TimeUnit.MILLISECONDS.convert(
                targetTime - System.nanoTime(), TimeUnit.NANOSECONDS);
        sleepDuration = Math.max(sleepDuration, 0);
        try { 
            Thread.sleep(sleepDuration);
        } catch(InterruptedException e) {}
    } 
 
    private BufferedReader openResourceFile(URI filename) {
        InputStream stream;