List of usage examples for java.lang Long toString
public static String toString(long i)
From source file:Main.java
/** * Get a timestamp for an OAuth request. OAuth defines the timestamp as * "the number of seconds since January 1, 1970 00:00:00 GMT. The timestamp * value MUST be a positive integer and MUST be equal or greater than the * timestamp used in previous requests." * * @return the timestamp string to use in an OAuth request. *//*from w w w . j a v a 2 s.c om*/ public static String getTimestamp() { return Long.toString(System.currentTimeMillis() / 1000); }
From source file:ctlogger.CTlogger.java
public static void main(String args[]) { /**// www. j a v a 2s . c om * * Original code for command line parsing * (This has been replaced by code using Apache Commons CLI, see below) * String helpMsg = "CTlogger -x -r -z -g -k <skiplines> -f <flush_sec> -p <poll_sec> -n <nanVal> -i <leadingID> -s <SourceName> -H <HeaderLine> <logger.dat> <CTfolder>"; int dirArg = 0; while((dirArg<args.length) && args[dirArg].startsWith("-")) { // arg parsing if(args[dirArg].equals("-h")) { System.err.println(helpMsg); System.exit(0); } if(args[dirArg].equals("-x")) { debug = true; } if(args[dirArg].equals("-b")) { noBackwards = true; } if(args[dirArg].equals("-g")) { gzipmode = true; } // default false if(args[dirArg].equals("-a")) { appendMode = false; } // default true if(args[dirArg].equals("-z")) { zipmode = false; } // default true if(args[dirArg].equals("-N")) { newFileMode = true; } // default false if(args[dirArg].equals("-f")) { autoflush = Long.parseLong(args[++dirArg]); } if(args[dirArg].equals("-p")) { pollInterval = Long.parseLong(args[++dirArg]); } if(args[dirArg].equals("-k")) { skipLines = Long.parseLong(args[++dirArg]); } if(args[dirArg].equals("-r")) { repeatFetch = true; } if(args[dirArg].equals("-B")) { blockMode = true; } if(args[dirArg].equals("-t")) { storeTime = true; } if(args[dirArg].equals("-T")) { trimTime = Double.parseDouble(args[++dirArg]); } if(args[dirArg].equals("-n")) { nanVal = args[++dirArg]; } if(args[dirArg].equals("-i")) { leadingID = args[++dirArg]; } if(args[dirArg].equals("-s")) { SourceName = args[++dirArg]; } if(args[dirArg].equals("-H")) { HeaderLine = args[++dirArg]; } dirArg++; } if(args.length < (dirArg+2)) { System.err.println(helpMsg); System.exit(0); } loggerFileName = args[dirArg++]; // args[0]: logger.dat file CTrootfolder = args[dirArg++]; // args[1]: CT destination folder */ // // Parse command line arguments // // 1. Setup command line options // Options options = new Options(); // Boolean options (only the flag, no argument) options.addOption("h", "help", false, "Print this message"); options.addOption("x", "debug", false, "turn on debug output"); options.addOption("b", "nobackwards", false, "no backwards-going time allowed"); options.addOption("g", "gzipmode", false, "turn on gzip for extra compression"); options.addOption("a", "noappend", false, "turn off append mode (i.e., do not append to end of existing CT data)"); options.addOption("z", "nozip", false, "turn off zip mode (it is on by default)"); options.addOption("N", "newfilemode", false, "re-parse entire logger file every time it is checked"); options.addOption("r", "repeatFetch", false, "turn on repeat fetch (auto-fetch data loop)"); options.addOption("B", "blockMode", false, "turn on CloudTurbine writer block mode (multiple points per output data file, packed data)"); options.addOption("t", "storeTime", false, "store time string as a channel; time is the first data entry in each line; if this option is not specified, then the time channel is skipped/not saved to CloudTurbine"); // Options with an argument Option outputFolderOption = Option.builder("f").argName("autoflush").hasArg() .desc("flush interval (sec); default = \"" + autoflush + "\"").build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("p").argName("pollInterval").hasArg().desc( "if repeatFetch option has been specified, recheck the logger data file at this polling interval (sec); default = \"" + pollInterval + "\"") .build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("k").argName("skipLines").hasArg().desc( "in logger file, the num lines to skip after the header line to get to the first line of data; default = \"" + skipLines + "\"") .build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("T").argName("trimTime").hasArg().desc( "trim (ring-buffer loop) time (sec) (trimTime=0 for indefinite); default = \"" + trimTime + "\"") .build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("n").argName("nanVal").hasArg() .desc("replace NAN with this; default = \"" + nanVal + "\"").build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("i").argName("leadingID").hasArg() .desc("leading ID string (IWG1 compliant)").build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("s").argName("sourceName").hasArg() .desc("CloudTurbine source name; default = \"" + SourceName + "\"").build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("H").argName("HeaderLine").hasArg().desc( "optional CSV list of channel names; if not supplied, this is read from the first line in the logger file") .build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("l").argName("loggerfilename").hasArg() .desc("name of the logger data file; required argument").build(); options.addOption(outputFolderOption); outputFolderOption = Option.builder("o").longOpt("outputfolder").argName("folder").hasArg() .desc("Location of output files (source is created under this folder); default = " + CTrootfolder) .build(); options.addOption(outputFolderOption); // // 2. Parse command line options // CommandLineParser parser = new DefaultParser(); CommandLine line = null; try { line = parser.parse(options, args); } catch (org.apache.commons.cli.ParseException exp) { // oops, something went wrong System.err.println("Command line argument parsing failed: " + exp.getMessage()); return; } // // 3. Retrieve the command line values // if (line.hasOption("help")) { // Display help message and quit HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("CTlogger", options); return; } debug = line.hasOption("x"); noBackwards = line.hasOption("b"); gzipmode = line.hasOption("g"); appendMode = !line.hasOption("a"); zipmode = !line.hasOption("z"); newFileMode = line.hasOption("N"); repeatFetch = line.hasOption("r"); blockMode = line.hasOption("B"); storeTime = line.hasOption("t"); autoflush = Long.parseLong(line.getOptionValue("f", Long.toString(autoflush))); pollInterval = Long.parseLong(line.getOptionValue("p", Long.toString(pollInterval))); skipLines = Long.parseLong(line.getOptionValue("k", Long.toString(skipLines))); trimTime = Double.parseDouble(line.getOptionValue("T", Double.toString(trimTime))); nanVal = line.getOptionValue("n", nanVal); if (line.hasOption("i")) { leadingID = line.getOptionValue("i"); } SourceName = line.getOptionValue("s", SourceName); if (line.hasOption("H")) { HeaderLine = line.getOptionValue("H"); } if (line.hasOption("l")) { loggerFileName = line.getOptionValue("l"); } else { System.err.println("ERROR: you must supply the logger file name."); return; } CTrootfolder = line.getOptionValue("o", CTrootfolder); if (!debug) { System.err.println("CTlogger: " + loggerFileName + ", CTrootfolder: " + CTrootfolder + ", pollInterval: " + pollInterval); } else { System.err.println("debug = " + debug); System.err.println("noBackwards = " + noBackwards); System.err.println("gzipmode = " + gzipmode); System.err.println("appendMode = " + appendMode); System.err.println("zipmode = " + zipmode); System.err.println("newFileMode = " + newFileMode); System.err.println("repeatFetch = " + repeatFetch); System.err.println("blockMode = " + blockMode); System.err.println("storeTime = " + storeTime); System.err.println("autoflush = " + autoflush); System.err.println("pollInterval = " + pollInterval); System.err.println("skipLines = " + skipLines); System.err.println("trimTime = " + trimTime); System.err.println("nanVal = " + nanVal); System.err.println("leadingID = " + leadingID); System.err.println("SourceName = " + SourceName); System.err.println("HeaderLine = " + HeaderLine); System.err.println("loggerFileName = " + loggerFileName); System.err.println("CTrootfolder = " + CTrootfolder); } // // Run CTlogger // if (!repeatFetch) getData(true); // run once else { Timer timer = new Timer(); TimerTask fetchTask = new TimerTask() { @Override public void run() { if (newFileMode) getData(true); else if (getData(false)) { // pick up from old data if you can System.err.println("Failed to pick up from old data, refetch from start of file..."); boolean status = getData(true); System.err.println("refetch status: " + status); } if (debug) System.err.println("Waiting for data, pollInterval: " + pollInterval + " sec..."); }; }; // repeatFetch@autoflush interval, convert to msec if ((autoflush > 0) && (pollInterval > autoflush)) pollInterval = autoflush; timer.scheduleAtFixedRate(fetchTask, 0, pollInterval * 1000); } }
From source file:Main.java
public static String toHumanReadableSize(long byteCount) { if (byteCount >= 10 * 1024 * 1024) { return (byteCount / (1024 * 1024)) + "MB"; } else if (byteCount >= 10 * 1024) { return (byteCount / 1024) + "kB"; } else {/*from w w w . jav a2s. c o m*/ return Long.toString(byteCount); } }
From source file:Main.java
/** * Get a nonce for an OAuth request. OAuth defines the nonce as "a random * string, uniquely generated for each request. The nonce allows the Service * Provider to verify that a request has never been made before and helps * prevent replay attacks when requests are made over a non-secure channel * (such as HTTP)."/* ww w .ja va 2s. c o m*/ * * @return the nonce string to use in an OAuth request */ public static String getNonce() { return Long.toString(System.nanoTime()); }
From source file:MyCanvas.java
public void paint(Graphics g) { g.drawString(Long.toString(System.currentTimeMillis()), 10, 30); repaint(1000); }
From source file:com.linkedin.pinot.common.utils.FileUtils.java
public static String getRandomFileName() { return StringUtil.join("-", "tmp", String.valueOf(System.currentTimeMillis()), Long.toString(RANDOM.nextLong())); }
From source file:OutputStreamDemo.java
static void writeints(String msg, int count, OutputStream os) throws IOException { long currentTime = System.currentTimeMillis(); for (int i = 0; i < count; i++) os.write(i & 255);/*w w w. ja va2 s . co m*/ os.close(); System.out.println(msg + Long.toString(System.currentTimeMillis() - currentTime)); }
From source file:Main.java
/** * Return the filename for a given attachment. This should be used by any code that is * going to *write* attachments.//from ww w.j a va2 s . c om * * This does not create or write the file, or even the directories. It simply builds * the filename that should be used. */ public static File getAttachmentFilename(Context context, long accountId, long attachmentId) { return new File(getAttachmentDirectory(context, accountId), Long.toString(attachmentId)); }
From source file:Main.java
/** * format double value//from w ww . j a v a2 s .co m * @param d the amount * @param len the field len * @return a String of fieldLen characters (right justified) */ public static String formatDouble(double d, int len) { String prefix = Long.toString((long) d); String suffix = Integer.toString((int) ((Math.round(d * 100f)) % 100)); try { if (len > 3) prefix = padleft(prefix, len - 3, ' '); suffix = zeropad(suffix, 2); } catch (Exception e) { // should not happen } return prefix + "." + suffix; }
From source file:Main.java
/** * Format size in string form/*from w w w .j a v a2 s.com*/ * * @param size Size in bytes * @return Size in stinrg format with suffix */ public static String formatSize(int size) { String suffix = null; if (size >= 1024) { suffix = "KB"; size /= 1024; if (size >= 1024) { suffix = "MB"; size /= 1024; } } StringBuilder resultBuffer = new StringBuilder(Long.toString(size)); int commaOffset = resultBuffer.length() - 3; while (commaOffset > 0) { resultBuffer.insert(commaOffset, ','); commaOffset -= 3; } if (suffix != null) resultBuffer.append(suffix); return resultBuffer.toString(); }