Example usage for java.util Date getTime

List of usage examples for java.util Date getTime

Introduction

In this page you can find the example usage for java.util Date getTime.

Prototype

public long getTime() 

Source Link

Document

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

Usage

From source file:com.krawler.common.timezone.Timezone.java

public static void main(String[] args) {
    Connection conn = null;//from  ww w  .j a va 2  s .  c  o m
    try {
        java.util.Date post_time = Timezone.getGmtDate();
        java.sql.Timestamp sqlPostDate = new java.sql.Timestamp(post_time.getTime());
        conn = DbPool.getConnection();
        String c = "examdate";
        String t = "lexamschedule";
        String tZ = "+08:00";
        Date gmtDate = getGmtDate();
        String date = "2008-05-21";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-dd-MM");
        //            sdf.parse(date);
        Date newGmtDate = getGmtDate(sdf.parse(date));
        //String date = "2008-05-21 15:30:00";
        String uid = "08b18f8b-86ca-4d5b-a7a0-f576d50e7cb0"; //timezone == 2
        System.out.println(getGmtDate(conn, date, uid));

    } catch (Exception e) {
        System.out.println("You have an error: " + e);
    } finally {
        DbPool.quietClose(conn);
    }
}

From source file:de.uniwue.dmir.heatmap.EntryPointIncremental.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) throws IOException, ParseException {

    DateFormat df = new SimpleDateFormat(DATE_FORMAT);
    SimpleDateFormat backupDf = new SimpleDateFormat(BACKUP_DATE_FORMAT);

    String workDir = System.getProperty("workDir", ".");
    LOGGER.debug("Work dir: {}", workDir);
    String configDir = System.getProperty("configDir", ".");
    LOGGER.debug("Config dir: {}", configDir);

    File seedDir = new File(workDir, SEED_DIR);
    LOGGER.debug("Seed dir: {}", seedDir);
    File currentDir = new File(workDir, CURRENT_DIR);
    LOGGER.debug("Current dir: {}", currentDir);
    File backupDir = new File(workDir, BACKUP_DIR);
    LOGGER.debug("Backup dir: {}", backupDir);

    String initialMinTimeString = System.getProperty("minTime");
    LOGGER.debug("Initial minimal time parameter: {}", initialMinTimeString);
    Date initialMinTime = initialMinTimeString == null ? new Date(0) : df.parse(initialMinTimeString);
    LOGGER.debug("Initial minimal time: {}", df.format(initialMinTime));

    String absoluteMaxTimeString = System.getProperty("maxTime");
    LOGGER.debug("Absolute maximal time parameter: {}", absoluteMaxTimeString);
    Date absoluteMaxTime = absoluteMaxTimeString == null ? new Date()
            : new SimpleDateFormat(DATE_FORMAT).parse(absoluteMaxTimeString);
    LOGGER.debug("Absolute maximal time: {}", df.format(absoluteMaxTime));

    String incrementalFile = new File("file:" + configDir, INCREMENTAL_FILE).getPath();
    String settingsFile = new File("file:" + configDir, HEATMAP_PROCESSOR__FILE).getPath();

    LOGGER.debug("Initializing incremental control file: {}", incrementalFile);
    FileSystemXmlApplicationContext incrementalContext = new FileSystemXmlApplicationContext(incrementalFile);

    // get point limit
    int pointLimit = Integer
            .parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${point.limit}"));
    LOGGER.debug("Print limit: {}", pointLimit);

    // get backups to keep
    int backupsToKeep = Integer
            .parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${backups.to.keep}"));
    LOGGER.debug("Backups to keep: {}", pointLimit);

    LOGGER.debug("Initializing process components (manager and limiter).");
    IProcessManager processManager = incrementalContext.getBean(IProcessManager.class);
    IProcessLimiter processLimiter = incrementalContext.getBean(IProcessLimiter.class);

    LOGGER.debug("Starting incremental loop.");
    while (true) { // break as soon as no new points are available

        // cleanup --- just in case
        LOGGER.debug("Deleting \"current\" dir.");
        FileUtils.deleteDirectory(currentDir);

        // copy from seed to current
        LOGGER.debug("Copying seed.");
        seedDir.mkdirs();/*from  ww w .j av  a 2 s . co m*/
        FileUtils.copyDirectory(seedDir, currentDir);

        // get min time
        LOGGER.debug("Getting minimal time ...");
        Date minTime = initialMinTime;
        ProcessManagerEntry entry = processManager.getEntry();
        if (entry != null && entry.getMaxTime() != null) {
            minTime = entry.getMaxTime();
        }
        LOGGER.debug("Minimal time: {}", new SimpleDateFormat(DATE_FORMAT).format(minTime));

        // break if we processed all available points (minTime is greater than or equal to absoluteMaxTime)
        if (minTime.getTime() >= absoluteMaxTime.getTime()) {
            LOGGER.debug("Processed all points.");
            break;
        }

        // get the maximal time
        LOGGER.debug("Get maximal time.");

        // get the time from the newest point in our point range (pointMaxTime) ...
        Date pointMaxTime = processLimiter.getMaxTime(minTime, pointLimit);

        // ... and possibly break the loop if no new points are available
        if (pointMaxTime == null)
            break;

        // set the max time and make sure we are not taking to many points 
        // (set max time to the minimum of pointMaxTime and absoluteMaxTime)
        Date maxTime = pointMaxTime.getTime() > absoluteMaxTime.getTime() ? absoluteMaxTime : pointMaxTime;

        LOGGER.debug("Maximal time: {}", new SimpleDateFormat(DATE_FORMAT).format(maxTime));

        // start process
        processManager.start(minTime);

        System.setProperty("minTimestamp", new SimpleDateFormat(DATE_FORMAT).format(minTime));

        System.setProperty("maxTimestamp", new SimpleDateFormat(DATE_FORMAT).format(maxTime));

        FileSystemXmlApplicationContext heatmapContext = new FileSystemXmlApplicationContext(settingsFile);

        IHeatmap heatmap = heatmapContext.getBean(HEATMAP_BEAN, IHeatmap.class);

        ITileProcessor tileProcessor = heatmapContext.getBean(WRITER_BEAN, ITileProcessor.class);

        heatmap.processTiles(tileProcessor);

        tileProcessor.close();
        heatmapContext.close();

        // finish process
        processManager.finish(maxTime);

        // move old seed
        if (backupsToKeep > 0) {
            FileUtils.moveDirectory(seedDir, new File(backupDir, backupDf.format(minTime))); // minTime is the maxTime of the seed

            // cleanup backups
            String[] backups = backupDir.list(DirectoryFileFilter.DIRECTORY);
            File oldestBackup = null;
            if (backups.length > backupsToKeep) {
                for (String bs : backups) {
                    File b = new File(backupDir, bs);
                    if (oldestBackup == null || oldestBackup.lastModified() > b.lastModified()) {
                        oldestBackup = b;
                    }
                }
                FileUtils.deleteDirectory(oldestBackup);
            }

        } else {
            FileUtils.deleteDirectory(seedDir);
        }

        // move new seed
        FileUtils.moveDirectory(currentDir, seedDir);

    }

    incrementalContext.close();

}

From source file:com.yobidrive.diskmap.buckets.BucketTableManager.java

public static void main(String[] args) {

    try {//w w  w . j  a v a 2  s.com
        BucketTableManager nw = new BucketTableManager("/Users/Francois/Documents/NEEDLES/0.TestStore", 100,
                1000000, 3000L, true);

        nw.initialize();
        System.out.println(
                "Bucket table initialization: " + (nw.getCheckPoint().isEmpty() ? " Repair required" : " OK"));

        Runtime runtime = Runtime.getRuntime();
        long before = runtime.totalMemory() - runtime.freeMemory();

        nw.getCheckPoint().copyFrom(new NeedlePointer()); // reset checkpoint

        Date startDate = new Date();
        Date lapDate = new Date();
        System.out.println("Start test for " + TEST_COUNT + " pointers");
        long counter = 0;
        long lapCounter = 0;
        long offset = 0;
        BucketFNVHash hashFunc = new BucketFNVHash(1000000000L);
        while (counter < TEST_COUNT) {
            NeedlePointer needlePointer = new NeedlePointer();
            String key = "MYVERYNICEKEY" + counter;
            long bucket = hashFunc.hash(key);
            needlePointer.setNeedleFileNumber(4);
            needlePointer.setNeedleOffset(offset++);
            nw.writeNeedlePointer(bucket, needlePointer);
            counter++;
            Date lapDate2 = new Date();
            long spent = lapDate2.getTime() - lapDate.getTime();
            if (spent >= 1000 || (counter - lapCounter > TARGET_TPS)) { // Check each second or target tps
                if (spent < 1000) { // pause when tps reached
                    Thread.sleep(1000 - spent);
                    System.out.print(".");
                } else
                    System.out.print("*");
                lapDate = lapDate2; // Reset lap time
                lapCounter = counter; // Reset tps copunter
            }
        }
        long timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nWriting before cache commit of " + TEST_COUNT + " pointers \n"
                + "\tTotal time: " + timeSpent / 1000 + "s\n" + "\tThroughput: "
                + (TEST_COUNT / timeSpent * 1000) + " tps");

        timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nProcessed writing of " + TEST_COUNT + " pointers \n" + "\tTotal time: "
                + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT / timeSpent * 1000) + " tps");
        System.out.println("Max cycle time = " + (nw.getMaxCycleTimePass1() + nw.getMaxCycleTimePass2()));

    } catch (Throwable th) {
        th.printStackTrace();
    }

}

From source file:com.yobidrive.diskmap.DiskMapStore.java

public static void main(String[] args) {

    try {//from  w  ww  . j a  v  a  2  s.  c o  m
        BasicConfigurator.configure();
        //   (String storeName, String logPath, String keyPath, long ckeckPointPeriod, long logSize, int keySize,
        //      long mapSize, int packInterval, int readThreads, long needleCachedEntries, long bucketCachedBytes, short nodeId)

        /* String path = "/Users/david/Documents/NEEDLES";
        if ( args.length > 0) {
           path = args[0];
        }
        System.out.println("Using directory:" + path);
        */

        DiskMapStore dms = new DiskMapStore("teststore", "/drive_hd1;/drive_hd2", "/drive_ssd/storage_indexes",
                1000L, // Synching period
                60000 * 5L, // Checkpointing period
                2000000000L, // Log file size
                100, // Key max size
                2048, // Nb of buffers
                32768, // Nb of entries (buckets) per buffer
                60, // Compact interval
                8, // Read threads
                TEST_COUNT / 3 * 2 * 140, // NeedleHeaderCachedEntries (1/20 in cache, 1/2 of typical data set)
                TEST_COUNT / 3 * 2 * 140, // NeedleCachedBytes (3% of Map, weights 120 bytes/entry)
                true, // Use needle average age instead of needle yougest age
                (short) 0, 1, 1, 1);
        // dmm.getBtm().getCheckPoint().copyFrom(new NeedlePointer()) ; // Removes checkpoint
        dms.initialize();
        // System.out.println("Start read for "+TEST_COUNT+" pointers") ;
        Date startDate = new Date();
        Date lapDate = new Date();
        System.out.println("Start read test for " + TEST_COUNT + " pointers");
        long counter = 0;
        long lapCounter = 0;
        startDate = new Date();
        lapDate = new Date();
        long failCount = 0;
        counter = 0;
        while (counter < TEST_COUNT) {
            String key = "MYVERYNICELEY" + counter;
            // System.out.println("key="+key+"...") ;
            List<Versioned<byte[]>> values = dms.get(new ByteArray(key.getBytes("UTF-8")), null);
            if (values.size() <= 0) {
                failCount++;
            } else {
                // Gets previous version   
                byte[] value = values.get(0).getValue();
                if (value == null)
                    failCount++;
                else if (value[0] != (byte) ((short) counter % 128))
                    failCount++;
            }
            counter++;
            Date lapDate2 = new Date();
            long spent = lapDate2.getTime() - lapDate.getTime();
            if (spent >= 1000 || (counter - lapCounter > TARGET_TPSR)) { // Check each second or target tps
                if (spent < 1000) { // pause when tps reached
                    Thread.sleep(1000 - spent);
                    // System.out.print(".") ;
                } else
                    // System.out.print("*") ;
                    lapDate = lapDate2; // Reset lap time
                lapCounter = counter; // Reset tps copunter
            }
        }
        long timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nProcessed reading of " + TEST_COUNT + " pointers \n" + "\tTotal time: "
                + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT * 1000 / timeSpent) + " tps\n"
                + "\tBad results: " + failCount);

        startDate = new Date();
        lapDate = new Date();
        System.out.println("Start write test for " + TEST_COUNT + " pointers");
        counter = 0;
        lapCounter = 0;

        while (counter < TEST_COUNT) {
            String key = "MYVERYNICELEY" + counter;
            // System.out.println("key="+key+"...") ;
            byte[] value = new byte[128000];
            value[0] = (byte) ((short) counter % 128);
            long chaseDurer = new Date().getTime();
            List<Versioned<byte[]>> previousValues = dms.get(new ByteArray(key.getBytes("UTF-8")), null);
            long chaseDurer2 = new Date().getTime();
            // System.out.println("Get in "+(chaseDurer2 -chaseDurer)+"ms") ;
            chaseDurer = chaseDurer2;
            Version newVersion = null;
            if (previousValues.size() <= 0) {
                newVersion = new VectorClock();
            } else {
                // Gets previous version
                newVersion = previousValues.get(0).cloneVersioned().getVersion();
            }
            // Increment version before writing
            ((VectorClock) newVersion).incrementVersion(0, new Date().getTime());
            Versioned<byte[]> versionned = new Versioned<byte[]>(
                    previousValues.size() <= 0 ? value : previousValues.get(0).cloneVersioned().getValue(),
                    newVersion);
            dms.put(new ByteArray(key.getBytes("UTF-8")), versionned, null);
            chaseDurer2 = new Date().getTime();
            // System.out.println("Put in "+(chaseDurer2 -chaseDurer)+"ms") ;
            // dmm.putValue(key.getBytes("UTF-8"), value) ;
            counter++;
            Date lapDate2 = new Date();
            long spent = lapDate2.getTime() - lapDate.getTime();
            if (spent >= 1000 || (counter - lapCounter > TARGET_TPS)) { // Check each second or target tps
                if (spent < 1000) { // pause when tps reached
                    Thread.sleep(1000 - spent);
                    // System.out.print("("+counter+")") ;
                } else
                    // System.out.print("["+counter+"]") ;
                    lapDate = lapDate2; // Reset lap time
                lapCounter = counter; // Reset tps copunter
            }
        }

        timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nWriting before cache commit of " + TEST_COUNT + " pointers \n"
                + "\tTotal time: " + timeSpent / 1000 + "s\n" + "\tThroughput: "
                + (TEST_COUNT * 1000 / timeSpent) + " tps");

        System.out.println("Start read for " + TEST_COUNT + " pointers");
        startDate = new Date();
        lapDate = new Date();
        failCount = 0;
        counter = 0;
        while (counter < TEST_COUNT) {
            String key = "MYVERYNICELEY" + counter;
            // System.out.println("key="+key+"...") ;
            List<Versioned<byte[]>> values = dms.get(new ByteArray(key.getBytes("UTF-8")), null);
            if (values.size() <= 0) {
                failCount++;
            } else {
                // Gets previous version   
                byte[] value = values.get(0).getValue();
                if (value == null)
                    failCount++;
                else if (value[0] != (byte) ((short) counter % 128))
                    failCount++;
            }
            counter++;
            Date lapDate2 = new Date();
            long spent = lapDate2.getTime() - lapDate.getTime();
            if (spent >= 1000 || (counter - lapCounter > TARGET_TPSR)) { // Check each second or target tps
                if (spent < 1000) { // pause when tps reached
                    Thread.sleep(1000 - spent);
                    // System.out.print(".") ;
                } else
                    // System.out.print("*") ;
                    lapDate = lapDate2; // Reset lap time
                lapCounter = counter; // Reset tps copunter
            }
        }
        timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nProcessed reading of " + TEST_COUNT + " pointers \n" + "\tTotal time: "
                + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT * 1000 / timeSpent) + " tps\n"
                + "\tBad results: " + failCount);

        dms.close();
        // System.out.println("Max cycle time = "+ (dms.getBtm().getMaxCycleTimePass1()+dmm.getBtm().getMaxCycleTimePass2())) ;

    } catch (Throwable th) {
        th.printStackTrace();
    }

}

From source file:com.radvision.icm.service.vcm.ICMService.java

public static void main(String[] args) {
    long currTime = System.currentTimeMillis();
    //      long tmpTime = currTime - 24 * 60 * 60 * 1000;
    Date dt = new Date(currTime);
    //      Calendar cal = Calendar.getInstance();
    //      cal.setTime(dt);
    //      System.out.println(cal);

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    String s = df.format(dt);//from   w w  w  . j a  va2  s .  com
    System.out.println(s);
    try {
        Date dtNew = df.parse(s);
        long newTime = dtNew.getTime();
        long minutes = (currTime - newTime) / (1000 * 60);
        System.out.println(minutes / 60 + ":" + minutes % 60);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:de.tudarmstadt.ukp.dariah.pipeline.RunPipeline.java

public static void main(String[] args) {

    Date startDate = new Date();

    PrintStream ps;/*from  w w  w.  j  a v a 2  s  .com*/
    try {
        ps = new PrintStream("error.log");
        System.setErr(ps);
    } catch (FileNotFoundException e) {
        System.out.println("Errors cannot be redirected");
    }

    try {
        if (!parseArgs(args)) {
            System.out.println("Usage: java -jar pipeline.jar -help");
            System.out.println("Usage: java -jar pipeline.jar -input <Input File> -output <Output Folder>");
            System.out.println(
                    "Usage: java -jar pipeline.jar -config <Config File> -input <Input File> -output <Output Folder>");
            return;
        }
    } catch (ParseException e) {
        e.printStackTrace();
        System.out.println(
                "Error when parsing command line arguments. Use\njava -jar pipeline.jar -help\n to get further information");
        System.out.println("See error.log for further details");
        return;
    }

    LinkedList<String> configFiles = new LinkedList<>();

    String configFolder = "configs/";
    configFiles.add(configFolder + "default.properties");

    //Language dependent properties file
    String path = configFolder + "default_" + optLanguage + ".properties";
    File f = new File(path);
    if (f.exists()) {
        configFiles.add(path);
    } else {
        System.out.println("Language config file: " + path + " not found");
    }

    String[] configFileArg = new String[0];
    for (int i = 0; i < args.length - 1; i++) {
        if (args[i].equals("-config")) {
            configFileArg = args[i + 1].split("[,;]");
            break;
        }
    }

    for (String configFile : configFileArg) {

        f = new File(configFile);
        if (f.exists()) {
            configFiles.add(configFile);
        } else {
            //Check in configs folder
            path = configFolder + configFile;

            f = new File(path);
            if (f.exists()) {
                configFiles.add(path);
            } else {
                System.out.println("Config file: " + configFile + " not found");
                return;
            }
        }
    }

    for (String configFile : configFiles) {
        try {
            parseConfig(configFile);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Exception when parsing config file: " + configFile);
            System.out.println("See error.log for further details");
        }
    }

    printConfiguration(configFiles.toArray(new String[0]));

    try {

        // Read in the input files
        String defaultFileExtension = (optReader == ReaderType.XML) ? ".xml" : ".txt";

        GlobalFileStorage.getInstance().readFilePaths(optInput, defaultFileExtension, optOutput, optResume);

        System.out.println("Process " + GlobalFileStorage.getInstance().size() + " files");

        CollectionReaderDescription reader;

        if (optReader == ReaderType.XML) {
            reader = createReaderDescription(XmlReader.class, XmlReader.PARAM_LANGUAGE, optLanguage);
        } else {
            reader = createReaderDescription(TextReaderWithInfo.class, TextReaderWithInfo.PARAM_LANGUAGE,
                    optLanguage);
        }

        AnalysisEngineDescription paragraph = createEngineDescription(ParagraphSplitter.class,
                ParagraphSplitter.PARAM_SPLIT_PATTERN,
                (optParagraphSingleLineBreak) ? ParagraphSplitter.SINGLE_LINE_BREAKS_PATTERN
                        : ParagraphSplitter.DOUBLE_LINE_BREAKS_PATTERN);

        AnalysisEngineDescription seg = createEngineDescription(optSegmenterCls, optSegmenterArguments);

        AnalysisEngineDescription paragraphSentenceCorrector = createEngineDescription(
                ParagraphSentenceCorrector.class);

        AnalysisEngineDescription frenchQuotesSeg = createEngineDescription(PatternBasedTokenSegmenter.class,
                PatternBasedTokenSegmenter.PARAM_PATTERNS, "+|[]");

        AnalysisEngineDescription quotesSeg = createEngineDescription(PatternBasedTokenSegmenter.class,
                PatternBasedTokenSegmenter.PARAM_PATTERNS, "+|[\"\"]");

        AnalysisEngineDescription posTagger = createEngineDescription(optPOSTaggerCls, optPOSTaggerArguments);

        AnalysisEngineDescription lemma = createEngineDescription(optLemmatizerCls, optLemmatizerArguments);

        AnalysisEngineDescription chunker = createEngineDescription(optChunkerCls, optChunkerArguments);

        AnalysisEngineDescription morph = createEngineDescription(optMorphTaggerCls, optMorphTaggerArguments);

        AnalysisEngineDescription hyphenation = createEngineDescription(optHyphenationCls,
                optHyphenationArguments);

        AnalysisEngineDescription depParser = createEngineDescription(optDependencyParserCls,
                optDependencyParserArguments);

        AnalysisEngineDescription constituencyParser = createEngineDescription(optConstituencyParserCls,
                optConstituencyParserArguments);

        AnalysisEngineDescription ner = createEngineDescription(optNERCls, optNERArguments);

        AnalysisEngineDescription directSpeech = createEngineDescription(DirectSpeechAnnotator.class,
                DirectSpeechAnnotator.PARAM_START_QUOTE, optStartQuote);

        AnalysisEngineDescription srl = createEngineDescription(optSRLCls, optSRLArguments); //Requires DKPro 1.8.0   

        AnalysisEngineDescription coref = createEngineDescription(optCorefCls, optCorefArguments); //StanfordCoreferenceResolver.PARAM_POSTPROCESSING, true

        AnalysisEngineDescription writer = createEngineDescription(DARIAHWriter.class,
                DARIAHWriter.PARAM_TARGET_LOCATION, optOutput, DARIAHWriter.PARAM_OVERWRITE, true);

        AnalysisEngineDescription annWriter = createEngineDescription(AnnotationWriter.class);

        AnalysisEngineDescription noOp = createEngineDescription(NoOpAnnotator.class);

        System.out.println("\nStart running the pipeline (this may take a while)...");

        while (!GlobalFileStorage.getInstance().isEmpty()) {
            try {
                SimplePipeline.runPipeline(reader, paragraph, (optSegmenter) ? seg : noOp,
                        paragraphSentenceCorrector, frenchQuotesSeg, quotesSeg,
                        (optPOSTagger) ? posTagger : noOp, (optLemmatizer) ? lemma : noOp,
                        (optChunker) ? chunker : noOp, (optMorphTagger) ? morph : noOp,
                        (optHyphenation) ? hyphenation : noOp, directSpeech,
                        (optDependencyParser) ? depParser : noOp,
                        (optConstituencyParser) ? constituencyParser : noOp, (optNER) ? ner : noOp,
                        (optSRL) ? srl : noOp, //Requires DKPro 1.8.0
                        (optCoref) ? coref : noOp, writer
                //                  ,annWriter
                );
            } catch (OutOfMemoryError e) {
                System.out.println("Out of Memory at file: "
                        + GlobalFileStorage.getInstance().getLastPolledFile().getAbsolutePath());
            }
        }

        Date enddate = new Date();
        double duration = (enddate.getTime() - startDate.getTime()) / (1000 * 60.0);

        System.out.println("---- DONE -----");
        System.out.printf("All files processed in %.2f minutes", duration);
    } catch (ResourceInitializationException e) {
        System.out.println("Error when initializing the pipeline.");
        if (e.getCause() instanceof FileNotFoundException) {
            System.out.println("File not found. Maybe the input / output path is incorrect?");
            System.out.println(e.getCause().getMessage());
        }

        e.printStackTrace();
        System.out.println("See error.log for further details");
    } catch (UIMAException e) {
        e.printStackTrace();
        System.out.println("Error in the pipeline.");
        System.out.println("See error.log for further details");
    } catch (IOException e) {
        e.printStackTrace();
        System.out
                .println("Error while reading or writing to the file system. Maybe some paths are incorrect?");
        System.out.println("See error.log for further details");
    }

}

From source file:com.jdo.CloudContactUtils.java

public static void main(String[] args) {
    //   //  www .  j a  va  2  s.  c om
    //     List<CloudContactNotification> lc=new ArrayList<CloudContactNotification>();
    //     CloudContactNotification a=new CloudContactNotification();
    //     a.setLastAccess(""+new Date().getTime());
    //     a.setText("tt");
    //     a.setUserName("dhaneesh");
    //     lc.add(a);
    //     
    //     System.out.println(JSONObject.wrap(lc));
    //   

    try {
        //Asia/Calcutta
        String[] allTimeZones = TimeZone.getAvailableIDs();
        Date now = new Date();
        for (int i = 0; i < allTimeZones.length; i++) {
            //System.out.println(allTimeZones[i]);
            TimeZone tz = TimeZone.getTimeZone(allTimeZones[i]);
            System.out.format("%s;%s; %f \n", allTimeZones[i], tz.getDisplayName(),
                    (float) (tz.getOffset(now.getTime()) / 3600000.0));
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.yobidrive.diskmap.DiskMapManager.java

public static void main(String[] args) {

    try {//from  w  w w  . j  a v  a 2s . co m
        BasicConfigurator.configure();
        //   (String storeName, String logPath, String keyPath, long ckeckPointPeriod, long logSize, int keySize,
        //      long mapSize, int packInterval, int readThreads, long needleCachedEntries, long bucketCachedBytes, short nodeId)

        /* String path = "/Users/david/Documents/NEEDLES";
        if ( args.length > 0) {
           path = args[0];
        }
        System.out.println("Using directory:" + path);
        */
        DiskMapManager dmm = new DiskMapManager("TestStore", "/drive_hd1", "/drive_ssd/storage_indexes", 1000, // Synching period
                60000 * 5, // Checkpointing period
                2000000000L, // Log file size
                100, // Key max size
                2048, // Nb of buffers
                32768, // Nb of entries (buckets) per buffer
                60, // Compact interval
                8, // Read threads
                TEST_COUNT / 3 * 2 * 140, // NeedleHeaderCachedEntries (1/20 in cache, 1/2 of typical data set)
                TEST_COUNT / 3 * 2 * 140, // NeedleCachedBytes (3% of Map, weights 120 bytes/entry)
                true, // Use needle average age instead of needle yougest age
                (short) 0, (short) 0, 0, new TokenSynchronizer(1), new TokenSynchronizer(1), null);
        // dmm.getBtm().getCheckPoint().copyFrom(new NeedlePointer()) ; // Removes checkpoint

        // System.out.println("Start read for "+TEST_COUNT+" pointers") ;
        Date startDate = new Date();
        Date lapDate = new Date();
        System.out.println("Start read test for " + TEST_COUNT + " pointers");
        long counter = 0;
        long lapCounter = 0;
        startDate = new Date();
        lapDate = new Date();
        long failCount = 0;
        counter = 0;
        while (counter < TEST_COUNT) {
            String key = "MYVERYNICELEY" + counter;
            // System.out.println("key="+key+"...") ;
            List<Versioned<byte[]>> values = dmm.get(key.getBytes("UTF-8"));
            if (values.size() <= 0) {
                failCount++;
            } else {
                // Gets previous version   
                byte[] value = values.get(0).getValue();
                if (value == null)
                    failCount++;
                else if (value[0] != (byte) ((short) counter % 128))
                    failCount++;
            }
            counter++;
            Date lapDate2 = new Date();
            long spent = lapDate2.getTime() - lapDate.getTime();
            if (spent >= 1000 || (counter - lapCounter > TARGET_TPSR)) { // Check each second or target tps
                if (spent < 1000) { // pause when tps reached
                    Thread.sleep(1000 - spent);
                    // System.out.print(".") ;
                } else
                    // System.out.print("*") ;
                    lapDate = lapDate2; // Reset lap time
                lapCounter = counter; // Reset tps copunter
            }
        }
        long timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nProcessed reading of " + TEST_COUNT + " pointers \n" + "\tTotal time: "
                + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT * 1000 / timeSpent) + " tps\n"
                + "\tBad results: " + failCount);

        startDate = new Date();
        lapDate = new Date();
        System.out.println("Start write test for " + TEST_COUNT + " pointers");
        counter = 0;
        lapCounter = 0;

        while (counter < TEST_COUNT) {
            String key = "MYVERYNICELEY" + counter;
            // System.out.println("key="+key+"...") ;
            byte[] value = new byte[128000];
            value[0] = (byte) ((short) counter % 128);
            long chaseDurer = new Date().getTime();
            List<Versioned<byte[]>> previousValues = dmm.get(key.getBytes("UTF-8"));
            long chaseDurer2 = new Date().getTime();
            // System.out.println("Get in "+(chaseDurer2 -chaseDurer)+"ms") ;
            chaseDurer = chaseDurer2;
            Version newVersion = null;
            if (previousValues.size() <= 0) {
                newVersion = new VectorClock();
            } else {
                // Gets previous version
                newVersion = previousValues.get(0).cloneVersioned().getVersion();
            }
            // Increment version before writing
            ((VectorClock) newVersion).incrementVersion(dmm.getNodeId(), new Date().getTime());
            dmm.put(key.getBytes("UTF-8"), value, newVersion);
            chaseDurer2 = new Date().getTime();
            // System.out.println("Put in "+(chaseDurer2 -chaseDurer)+"ms") ;
            // dmm.putValue(key.getBytes("UTF-8"), value) ;
            counter++;
            Date lapDate2 = new Date();
            long spent = lapDate2.getTime() - lapDate.getTime();
            if (spent >= 1000 || (counter - lapCounter > TARGET_TPS)) { // Check each second or target tps
                if (spent < 1000) { // pause when tps reached
                    Thread.sleep(1000 - spent);
                    // System.out.print("("+counter+")") ;
                } else
                    // System.out.print("["+counter+"]") ;
                    lapDate = lapDate2; // Reset lap time
                lapCounter = counter; // Reset tps copunter
            }
        }

        timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nWriting before cache commit of " + TEST_COUNT + " pointers \n"
                + "\tTotal time: " + timeSpent / 1000 + "s\n" + "\tThroughput: "
                + (TEST_COUNT * 1000 / timeSpent) + " tps");

        System.out.println("Start read for " + TEST_COUNT + " pointers");
        startDate = new Date();
        lapDate = new Date();
        failCount = 0;
        counter = 0;
        while (counter < TEST_COUNT) {
            String key = "MYVERYNICELEY" + counter;
            // System.out.println("key="+key+"...") ;
            List<Versioned<byte[]>> values = dmm.get(key.getBytes("UTF-8"));
            if (values.size() <= 0) {
                failCount++;
            } else {
                // Gets previous version   
                byte[] value = values.get(0).getValue();
                if (value == null)
                    failCount++;
                else if (value[0] != (byte) ((short) counter % 128))
                    failCount++;
            }
            counter++;
            Date lapDate2 = new Date();
            long spent = lapDate2.getTime() - lapDate.getTime();
            if (spent >= 1000 || (counter - lapCounter > TARGET_TPSR)) { // Check each second or target tps
                if (spent < 1000) { // pause when tps reached
                    Thread.sleep(1000 - spent);
                    // System.out.print(".") ;
                } else
                    // System.out.print("*") ;
                    lapDate = lapDate2; // Reset lap time
                lapCounter = counter; // Reset tps copunter
            }
        }
        timeSpent = new Date().getTime() - startDate.getTime();
        System.out.println("\n\nProcessed reading of " + TEST_COUNT + " pointers \n" + "\tTotal time: "
                + timeSpent / 1000 + "s\n" + "\tThroughput: " + (TEST_COUNT * 1000 / timeSpent) + " tps\n"
                + "\tBad results: " + failCount);

        dmm.stopService();
        System.out.println("Max cycle time = "
                + (dmm.getBtm().getMaxCycleTimePass1() + dmm.getBtm().getMaxCycleTimePass2()));

    } catch (Throwable th) {
        th.printStackTrace();
    }

}

From source file:com.trsst.Command.java

public static void main(String[] argv) {

    // during alpha period: expire after one week
    Date builtOn = Common.getBuildDate();
    if (builtOn != null) {
        long weekMillis = 1000 * 60 * 60 * 24 * 7;
        Date expiry = new Date(builtOn.getTime() + weekMillis);
        if (new Date().after(expiry)) {
            System.err.println("Build expired on: " + expiry);
            System.err.println("Please obtain a more recent build for testing.");
            System.exit(1);// w w  w  .j  a v  a2s  . co  m
        } else {
            System.err.println("Build will expire on: " + expiry);
        }
    }

    // experimental tor support
    boolean wantsTor = false;
    for (String s : argv) {
        if ("--tor".equals(s)) {
            wantsTor = true;
            break;
        }
    }
    if (wantsTor && !HAS_TOR) {
        try {
            log.info("Attempting to connect to tor network...");
            Security.addProvider(new BouncyCastleProvider());
            JvmGlobalUtil.init();
            NetLayer netLayer = NetFactory.getInstance().getNetLayerById(NetLayerIDs.TOR);
            JvmGlobalUtil.setNetLayerAndNetAddressNameService(netLayer, true);
            log.info("Connected to tor network");
            HAS_TOR = true;
        } catch (Throwable t) {
            log.error("Could not connect to tor: exiting", t);
            System.exit(1);
        }
    }

    // if unspecified, default relay to home.trsst.com
    if (System.getProperty("com.trsst.server.relays") == null) {
        System.setProperty("com.trsst.server.relays", "https://home.trsst.com/feed");
    }

    // default to user-friendlier file names
    String home = System.getProperty("user.home", ".");
    if (System.getProperty("com.trsst.client.storage") == null) {
        File client = new File(home, "Trsst Accounts");
        System.setProperty("com.trsst.client.storage", client.getAbsolutePath());
    }
    if (System.getProperty("com.trsst.server.storage") == null) {
        File server = new File(home, "Trsst System Cache");
        System.setProperty("com.trsst.server.storage", server.getAbsolutePath());
    }
    // TODO: try to detect if launching from external volume like a flash
    // drive and store on the local flash drive instead

    Console console = System.console();
    int result;
    try {
        if (console == null && argv.length == 0) {
            argv = new String[] { "serve", "--gui" };
        }
        result = new Command().doBegin(argv, System.out, System.in);

        // task queue prevents exit unless stopped
        if (TrsstAdapter.TASK_QUEUE != null) {
            TrsstAdapter.TASK_QUEUE.cancel();
        }
    } catch (Throwable t) {
        result = 1; // "general catchall error code"
        log.error("Unexpected error, exiting.", t);
    }

    // if error
    if (result != 0) {
        // force exit
        System.exit(result);
    }
}

From source file:com.krawler.common.util.StringUtil.java

public static void main(String args[]) {
    //      dump("this is a test");
    //      dump("this is 'a nother' test");
    //      dump("this is\\ test");
    //      dump("first Roland last 'Schemers' full 'Roland Schemers'");
    //      dump("multi 'Roland\\nSchemers'");
    //      dump("a");
    //      dump("");
    //      dump("\\  \\ ");
    //      dump("backslash \\\\");
    //      dump("backslash \\f");
    //      dump("a           b");
    //            TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    ////            getUserTimeZoneDate("CST");
    ///*from  w  w  w  .  j a va 2s  . c  om*/
    //            String olddate = "Tue Sep 29 06:33:19 GMT 2010";
    //
    //            System.out.println(issameDatesExTime(new Date(),olddate));

    Calendar cal = Calendar.getInstance();
    Calendar cal1 = new GregorianCalendar(TimeZone.getTimeZone("GMT" + "+5:30"));
    try {
        Date dt = new Date();
        cal1.setTimeInMillis(dt.getTime());
        cal.set(Calendar.YEAR, cal1.get(Calendar.YEAR));
        cal.set(Calendar.MONTH, cal1.get(Calendar.MONTH));
        cal.set(Calendar.DAY_OF_MONTH, cal1.get(Calendar.DAY_OF_MONTH));
        cal.set(Calendar.HOUR_OF_DAY, cal1.get(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, cal1.get(Calendar.MINUTE));
        cal.set(Calendar.SECOND, cal1.get(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, cal1.get(Calendar.MILLISECOND));
        System.out.println("IST timezone dt: " + cal.getTime() + " Date is: " + dt);
    } catch (Exception ex) {
        System.out.println(ex);
    } finally {
        //return cal.getTime();
    }
    /*Date date = new Date();
    System.out.println(date);
    SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
    //SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
    sdf.setTimeZone(TimeZone.getTimeZone("CST"));  // replace timezine with user timezone
    String datestr = sdf.format(date);
    System.out.println(datestr);
    String[] datearr = datestr.split(" ");
    String newstr = datestr.replace(datearr[4], " ");
    Date newdate = new Date(newstr);
    System.out.println(newdate);*/
    //            datearr[datearr.length-1]="GMT";
    //            String newstr = "";
    //            for (int i = 0; i < datearr.length; i++) {
    //                if (i != 4) {
    //                    newstr += datearr[i] + " ";
    //                }else{
    //                    newstr += "GMT ";
    //                }
    //            }
    //            newstr = newstr.substring(0, newstr.length() - 1);

}