List of usage examples for java.lang Long parseLong
public static long parseLong(String s) throws NumberFormatException
From source file:Main.java
/** * Read a long[] object from an XmlPullParser. The XML data could * previously have been generated by writeLongArrayXml(). The XmlPullParser * must be positioned <em>after</em> the tag that begins the list. * * @param parser The XmlPullParser from which to read the list data. * @param endTag Name of the tag that will end the list, usually "list". * @param name An array of one string, used to return the name attribute * of the list's tag.//from w w w . jav a 2s . c o m * @return Returns a newly generated long[]. * @see #readListXml */ public static long[] readThisLongArrayXml(XmlPullParser parser, String endTag, String[] name) throws XmlPullParserException, java.io.IOException { int num; try { num = Integer.parseInt(parser.getAttributeValue(null, "num")); } catch (NullPointerException e) { throw new XmlPullParserException("Need num attribute in long-array"); } catch (NumberFormatException e) { throw new XmlPullParserException("Not a number in num attribute in long-array"); } parser.next(); long[] array = new long[num]; int i = 0; int eventType = parser.getEventType(); do { if (eventType == XmlPullParser.START_TAG) { if (parser.getName().equals("item")) { try { array[i] = Long.parseLong(parser.getAttributeValue(null, "value")); } catch (NullPointerException e) { throw new XmlPullParserException("Need value attribute in item"); } catch (NumberFormatException e) { throw new XmlPullParserException("Not a number in value attribute in item"); } } else { throw new XmlPullParserException("Expected item tag at: " + parser.getName()); } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(endTag)) { return array; } else if (parser.getName().equals("item")) { i++; } else { throw new XmlPullParserException("Expected " + endTag + " end tag at: " + parser.getName()); } } eventType = parser.next(); } while (eventType != XmlPullParser.END_DOCUMENT); throw new XmlPullParserException("Document ended before " + endTag + " end tag"); }
From source file:Util.PacketGenerator.java
public static void GeneratePacket() { try {/*from www .j a va 2 s.co m*/ File file = new File( "D:\\Mestrado\\Prototipo\\Trace\\Los Angeles\\equinix-sanjose.dirA.20120920-130000.UTC.anon.pcap.csv"); File newFile = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Tracer_100_Pacotes.csv"); FileInputStream tracesFIS = new FileInputStream(file); DataInputStream tracesDIS = new DataInputStream(tracesFIS); BufferedReader tracesBR = new BufferedReader(new InputStreamReader(tracesDIS)); FileWriter tracesFW = new FileWriter(newFile); String tracesStr = tracesBR.readLine(); Random random = new Random(); long numberOfPackets = 0; while (tracesStr != null && numberOfPackets < 100) { String[] packetTokens = tracesStr.split(","); long time = Long.parseLong(packetTokens[0]); long srcIP = Long.parseLong(packetTokens[1]); long dstIP = Long.parseLong(packetTokens[2]); int srcPort = Integer.parseInt(packetTokens[3]); int dstPort = Integer.parseInt(packetTokens[4]); int payload = random.nextInt(256); tracesFW.write( time + "," + srcIP + "," + dstIP + "," + srcPort + "," + dstPort + "," + payload + "\n"); tracesStr = tracesBR.readLine(); numberOfPackets++; if ((numberOfPackets % 100000) == 0) { System.out.println(numberOfPackets / 1000 + "K Pacotes"); } } tracesBR.close(); tracesDIS.close(); tracesFIS.close(); tracesFW.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:edu.pdx.konstan2.PortlandLive.Route.java
public Route(Element v) { route = Long.parseLong(v.getAttribute("route")); type = v.getAttribute("type"); description = v.getAttribute("desc"); NodeList routesList = v.getElementsByTagName("dir"); for (int count = 0; count < routesList.getLength(); count++) { Node node1 = routesList.item(count); if (node1.getNodeType() == node1.ELEMENT_NODE) { Element dir = (Element) node1; dirDescription = dir.getAttribute("desc"); direction = Long.parseLong(dir.getAttribute("dir")); }/*from ww w .j a v a 2 s . c o m*/ } }
From source file:gov.nih.nci.security.authentication.LockoutConfigurationListener.java
@Override public void configurationChanged(ConfigurationEvent event) { if (!event.isBeforeUpdate()) { // only display events after the modification was done LockoutManager lockoutManager = LockoutManager.getInstance(); if (event.getPropertyName() != null && event.getPropertyName().equalsIgnoreCase("PASSWORD_LOCKOUT_TIME")) { if (event.getPropertyValue() != null) { String[] st = (String[]) event.getPropertyValue(); lockoutManager.setLockoutTime((Long.parseLong(st[0]))); }//from w w w .ja v a 2 s .c o m } if (event.getPropertyName() != null && event.getPropertyName().equalsIgnoreCase("ALLOWED_LOGIN_TIME")) { if (event.getPropertyValue() != null) { String[] st = (String[]) event.getPropertyValue(); lockoutManager.setAllowedLoginTime(Long.parseLong(st[0])); } } if (event.getPropertyName() != null && event.getPropertyName().equalsIgnoreCase("ALLOWED_ATTEMPTS")) { if (event.getPropertyValue() != null) { String[] st = (String[]) event.getPropertyValue(); lockoutManager.setAllowedAttempts(Integer.parseInt(st[0])); } } LockoutManager lockoutManager2 = LockoutManager.getInstance(); } }
From source file:Main.java
/** * Read a long[] object from an XmlPullParser. The XML data could * previously have been generated by writeLongArrayXml(). The XmlPullParser * must be positioned <em>after</em> the tag that begins the list. * * @param parser The XmlPullParser from which to read the list data. * @param endTag Name of the tag that will end the list, usually "list". * @param name An array of one string, used to return the name attribute * of the list's tag./* w w w . j a va2s. c o m*/ * @return Returns a newly generated long[]. * @see #readListXml */ public static final long[] readThisLongArrayXml(XmlPullParser parser, String endTag, String[] name) throws XmlPullParserException, IOException { int num; try { num = Integer.parseInt(parser.getAttributeValue(null, "num")); } catch (NullPointerException e) { throw new XmlPullParserException("Need num attribute in long-array"); } catch (NumberFormatException e) { throw new XmlPullParserException("Not a number in num attribute in long-array"); } parser.next(); long[] array = new long[num]; int i = 0; int eventType = parser.getEventType(); do { if (eventType == parser.START_TAG) { if (parser.getName().equals("item")) { try { array[i] = Long.parseLong(parser.getAttributeValue(null, "value")); } catch (NullPointerException e) { throw new XmlPullParserException("Need value attribute in item"); } catch (NumberFormatException e) { throw new XmlPullParserException("Not a number in value attribute in item"); } } else { throw new XmlPullParserException("Expected item tag at: " + parser.getName()); } } else if (eventType == parser.END_TAG) { if (parser.getName().equals(endTag)) { return array; } else if (parser.getName().equals("item")) { i++; } else { throw new XmlPullParserException("Expected " + endTag + " end tag at: " + parser.getName()); } } eventType = parser.next(); } while (eventType != parser.END_DOCUMENT); throw new XmlPullParserException("Document ended before " + endTag + " end tag"); }
From source file:org.esigate.servlet.impl.HttpServletRequestEntity.java
HttpServletRequestEntity(HttpServletRequest request) { this.request = request; String contentLengthHeader = request.getHeader(HttpHeaders.CONTENT_LENGTH); if (contentLengthHeader != null) { length = Long.parseLong(contentLengthHeader); } else {// w ww. j ava 2 s. co m length = -1; } String contentTypeHeader = request.getContentType(); if (contentTypeHeader != null) { this.setContentType(contentTypeHeader); } String contentEncodingHeader = request.getCharacterEncoding(); if (contentEncodingHeader != null) { this.setContentEncoding(contentEncodingHeader); } }
From source file:helpers.BaseFilterController.java
@After static void endTime() { String header = response.getHeader(X_TIME_ELAPSED); long duration = new Date().getTime() - Long.parseLong(header); response.setHeader(X_TIME_ELAPSED, ((Long) duration).toString()); if (response.status == 200) { response.setHeader("X-Mashape-Billing", "filters=1"); }//from w w w .j a va 2s . c o m }
From source file:com.inkubator.hrm.web.reference.BankDetailController.java
@PostConstruct @Override//from w w w . j av a2 s. c om public void initialization() { try { super.initialization(); String execution = FacesUtil.getRequestParameter("execution"); String param = execution.substring(0, 1); if (StringUtils.equals(param, "e")) { selectedBank = bankService.getEntityWithDetail(Long.parseLong(execution.substring(1))); } } catch (Exception ex) { LOGGER.error("error", ex); } }
From source file:org.shredzone.cilla.web.converter.StringToTag.java
@Override public Tag convert(String string) { try {/*from www . jav a 2 s . c o m*/ return tagDao.fetch(Long.parseLong(string)); } catch (NumberFormatException ex) { return tagDao.fetchByName(string); } }
From source file:com.glaf.core.util.converter.LongConverter.java
public Object convert(Class type, Object value) { if (value == null) { return null; }/*from www . j a v a 2s.c o m*/ if (value instanceof String) { String tmp = (String) value; if (tmp.trim().length() == 0) { return null; } else { return Long.parseLong(tmp); } } return null; }