List of usage examples for java.lang Long parseLong
public static long parseLong(String s) throws NumberFormatException
From source file:Main.java
/** * @param s A string representing hours, minutes, seconds, e.g. <code>11:23:44</code> * @return The converted number of seconds. *//*from w w w . j av a 2 s. c o m*/ public static long fromTimeString(String s) { // Handle "00:00:00.000" pattern, drop the milliseconds if (s.lastIndexOf(".") != -1) s = s.substring(0, s.lastIndexOf(".")); String[] split = s.split(":"); if (split.length != 3) throw new IllegalArgumentException("Can't parse time string: " + s); return (Long.parseLong(split[0]) * 3600) + (Long.parseLong(split[1]) * 60) + (Long.parseLong(split[2])); }
From source file:com.neusoft.mid.clwapi.tools.RandomNumberUtil.java
/** * ?18?long?(long?9223372036854775807,19?) * /* w ww .ja v a 2 s .co m*/ * @param digit * ??? */ public static long randomLong(final int digit) { if (digit >= 19 || digit <= 0) { throw new IllegalArgumentException("digit should between 1 and 18(1<=digit<=18)"); } final String s = RandomStringUtils.randomNumeric(digit - 1); return Long.parseLong(getPrefix() + s); }
From source file:Main.java
/** * Parses a unsigned int value to a byte array containing the IP * @param ip the IP in String format 111.111.111.111 * @return byte array representation of the IP *//* w ww. jav a2 s . c o m*/ public static byte[] parseIntIP(String ip) { long IP = Long.parseLong(ip); // create byte[] from int address byte[] addr = new byte[4]; addr[0] = (byte) ((IP >>> 24) & 0xFF); addr[1] = (byte) ((IP >>> 16) & 0xFF); addr[2] = (byte) ((IP >>> 8) & 0xFF); addr[3] = (byte) (IP & 0xFF); return addr; }
From source file:Main.java
/** * Parses a WebVTT timestamp.//from ww w .ja v a 2s . co m * * @param timestamp The timestamp string. * @return The parsed timestamp in microseconds. * @throws NumberFormatException If the timestamp could not be parsed. */ public static long parseTimestampUs(String timestamp) throws NumberFormatException { long value = 0; String[] parts = timestamp.split("\\.", 2); String[] subparts = parts[0].split(":"); for (int i = 0; i < subparts.length; i++) { value = value * 60 + Long.parseLong(subparts[i]); } return (value * 1000 + Long.parseLong(parts[1])) * 1000; }
From source file:mx.jalan.Utils.KeyUtils.java
public static Long getLongKey(String key) { return Long.parseLong(key); }
From source file:Main.java
/** * Parses the long value of the specified string. * /*from www. j a v a2 s.co m*/ * @param s * The string value to parse. * @param iDefault * A default long value. * @return A long value parsed from the specified string. */ public static long parseLong(String s, long iDefault) { if (s == null || s.equals("")) return iDefault; try { s = s.trim().replaceAll(",", ""); final int l = s.indexOf('.'); if (l > 0) s = s.substring(0, l); return Long.parseLong(s); } catch (RuntimeException e) { return iDefault; } }
From source file:com.pureinfo.tgirls.sns.SNSDataHelper.java
public static List<User> getFriends(String _taobaoId, HttpServletRequest _request) { if (StringUtils.isEmpty(_taobaoId)) { return null; }//from w w w.ja v a 2s . c om String sessionId = (String) CookieUtils.getRequestCookieValue(_request, SessionConstants.TAOBAO_SESSION_ID); try { ListResponse<com.taobao.api.sns.pojo.user.User> lr = TOPAPI.getInstance() .getFriends(Long.parseLong(_taobaoId), 1, 100, sessionId); IUserMgr mgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class); List<User> result = new ArrayList<User>(); if (lr.isSuccess() && lr.getObjs() != null) { for (Iterator iterator = lr.getObjs().iterator(); iterator.hasNext();) { com.taobao.api.sns.pojo.user.User user = (com.taobao.api.sns.pojo.user.User) iterator.next(); User tgirlUser = mgr.getUserByTaobaoId(user.getUserid() + ""); if (tgirlUser != null) { result.add(tgirlUser); } } } return result; } catch (Exception e) { e.printStackTrace(System.err); } return null; }
From source file:com.inkubator.hrm.util.IpUtil.java
public static long ipV4ToLong(String ip) { String[] octets = ip.split("\\."); return (Long.parseLong(octets[0]) << 24) + (Integer.parseInt(octets[1]) << 16) + (Integer.parseInt(octets[2]) << 8) + Integer.parseInt(octets[3]); }
From source file:Main.java
public static String getGSFID(Context context) { String result;// w w w. j a v a2 s .c om final Uri URI = Uri.parse("content://com.google.android.gsf.gservices"); final String ID_KEY = "android_id"; String[] params = { ID_KEY }; Cursor c = context.getContentResolver().query(URI, null, null, params, null); if (c == null || !c.moveToFirst() || c.getColumnCount() < 2) { return null; } else { result = Long.toHexString(Long.parseLong(c.getString(1))); } c.close(); return result; }
From source file:Main.java
public static long readLongAttribute(XmlPullParser in, String name) throws IOException { final String value = in.getAttributeValue(null, name); try {/*from w w w .j a v a 2s. co m*/ return Long.parseLong(value); } catch (NumberFormatException e) { throw new ProtocolException("problem parsing " + name + "=" + value + " as long"); } }