List of usage examples for java.lang NumberFormatException toString
public String toString()
From source file:org.mule.modules.FtpUtils.java
public static FTPClient createSession(FtpLiteConnectorConfig config, String userName, String hostName, String port, String password) { FTPClient ftp = new FTPClient(); ftp.setControlEncoding(config.getEncoding()); try {//ww w . j ava2s. c o m ftp.connect(hostName, Integer.parseInt(port)); ftp.login(userName, password); } catch (NumberFormatException e) { throw new FtpLiteHostException("Port was incorrect and could not be parsed"); } catch (SocketException e) { throw new FtpLiteHostException("Error connecting. " + e.toString()); } catch (IOException e) { throw new FtpLiteHostException("Error connecting. " + e.toString()); } return ftp; }
From source file:org.apache.sqoop.util.MainframeFTPClientUtils.java
public static FTPClient getFTPConnection(Configuration conf) throws IOException { FTPClient ftp = null;/* w ww. ja va 2 s. com*/ try { String username = conf.get(DBConfiguration.USERNAME_PROPERTY); String password; if (username == null) { username = "anonymous"; password = ""; } else { password = DBConfiguration.getPassword((JobConf) conf); } String connectString = conf.get(DBConfiguration.URL_PROPERTY); String server = connectString; int port = 0; String[] parts = connectString.split(":"); if (parts.length == 2) { server = parts[0]; try { port = Integer.parseInt(parts[1]); } catch (NumberFormatException e) { LOG.warn("Invalid port number: " + e.toString()); } } if (null != mockFTPClient) { ftp = mockFTPClient; } else { ftp = new FTPClient(); } FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_MVS); ftp.configure(config); if (conf.getBoolean(JobBase.PROPERTY_VERBOSE, false)) { ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true)); } try { if (port > 0) { ftp.connect(server, port); } else { ftp.connect(server); } } catch (IOException ioexp) { throw new IOException("Could not connect to server " + server, ioexp); } int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { throw new IOException("FTP server " + server + " refused connection:" + ftp.getReplyString()); } LOG.info("Connected to " + server + " on " + (port > 0 ? port : ftp.getDefaultPort())); if (!ftp.login(username, password)) { ftp.logout(); throw new IOException("Could not login to server " + server + ":" + ftp.getReplyString()); } // set ASCII transfer mode ftp.setFileType(FTP.ASCII_FILE_TYPE); // Use passive mode as default. ftp.enterLocalPassiveMode(); LOG.info("System type detected: " + ftp.getSystemType()); } catch (IOException ioe) { if (ftp != null && ftp.isConnected()) { try { ftp.disconnect(); } catch (IOException f) { // do nothing } } ftp = null; throw ioe; } return ftp; }
From source file:org.dspace.app.itemupdate.MetadataUtilities.java
/** * // w w w .j a v a2 s. c o m * @param f * @throws FileNotFoundException * @throws IOException */ public static List<Integer> readDeleteContentsFile(File f) throws FileNotFoundException, IOException { List<Integer> list = new ArrayList<Integer>(); BufferedReader in = null; try { in = new BufferedReader(new FileReader(f)); String line = null; while ((line = in.readLine()) != null) { line = line.trim(); if ("".equals(line)) { continue; } int n = 0; try { n = Integer.parseInt(line); list.add(n); } catch (NumberFormatException e) { ItemUpdate.pr("Error reading delete contents line:" + e.toString()); } } } finally { try { in.close(); } catch (IOException e) { //skip } } return list; }
From source file:org.dspace.app.dav.DAVServlet.java
/** * Get Session Cookie./*from w w w. ja va2 s. co m*/ * <p> * DAVServlet rolls its own session cookie because the Servlet container's * session <em>cannot</em> be constrained to use ONLY cookies and NOT * URL-rewriting, and the latter would break the DAV protocol so we cannot * use it. Since we really only need to cache the authenticated EPerson (an * integer ID) anyway, it's easy enough so simply stuff that into a cookie. * <p> * Cookie format is: <br> * {timestamp}!{epersonID}!{client-IP}!{MAC} <br> * where timestamp and eperson are integers; client IP is dotted IP * notation, and MAC is the hex MD5 of the preceding fields plus the * "cookieSecret" string. The MAC ensures that the cookie was issued by this * servlet. * <p> * Look for authentication cookie and try to get a previously-authenticated * EPerson from it if found. Also check the timestamp to be sure the cookie * isn't "stale". * <p> * NOTE This is also used by the SOAP servlet. * <p> * * @param context - * set user in this context * @param request - * HTTP request. * * @return true when a fresh cookie yields a valid eperson. * * @throws SQLException the SQL exception */ protected static boolean getAuthFromCookie(Context context, HttpServletRequest request) throws SQLException { Cookie cookie = gimmeCookie(request); if (cookie == null) { return false; } String crumb[] = cookie.getValue().split("\\!"); if (crumb.length != 4) { log.warn("Got invalid cookie value = \"" + cookie.getValue() + "\""); return false; } long timestamp = 0; int epersonID = 0; try { timestamp = Long.parseLong(crumb[0]); epersonID = Integer.parseInt(crumb[1]); } catch (NumberFormatException e) { log.warn("Error groveling cookie, " + e.toString()); return false; } // check freshness long now = new Date().getTime(); if (timestamp > now || (now - timestamp) > COOKIE_SELL_BY) { log.warn("Cookie is stale or has weird time, value = \"" + cookie.getValue() + "\""); return false; } // check IP address if (!crumb[2].equals(request.getRemoteAddr())) { log.warn("Cookie fails IP Addr test, value = \"" + cookie.getValue() + "\""); return false; } // check MAC String mac = Utils.getMD5(crumb[0] + "!" + crumb[1] + "!" + crumb[2] + "!" + cookieSecret); if (!mac.equals(crumb[3])) { log.warn("Cookie fails MAC test, value = \"" + cookie.getValue() + "\""); return false; } // looks like the browser reguritated a good one: EPerson cuser = EPerson.find(context, epersonID); if (cuser != null) { context.setCurrentUser(cuser); log.debug("Got authenticated user from cookie, id=" + crumb[1]); return true; } return false; }
From source file:edu.umd.cs.findbugs.util.Strings.java
/** * Unescape XML entities and illegal characters in the given string. This * enhances the functionality of/*from ww w . ja va2s .c o m*/ * org.apache.commons.lang.StringEscapeUtils.unescapeXml by unescaping * low-valued unprintable characters, which are not permitted by the W3C XML * 1.0 specification. * * @param s * a string * @return the same string with XML entities/escape sequences unescaped * @see <a href="http://www.w3.org/TR/REC-xml/#charsets">Extensible Markup * Language (XML) 1.0 (Fifth Edition)</a> * @see <a * href="http://commons.apache.org/lang/api/org/apache/commons/lang/StringEscapeUtils.html#unescapeXml(java.lang.String)">org.apache.commons.lang.StringEscapeUtils * javadoc</a> */ public static String unescapeXml(String s) { initializeEscapeMap(); /* * we can't escape the string if the pattern doesn't compile! (but that * should never happen since the pattern is static) */ if (!initializeUnescapePattern()) { return s; } if (s == null || s.length() == 0) { return s; } /* * skip this expensive check entirely if there are no substrings * resembling Unicode escape sequences in the string to be unescaped */ if (s.contains("\\u")) { StringBuffer sUnescaped = new StringBuffer(); Matcher m = unescapePattern.matcher(s); while (m.find() == true) { String slashes = m.group(1); String digits = m.group(3); int escapeCode; try { escapeCode = Integer.parseInt(digits, 16); } catch (NumberFormatException nfe) { /* * the static regular expression string should guarantee * that this exception is never thrown */ System.err.println("Impossible error: escape sequence '" + digits + "' is not a valid hex number! " + "Exception: " + nfe.toString()); return s; } if (slashes != null && slashes.length() % 2 == 0 && isInvalidXMLCharacter(escapeCode)) { Character escapedSequence = Character.valueOf((char) escapeCode); /* * slashes are apparently escaped when the string buffer is * converted to a string, so double them to make sure the * correct number appear in the final representation */ m.appendReplacement(sUnescaped, slashes + slashes + escapedSequence.toString()); } } m.appendTail(sUnescaped); s = sUnescaped.toString(); } return StringEscapeUtils.unescapeXml(s); }
From source file:com.streamsets.datacollector.definition.ConfigDefinitionExtractor.java
private static String resolveGroup(List<String> parentGroups, String group, Object contextMsg, List<ErrorMessage> errors) { if (group.startsWith("#")) { try {//from w w w . j a va 2 s. co m int pos = Integer.parseInt(group.substring(1).trim()); if (pos >= 0 && pos < parentGroups.size()) { group = parentGroups.get(pos); } else { errors.add(new ErrorMessage(DefinitionError.DEF_163, contextMsg, pos, parentGroups.size() - 1)); } } catch (NumberFormatException ex) { errors.add(new ErrorMessage(DefinitionError.DEF_164, contextMsg, ex.toString())); } } else { if (!parentGroups.contains(group)) { errors.add(new ErrorMessage(DefinitionError.DEF_165, contextMsg, group, parentGroups)); } } return group; }
From source file:phex.download.handler.HttpFileDownload.java
/** * We only care for the start offset since this is the important point to * begin the download from. Wherever it ends we try to download as long as we * stay connected or until we reach our goal. * <p>/*from w ww . j a v a 2s.c om*/ * Possible Content-Range Headers ( maybe not complete / header is upper * cased by Phex ) * <p> * Content-range:bytes abc-def/xyz * Content-range:bytes abc-def/* * Content-range:bytes *\/xyz * Content-range: bytes=abc-def/xyz (wrong but older Phex version and old clients use this) * * @param contentRangeLine the content range value * @return the content range start offset. * @throws WrongHTTPHeaderException if the content range line has wrong format. */ private static ContentRange parseContentRange(String contentRangeLine) throws WrongHTTPHeaderException { try { ContentRange range = new ContentRange(); String line = contentRangeLine.toLowerCase(Locale.US); // skip over bytes plus extra char int idx = line.indexOf("bytes") + 6; String rangeStr = line.substring(idx).trim(); int slashIdx = rangeStr.indexOf('/'); String leadingPart = rangeStr.substring(0, slashIdx); String trailingPart = rangeStr.substring(slashIdx + 1); // ?????/* if (trailingPart.charAt(0) == '*') { range.totalLength = -1; } else // ?????/789 { long fileLength = Long.parseLong(trailingPart); range.totalLength = fileLength; } // */??? if (leadingPart.charAt(0) == '*') { // startPos of -1 indicates '*' (free to choose) range.startPos = -1; // range.totalLength = range.totalLength; } else { // 123-456/??? int dashIdx = rangeStr.indexOf('-'); String startOffsetStr = leadingPart.substring(0, dashIdx); long startOffset = Long.parseLong(startOffsetStr); String endOffsetStr = leadingPart.substring(dashIdx + 1); long endOffset = Long.parseLong(endOffsetStr); range.startPos = startOffset; range.endPos = endOffset; } return range; } catch (NumberFormatException exp) { logger.warn(exp.toString(), exp); throw new WrongHTTPHeaderException("Number error while parsing content range: " + contentRangeLine); } catch (IndexOutOfBoundsException exp) { throw new WrongHTTPHeaderException("Error while parsing content range: " + contentRangeLine); } }
From source file:me.bramhaag.discordselfbot.commands.util.CommandTimer.java
@Command(name = "timer", minArgs = 1) public void execute(@NonNull Message message, @NonNull TextChannel channel, @NonNull String[] args) { long delay;//www . j a v a 2 s. c o m try { delay = Long.valueOf(args[0]); } catch (NumberFormatException e) { Util.sendError(message, e.toString()); return; } message.editMessage(new EmbedBuilder().setTitle("Timer", null) .setDescription( "Timer ending in " + DurationFormatUtils.formatDuration(delay * 1000, "H:mm:ss", true)) .setFooter("Timer | " + Util.generateTimestamp(), null).setColor(Color.GREEN).build()).queue(); channel.sendMessage(new EmbedBuilder().setTitle("Timer", null).setDescription("Timer expired!") .setFooter("Timer | " + Util.generateTimestamp(), null).setColor(Color.GREEN).build()) .queueAfter(delay, TimeUnit.SECONDS); }
From source file:com.dngames.mobilewebcam.PhotoSettings.java
public static int getEditInt(Context c, SharedPreferences prefs, String name, int d) throws NumberFormatException { int i = 0;/*from ww w . ja v a2 s.com*/ try { i = getEditInt(prefs, name, d); } catch (NumberFormatException e) { String msg = e.toString(); if (e.getMessage() != null) msg = e.getMessage(); if (MobileWebCam.gIsRunning) { try { Toast.makeText(c, msg, Toast.LENGTH_LONG).show(); } catch (RuntimeException er) { er.printStackTrace(); } } else MobileWebCam.LogE(msg); } return i; }
From source file:com.dngames.mobilewebcam.PhotoSettings.java
public static float getEditFloat(Context c, SharedPreferences prefs, String name, float d) throws NumberFormatException { float f = 0.0f; try {/* w w w . jav a2s. c o m*/ f = getEditFloat(prefs, name, d); } catch (NumberFormatException e) { String msg = e.toString(); if (e.getMessage() != null) msg = e.getMessage(); if (MobileWebCam.gIsRunning) { try { Toast.makeText(c, msg, Toast.LENGTH_LONG).show(); } catch (RuntimeException er) { er.printStackTrace(); } } else MobileWebCam.LogE(msg); } return f; }