List of usage examples for java.lang Long parseLong
public static long parseLong(String s) throws NumberFormatException
From source file:com.stargame.ad.util.cache.AbCacheHeaderParser.java
/** * ???./* w w w . j av a2s. c om*/ * * @param response * the response * @return the ab cache. entry */ public static AbDiskCache.Entry parseCacheHeaders(AbCacheResponse response) { Map<String, String> headers = response.headers; long serverTimeMillis = 0; long expiredTimeMillis = 0; long maxAge = 0; boolean hasCacheControl = false; String serverEtag = null; String headerValue; // ?? headerValue = headers.get("Date"); if (headerValue != null) { try { serverTimeMillis = DateUtils.parseDate(headerValue).getTime(); } catch (Exception e) { e.printStackTrace(); serverTimeMillis = System.currentTimeMillis(); } } // Cache-Control? headerValue = headers.get("Cache-Control"); if (headerValue != null) { hasCacheControl = true; String[] tokens = headerValue.split(","); for (int i = 0; i < tokens.length; i++) { String token = tokens[i].trim(); if (token.equals("no-cache") || token.equals("no-store")) { return null; } else if (token.startsWith("max-age=")) { try { maxAge = Long.parseLong(token.substring(8)); } catch (Exception e) { } } else if (token.equals("must-revalidate") || token.equals("proxy-revalidate")) { maxAge = 0; } } } serverEtag = headers.get("ETag"); if (hasCacheControl) { expiredTimeMillis = serverTimeMillis + maxAge; } AbDiskCache.Entry entry = new AbDiskCache.Entry(); entry.data = response.data; entry.etag = serverEtag; entry.serverTimeMillis = serverTimeMillis; entry.expiredTimeMillis = expiredTimeMillis; entry.responseHeaders = headers; return entry; }
From source file:iddb.core.util.Functions.java
public static final Long ipToDecimal(String ip) { if (ip == null || ip.length() == 0) return 0l; String[] parts = ip.split("\\."); Long n = 16777216 * Long.parseLong(parts[0]); n += 65536 * Long.parseLong(parts[1]); n += 256 * Long.parseLong(parts[2]); n += Long.parseLong(parts[3]); return n;//w ww. j a v a2 s . co m }
From source file:com.nxt.zyl.data.volley.toolbox.HttpHeaderParser.java
/** * Extracts a {@link Cache.Entry} from a {@link NetworkResponse}. * * @param response The network response to parse headers from * @return a cache entry for the given response, or null if the response is not cacheable. *///from w w w. j a v a 2 s . c o m public static Cache.Entry parseCacheHeaders(NetworkResponse response) { long now = System.currentTimeMillis(); Map<String, String> headers = response.headers; long serverDate = 0; long serverExpires = 0; long softExpire = 0; long maxAge = 0; boolean hasCacheControl = false; String serverEtag; String headerValue; headerValue = headers.get("Date"); if (headerValue != null) { serverDate = parseDateAsEpoch(headerValue); } headerValue = headers.get("Cache-Control"); if (headerValue != null) { hasCacheControl = true; String[] tokens = headerValue.split(","); for (String token1 : tokens) { String token = token1.trim(); if (token.equals("no-cache") || token.equals("no-store")) { return null; } else if (token.startsWith("max-age=")) { try { maxAge = Long.parseLong(token.substring(8)); } catch (Exception ignored) { } } else if (token.equals("must-revalidate") || token.equals("proxy-revalidate")) { maxAge = 0; } } } headerValue = headers.get("Expires"); if (headerValue != null) { serverExpires = parseDateAsEpoch(headerValue); } serverEtag = headers.get("ETag"); // Cache-Control takes precedence over an Expires header, even if both exist and Expires // is more restrictive. if (hasCacheControl) { softExpire = now + maxAge * 1000; } else if (serverDate > 0 && serverExpires >= serverDate) { // Default semantic for Expire header in HTTP specification is softExpire. softExpire = now + (serverExpires - serverDate); } Cache.Entry entry = new Cache.Entry(); entry.data = response.data; entry.etag = serverEtag; entry.softTtl = softExpire; entry.ttl = entry.softTtl; entry.serverDate = serverDate; entry.responseHeaders = headers; return entry; }
From source file:at.alladin.rmbt.db.fields.LongField.java
@Override public void setString(final String string) { value = Long.parseLong(string); }
From source file:com.redhat.rhn.domain.common.SatConfigFactory.java
/** * return satellite configuration long value for a specified key * @param key key/*from ww w. ja v a 2 s . c o m*/ * @return value long value */ public static Long getSatConfigLongValue(String key) { String stringValue = getSatConfigValue(key); if (stringValue != null) { try { return Long.parseLong(stringValue); } catch (NumberFormatException nfe) { log.error("Satellite configuration '" + key + "' value (" + stringValue + ") cannot be converted to Long."); } } return null; }
From source file:ch.newscron.newscronjsp.ShortUrlCreator.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {//from ww w . j av a 2 s. co m String customerId = request.getParameter("customerId"); String rew1 = request.getParameter("rew1"); String rew2 = request.getParameter("rew2"); String val = request.getParameter("val"); String urlEncoded = encodeUrl(customerId, rew1, rew2, val); if (urlEncoded == null) { response.sendRedirect(domain); } else { insertToDatabase(Long.parseLong(customerId), domain + "referral/" + urlEncoded); String redirectURL = domain + "userShortUrlStats?customerId=" + customerId; response.sendRedirect(redirectURL); } } catch (Exception ex) { Logger.getLogger(ShortUrlCreator.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:AIR.Common.Configuration.AppSettingsHelper.java
private static long getInt64(String key, Long defaultValue) { String rawValue = get(key);//w w w.ja v a2 s .com if (!StringUtils.isEmpty(rawValue)) { long value = Long.parseLong(rawValue); return value; } return defaultValue != null ? defaultValue.longValue() : 0; }