List of usage examples for java.lang NumberFormatException NumberFormatException
public NumberFormatException(String s)
NumberFormatException
with the specified detail message. From source file:QPEncoderStream.java
/** * Convert the bytes within the specified range of the given byte * array into a signed integer in the given radix . The range extends * from <code>start</code> till, but not including <code>end</code>. <p> * * Based on java.lang.Integer.parseInt() *//*from w ww . ja va2s . co m*/ public static int parseInt(byte[] b, int start, int end, int radix) throws NumberFormatException { if (b == null) throw new NumberFormatException("null"); int result = 0; boolean negative = false; int i = start; int limit; int multmin; int digit; if (end > start) { if (b[i] == '-') { negative = true; limit = Integer.MIN_VALUE; i++; } else { limit = -Integer.MAX_VALUE; } multmin = limit / radix; if (i < end) { digit = Character.digit((char) b[i++], radix); if (digit < 0) { throw new NumberFormatException("illegal number: " + toString(b, start, end)); } else { result = -digit; } } while (i < end) { // Accumulating negatively avoids surprises near MAX_VALUE digit = Character.digit((char) b[i++], radix); if (digit < 0) { throw new NumberFormatException("illegal number"); } if (result < multmin) { throw new NumberFormatException("illegal number"); } result *= radix; if (result < limit + digit) { throw new NumberFormatException("illegal number"); } result -= digit; } } else { throw new NumberFormatException("illegal number"); } if (negative) { if (i > start + 1) { return result; } else { /* Only got "-" */ throw new NumberFormatException("illegal number"); } } else { return -result; } }
From source file:com.krawler.common.util.BaseStringUtil.java
public static long hexadecimalToDecimal(String hex) throws NumberFormatException { long res = 0; if (hex.isEmpty()) { throw new NumberFormatException("Empty string is not a hexadecimal number"); }/*from www. j a v a 2 s . co m*/ for (int i = 0; i < hex.length(); i++) { char n = hex.charAt(hex.length() - (i + 1)); int f = (int) n - 48; if (f > 9) { f = f - 7; if (f > 15) { f = f - 32; } } if (f < 0 || f > 15) { throw new NumberFormatException("Not a hexadecimal number"); } else { res += f * Math.round(Math.pow(2.0, (4 * i))); } } return res; }
From source file:org.apache.spark.network.util.JavaUtils.java
/** * Convert a passed byte string (e.g. 50b, 100kb, or 250mb) to the given. If no suffix is * provided, a direct conversion to the provided unit is attempted. *///w w w. j av a2 s . co m public static long byteStringAs(String str, ByteUnit unit) { String lower = str.toLowerCase().trim(); try { Matcher m = Pattern.compile("([0-9]+)([a-z]+)?").matcher(lower); Matcher fractionMatcher = Pattern.compile("([0-9]+\\.[0-9]+)([a-z]+)?").matcher(lower); if (m.matches()) { long val = Long.parseLong(m.group(1)); String suffix = m.group(2); // Check for invalid suffixes if (suffix != null && !byteSuffixes.containsKey(suffix)) { throw new NumberFormatException("Invalid suffix: \"" + suffix + "\""); } // If suffix is valid use that, otherwise none was provided and use the default passed return unit.convertFrom(val, suffix != null ? byteSuffixes.get(suffix) : unit); } else if (fractionMatcher.matches()) { throw new NumberFormatException( "Fractional values are not supported. Input was: " + fractionMatcher.group(1)); } else { throw new NumberFormatException("Failed to parse byte string: " + str); } } catch (NumberFormatException e) { String byteError = "Size must be specified as bytes (b), " + "kibibytes (k), mebibytes (m), gibibytes (g), tebibytes (t), or pebibytes(p). " + "E.g. 50b, 100k, or 250m."; throw new NumberFormatException(byteError + "\n" + e.getMessage()); } }
From source file:org.occiware.mart.server.utils.Utils.java
/** * Parse a string to a number without knowning its type output. * * @param str value to convert. * @param instanceClass can be null, represent the class type of the value to convert (like Integer etc.) * @return a non null number object.//from w w w . j a v a 2 s. co m * @throws NumberFormatException if the value cannot be converted. */ public static Number parseNumber(String str, Class<?> instanceClass) throws NumberFormatException { Number number; if (instanceClass == null) { try { number = Float.parseFloat(str); } catch (NumberFormatException e) { try { number = Double.parseDouble(str); } catch (NumberFormatException e1) { try { number = Integer.parseInt(str); } catch (NumberFormatException e2) { try { number = Long.parseLong(str); } catch (NumberFormatException e3) { number = new BigDecimal(str); } } } } } else { if (instanceClass == Integer.class) { number = Integer.parseInt(str); } else if (instanceClass == Long.class) { number = Long.parseLong(str); } else if (instanceClass == Float.class) { number = Float.parseFloat(str); } else if (instanceClass == Double.class) { number = Double.parseDouble(str); } else if (instanceClass == Short.class) { number = Short.parseShort(str); } else if (instanceClass == Byte.class) { number = Byte.parseByte(str); } else if (instanceClass == BigDecimal.class) { number = new BigDecimal(str); } else { throw new NumberFormatException("Unknown format."); } } return number; }
From source file:org.n52.geoar.newdata.PluginLoader.java
/** * Parses a version string to long. Assumes that each part of a version * string is < 100.// w ww . j a va 2 s. com * * @param version * Version string, e.g. "1.2.3" * @return long built by multiplying each version component by 100 to the * power of its position from the back, i.e. "0.0.1" -> 1, "0.1.0" * -> 100 */ private static long parseVersionNumber(String version) { String[] split = version.split("\\."); long versionNumber = 0; for (int i = 0; i < split.length; i++) { int num = Integer.parseInt(split[i]); if (num < 0 || num >= 100) { throw new NumberFormatException("Unable to parse version number, each part may not exceed 100"); } versionNumber += Math.pow(100, (split.length - 1) - i) * num; } return versionNumber; }
From source file:org.rdv.RDV.java
/** * Parses the command line arguments. If there is an error parsing the * arguments, an error will be printed to stderr and false will be returned. * /*from w w w .j a va 2 s . c o m*/ * @param args the command line arguments * @param setArgs if true set the options, if false just try and parse them * @return true if the options parsed correctly, false otherwise */ public static boolean parseArgs(String[] args, boolean setArgs) { Options options = createOptions(); URL configURL = null; String hostName = null; int portNumber = -1; String[] channels = null; double playbackRate = -1; double timeScale = -1; double location = -1; boolean play = false; boolean realTime = false; int[] knockPorts = null; CommandLineParser parser = new PosixParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption('?')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar rdv.jar", options, true); return false; } String[] leftOverOptions = line.getArgs(); if (leftOverOptions != null && leftOverOptions.length > 0) { String configFile = leftOverOptions[0]; try { if (configFile.matches("^[a-zA-Z]+://.*")) { configURL = new URL(configFile); } else { configURL = new File(configFile).toURI().toURL(); } } catch (MalformedURLException e) { System.err.println("\"" + configFile + "\" is not a valid configuration file URL."); return false; } } if (line.hasOption('h')) { hostName = line.getOptionValue('h'); } if (line.hasOption('p')) { String value = line.getOptionValue('p'); portNumber = Integer.parseInt(value); } if (line.hasOption('c')) { channels = line.getOptionValues('c'); } if (line.hasOption('r')) { String value = line.getOptionValue('r'); playbackRate = Double.parseDouble(value); } if (line.hasOption('s')) { String value = line.getOptionValue('s'); timeScale = Double.parseDouble(value); } if (line.hasOption('t')) { String value = line.getOptionValue('t'); try { location = DataViewer.parseTimestamp(value); } catch (java.text.ParseException e) { System.err.println("Invalid time: " + value); return false; } } if (line.hasOption("play")) { play = true; } else if (line.hasOption("real-time")) { realTime = true; } if (line.hasOption('k')) { String[] knockPortStrings = line.getOptionValues('k'); knockPorts = new int[knockPortStrings.length]; try { for (int i = 0; i < knockPortStrings.length; i++) { knockPorts[i] = Integer.parseInt(knockPortStrings[i]); if (knockPorts[i] < 1 || knockPorts[i] > 65535) { throw new NumberFormatException("Invalid port range: " + knockPorts[i]); } } } catch (NumberFormatException e) { System.err.println("Invalid port knocking option: " + e.getMessage() + "."); return false; } } } catch (ParseException e) { System.err.println("Command line arguments invalid: " + e.getMessage() + "."); return false; } if (!setArgs) { return true; } if (configURL != null) { ConfigurationManager.loadConfiguration(configURL); return true; } RBNBController rbnbController = RBNBController.getInstance(); if (playbackRate != -1) { rbnbController.setPlaybackRate(playbackRate); } if (timeScale != -1) { rbnbController.setTimeScale(timeScale); } if (hostName == null && portNumber == -1) { ActionFactory.getInstance().getOfflineAction().goOffline(); return true; } if (knockPorts != null) { try { PortKnock.knock(hostName, knockPorts); } catch (IOException e) { log.warn("Error port knocking: " + e.getMessage() + "."); e.printStackTrace(); } } if (hostName != null) { rbnbController.setRBNBHostName(hostName); } if (portNumber != -1) { rbnbController.setRBNBPortNumber(portNumber); } if (!rbnbController.connect(true)) { return true; } // set location before we add channels so they load the correct data, but // this can get reset, so it is set again after all the channels are added if (location >= 0) { rbnbController.setLocation(location); } if (channels != null) { for (int i = 0; i < channels.length; i++) { String channel = channels[i]; log.info("Viewing channel " + channel + "."); DataPanelManager.getInstance().viewChannel(channel); } } if (play) { log.info("Starting data playback."); rbnbController.play(); } else if (realTime) { log.info("Viewing data in real time."); rbnbController.monitor(); } else if (location >= 0) { // make sure the location is set since it can be reset when channel's are // added and they have no data at the current location rbnbController.setLocation(location); } return true; }
From source file:op.tools.SYSCalendar.java
public static Date parseDate(String input) throws NumberFormatException { if (input == null || input.equals("")) { throw new NumberFormatException("empty"); }/* w w w .j ava2 s .c o m*/ if (input.indexOf(".") + input.indexOf(",") + input.indexOf("-") + input.indexOf("/") == -4) { input += "."; // er war zu faul auch nur einen punkt anzuhngen. } StringTokenizer st = new StringTokenizer(input, "/,.-"); if (st.countTokens() == 1) { // Vielleicht fehlen ja nur die Monats- und Jahresangaben. Dann hngen wir sie einach an. input += (SYSCalendar.today().get(GregorianCalendar.MONTH) + 1) + "." + SYSCalendar.today().get(GregorianCalendar.YEAR); st = new StringTokenizer(input, "/,.-"); // dann nochmal aufteilen... } if (st.countTokens() == 2) { // Vielleicht fehlt ja nur die Jahresangabe. Dann hngen wir es einfach an. if (!input.trim().substring(input.length() - 1).equals(".") && !input.trim().substring(input.length() - 1).equals(",")) { input += "."; // er war zu faul den letzten Punkt anzuhngen. } input += SYSCalendar.today().get(GregorianCalendar.YEAR); st = new StringTokenizer(input, "/,.-"); // dann nochmal aufteilen... } if (st.countTokens() != 3) { throw new NumberFormatException("wrong format"); } String sTag = st.nextToken(); String sMonat = st.nextToken(); String sJahr = st.nextToken(); int tag, monat, jahr; // Year 2010 Problem GregorianCalendar now = new GregorianCalendar(); int decade = (now.get(GregorianCalendar.YEAR) / 10) * 10; int century = (now.get(GregorianCalendar.YEAR) / 100) * 100; try { tag = Integer.parseInt(sTag); } catch (NumberFormatException nfe) { throw new NumberFormatException("day"); } try { monat = Integer.parseInt(sMonat); } catch (NumberFormatException nfe) { throw new NumberFormatException("month"); } try { jahr = Integer.parseInt(sJahr); } catch (NumberFormatException nfe) { throw new NumberFormatException("year"); } if (jahr < 0) { throw new NumberFormatException("year"); } if (jahr > 9999) { throw new NumberFormatException("year"); } if (jahr < 10) { jahr += decade; } if (jahr < 100) { jahr += century; } if (monat < 1 || monat > 12) { throw new NumberFormatException("month"); } if (tag < 1 || tag > eom(new GregorianCalendar(jahr, monat - 1, 1))) { throw new NumberFormatException("month"); } return new DateMidnight(jahr, monat, tag).toDate(); }
From source file:org.exjello.mail.ExchangeConnection.java
public static ExchangeConnection createConnection(String protocol, Session session, String host, int port, String username, String password) throws Exception { String prefix = "mail." + protocol.toLowerCase() + "."; boolean debugPassword = Boolean.parseBoolean(session.getProperty(DEBUG_PASSWORD_PROPERTY)); String pwd = (password == null) ? null : debugPassword ? password : "<password>"; if (host == null || username == null || password == null) { if (session.getDebug()) { session.getDebugOut().println("Missing parameter; host=\"" + host + "\",username=\"" + username + "\",password=\"" + pwd + "\""); }//ww w.j ava 2 s. c o m throw new IllegalStateException("Host, username, and password must be specified."); } boolean unfiltered = Boolean.parseBoolean(session.getProperty(UNFILTERED_PROPERTY)); /* Mirco */ String filterLastCheck = session.getProperty(ExchangeConstants.FILTER_LAST_CHECK); String filterFrom = session.getProperty(ExchangeConstants.FILTER_FROM_PROPERTY); String filterNotFrom = session.getProperty(ExchangeConstants.FILTER_NOT_FROM_PROPERTY); String filterTo = session.getProperty(ExchangeConstants.FILTER_TO_PROPERTY); boolean delete = Boolean.parseBoolean(session.getProperty(DELETE_PROPERTY)); boolean secure = Boolean.parseBoolean(session.getProperty(prefix + SSL_PROPERTY)); int limit = -1; String limitString = session.getProperty(LIMIT_PROPERTY); if (limitString != null) { try { limit = Integer.parseInt(limitString); } catch (NumberFormatException ex) { throw new NumberFormatException("Invalid limit specified: " + limitString); } } try { URL url = new URL(host); // if parsing succeeded, then strip out the components and use secure = "https".equalsIgnoreCase(url.getProtocol()); host = url.getHost(); int specifiedPort = url.getPort(); if (specifiedPort != -1) port = specifiedPort; } catch (MalformedURLException ex) { if (session.getDebug()) { session.getDebugOut().println("Not parsing " + host + " as a URL; using explicit options for " + "secure, host, and port."); } } if (port == -1) { try { port = Integer.parseInt(session.getProperty(prefix + PORT_PROPERTY)); } catch (Exception ignore) { } if (port == -1) port = secure ? HTTPS_PORT : HTTP_PORT; } String server = (secure ? "https://" : "http://") + host; if (secure ? (port != HTTPS_PORT) : (port != HTTP_PORT)) { server += ":" + port; } String mailbox = session.getProperty(MAILBOX_PROPERTY); if (mailbox == null) { mailbox = session.getProperty(prefix + FROM_PROPERTY); if (mailbox == null) { mailbox = InternetAddress.getLocalAddress(session).getAddress(); } } int index = username.indexOf(':'); if (index != -1) { mailbox = username.substring(index + 1); username = username.substring(0, index); String mailboxOptions = null; index = mailbox.indexOf('['); if (index != -1) { mailboxOptions = mailbox.substring(index + 1); mailboxOptions = mailboxOptions.substring(0, mailboxOptions.indexOf(']')); mailbox = mailbox.substring(0, index); } if (mailboxOptions != null) { Properties props = null; try { props = parseOptions(mailboxOptions); } catch (Exception ex) { throw new IllegalArgumentException("Unable to parse mailbox options: " + ex.getMessage(), ex); } String value = props.getProperty("unfiltered"); if (value != null) unfiltered = Boolean.parseBoolean(value); /* Mirco */ value = props.getProperty("filterLastCheck"); if (value != null) filterLastCheck = value; value = props.getProperty("filterTo"); if (value != null) filterTo = value; value = props.getProperty("filterFrom"); if (value != null) filterFrom = value; value = props.getProperty("filterNotFrom"); if (value != null) filterNotFrom = value; value = props.getProperty("delete"); if (value != null) delete = Boolean.parseBoolean(value); value = props.getProperty("limit"); if (value != null) { try { limit = Integer.parseInt(value); } catch (NumberFormatException ex) { throw new NumberFormatException("Invalid limit specified: " + value); } } } else if (session.getDebug()) { session.getDebugOut().println( "No mailbox options specified; " + "using explicit limit, unfiltered, and delete."); } } else if (session.getDebug()) { session.getDebugOut().println("No mailbox specified in username; " + "using explicit mailbox, limit, unfiltered, and delete."); } int timeout = -1; String timeoutString = session.getProperty(prefix + TIMEOUT_PROPERTY); if (timeoutString != null) { try { timeout = Integer.parseInt(timeoutString); } catch (NumberFormatException ex) { throw new NumberFormatException("Invalid timeout value: " + timeoutString); } } int connectionTimeout = -1; timeoutString = session.getProperty(prefix + CONNECTION_TIMEOUT_PROPERTY); if (timeoutString != null) { try { connectionTimeout = Integer.parseInt(timeoutString); } catch (NumberFormatException ex) { throw new NumberFormatException("Invalid connection timeout value: " + timeoutString); } } InetAddress localAddress = null; String localAddressString = session.getProperty(prefix + LOCAL_ADDRESS_PROPERTY); if (localAddressString != null) { try { localAddress = InetAddress.getByName(localAddressString); } catch (Exception ex) { throw new UnknownHostException("Invalid local address specified: " + localAddressString); } } if (mailbox == null) { throw new IllegalStateException("No mailbox specified."); } if (session.getDebug()) { PrintStream debugStream = session.getDebugOut(); debugStream.println("Server:\t" + server); debugStream.println("Username:\t" + username); debugStream.println("Password:\t" + pwd); debugStream.println("Mailbox:\t" + mailbox); debugStream.print("Options:\t"); debugStream.print((limit > 0) ? "Message Limit = " + limit : "Unlimited Messages"); debugStream.print(unfiltered ? "; Unfiltered" : "; Filtered to Unread"); debugStream.print(filterLastCheck == null || "".equals(filterLastCheck) ? "; NO filterLastCheck" : "; Filtered after " + filterLastCheck); debugStream.print(filterFrom == null || "".equals(filterFrom) ? "; NO filterFromDomain" : "; Filtered from " + filterFrom); debugStream.print(filterNotFrom == null || "".equals(filterNotFrom) ? "; NO filterNotFrom" : "; Filtered not from " + filterNotFrom); debugStream.print( filterTo == null || "".equals(filterTo) ? "; NO filterToEmail" : "; Filtered to " + filterTo); debugStream.println(delete ? "; Delete Messages on Delete" : "; Mark as Read on Delete"); if (timeout > 0) { debugStream.println("Read timeout:\t" + timeout + " ms"); } if (connectionTimeout > 0) { debugStream.println("Connection timeout:\t" + connectionTimeout + " ms"); } } return new ExchangeConnection(session, server, mailbox, username, password, timeout, connectionTimeout, localAddress, unfiltered, delete, limit, filterLastCheck, filterFrom, filterNotFrom, filterTo); }
From source file:org.exjello.mail.Exchange2003Connection.java
public static Exchange2003Connection createConnection(String protocol, Session session, String host, int port, String username, String password) throws Exception { String prefix = "mail." + protocol.toLowerCase() + "."; boolean debugPassword = Boolean.parseBoolean(session.getProperty(DEBUG_PASSWORD_PROPERTY)); String pwd = (password == null) ? null : debugPassword ? password : "<password>"; if (host == null || username == null || password == null) { if (session.getDebug()) { session.getDebugOut().println("Missing parameter; host=\"" + host + "\",username=\"" + username + "\",password=\"" + pwd + "\""); }/*from ww w . j av a2 s. com*/ throw new IllegalStateException("Host, username, and password must be specified."); } boolean unfiltered = Boolean.parseBoolean(session.getProperty(UNFILTERED_PROPERTY)); /* Mirco */ String filterLastCheck = session.getProperty(ExchangeConstants.FILTER_LAST_CHECK); String filterFrom = session.getProperty(ExchangeConstants.FILTER_FROM_PROPERTY); String filterNotFrom = session.getProperty(ExchangeConstants.FILTER_NOT_FROM_PROPERTY); String filterTo = session.getProperty(ExchangeConstants.FILTER_TO_PROPERTY); boolean delete = Boolean.parseBoolean(session.getProperty(DELETE_PROPERTY)); boolean secure = Boolean.parseBoolean(session.getProperty(prefix + SSL_PROPERTY)); int limit = -1; String limitString = session.getProperty(LIMIT_PROPERTY); if (limitString != null) { try { limit = Integer.parseInt(limitString); } catch (NumberFormatException ex) { throw new NumberFormatException("Invalid limit specified: " + limitString); } } try { URL url = new URL(host); // if parsing succeeded, then strip out the components and use secure = "https".equalsIgnoreCase(url.getProtocol()); host = url.getHost(); int specifiedPort = url.getPort(); if (specifiedPort != -1) port = specifiedPort; } catch (MalformedURLException ex) { if (session.getDebug()) { session.getDebugOut().println("Not parsing " + host + " as a URL; using explicit options for " + "secure, host, and port."); } } if (port == -1) { try { port = Integer.parseInt(session.getProperty(prefix + PORT_PROPERTY)); } catch (Exception ignore) { } if (port == -1) port = secure ? HTTPS_PORT : HTTP_PORT; } String server = (secure ? "https://" : "http://") + host; if (secure ? (port != HTTPS_PORT) : (port != HTTP_PORT)) { server += ":" + port; } String mailbox = session.getProperty(MAILBOX_PROPERTY); if (mailbox == null) { mailbox = session.getProperty(prefix + FROM_PROPERTY); if (mailbox == null) { mailbox = InternetAddress.getLocalAddress(session).getAddress(); } } int index = username.indexOf(':'); if (index != -1) { mailbox = username.substring(index + 1); username = username.substring(0, index); String mailboxOptions = null; index = mailbox.indexOf('['); if (index != -1) { mailboxOptions = mailbox.substring(index + 1); mailboxOptions = mailboxOptions.substring(0, mailboxOptions.indexOf(']')); mailbox = mailbox.substring(0, index); } if (mailboxOptions != null) { Properties props = null; try { props = parseOptions(mailboxOptions); } catch (Exception ex) { throw new IllegalArgumentException("Unable to parse mailbox options: " + ex.getMessage(), ex); } String value = props.getProperty("unfiltered"); if (value != null) unfiltered = Boolean.parseBoolean(value); /* Mirco */ value = props.getProperty("filterLastCheck"); if (value != null) filterLastCheck = value; value = props.getProperty("filterTo"); if (value != null) filterTo = value; value = props.getProperty("filterFrom"); if (value != null) filterFrom = value; value = props.getProperty("filterNotFrom"); if (value != null) filterNotFrom = value; value = props.getProperty("delete"); if (value != null) delete = Boolean.parseBoolean(value); value = props.getProperty("limit"); if (value != null) { try { limit = Integer.parseInt(value); } catch (NumberFormatException ex) { throw new NumberFormatException("Invalid limit specified: " + value); } } } else if (session.getDebug()) { session.getDebugOut().println( "No mailbox options specified; " + "using explicit limit, unfiltered, and delete."); } } else if (session.getDebug()) { session.getDebugOut().println("No mailbox specified in username; " + "using explicit mailbox, limit, unfiltered, and delete."); } int timeout = -1; String timeoutString = session.getProperty(prefix + TIMEOUT_PROPERTY); if (timeoutString != null) { try { timeout = Integer.parseInt(timeoutString); } catch (NumberFormatException ex) { throw new NumberFormatException("Invalid timeout value: " + timeoutString); } } int connectionTimeout = -1; timeoutString = session.getProperty(prefix + CONNECTION_TIMEOUT_PROPERTY); if (timeoutString != null) { try { connectionTimeout = Integer.parseInt(timeoutString); } catch (NumberFormatException ex) { throw new NumberFormatException("Invalid connection timeout value: " + timeoutString); } } InetAddress localAddress = null; String localAddressString = session.getProperty(prefix + LOCAL_ADDRESS_PROPERTY); if (localAddressString != null) { try { localAddress = InetAddress.getByName(localAddressString); } catch (Exception ex) { throw new UnknownHostException("Invalid local address specified: " + localAddressString); } } if (mailbox == null) { throw new IllegalStateException("No mailbox specified."); } if (session.getDebug()) { PrintStream debugStream = session.getDebugOut(); debugStream.println("Server:\t" + server); debugStream.println("Username:\t" + username); debugStream.println("Password:\t" + pwd); debugStream.println("Mailbox:\t" + mailbox); debugStream.print("Options:\t"); debugStream.print((limit > 0) ? "Message Limit = " + limit : "Unlimited Messages"); debugStream.print(unfiltered ? "; Unfiltered" : "; Filtered to Unread"); debugStream.print(filterLastCheck == null || "".equals(filterLastCheck) ? "; NO filterLastCheck" : "; Filtered after " + filterLastCheck); debugStream.print(filterFrom == null || "".equals(filterFrom) ? "; NO filterFromDomain" : "; Filtered from " + filterFrom); debugStream.print(filterNotFrom == null || "".equals(filterNotFrom) ? "; NO filterNotFrom" : "; Filtered not from " + filterNotFrom); debugStream.print( filterTo == null || "".equals(filterTo) ? "; NO filterToEmail" : "; Filtered to " + filterTo); debugStream.println(delete ? "; Delete Messages on Delete" : "; Mark as Read on Delete"); if (timeout > 0) { debugStream.println("Read timeout:\t" + timeout + " ms"); } if (connectionTimeout > 0) { debugStream.println("Connection timeout:\t" + connectionTimeout + " ms"); } } return new Exchange2003Connection(session, server, mailbox, username, password, timeout, connectionTimeout, localAddress, unfiltered, delete, limit, filterLastCheck, filterFrom, filterNotFrom, filterTo); }
From source file:net.darkmist.clf.LogParser.java
private static int parse2DigitInt(String str) { // return parseInt(str); int ret = 0;//from w ww . java2 s .c om switch (str.charAt(0)) { case '0': ret = 0; break; case '1': ret = 10; break; case '2': ret = 20; break; case '3': ret = 30; break; case '4': ret = 40; break; case '5': ret = 50; break; case '6': ret = 60; break; case '7': ret = 70; break; case '8': ret = 80; break; case '9': ret = 90; break; default: throw new NumberFormatException("Non-digit in " + str); } switch (str.charAt(1)) { case '0': return ret; case '1': return ret + 1; case '2': return ret + 2; case '3': return ret + 3; case '4': return ret + 4; case '5': return ret + 5; case '6': return ret + 6; case '7': return ret + 7; case '8': return ret + 8; case '9': return ret + 9; default: throw new NumberFormatException("Non-digit in " + str); } }