List of usage examples for java.lang StringIndexOutOfBoundsException getMessage
public String getMessage()
From source file:org.limy.common.util.UrlUtils.java
/** * ?????????/* www.j ava 2s . co m*/ * @param basePath * @param url * @return */ public static String concatUrl(String basePath, String url) { StringTokenizer tokenizer = new StringTokenizer(url, "/"); StringBuilder result = new StringBuilder(basePath); try { while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (".".equals(token)) { continue; } if ("..".equals(token)) { if (result.charAt(result.length() - 1) == '/') { result.setLength(result.length() - 1); } if (result.lastIndexOf("/") >= 0) { result.setLength(result.lastIndexOf("/")); } else { result.setLength(0); } continue; } if (result.length() > 0 && result.charAt(result.length() - 1) != '/') { result.append('/'); } result.append(token); } } catch (StringIndexOutOfBoundsException e) { LOG.warn(e.getMessage(), e); return url; } return result.toString(); }
From source file:com.comcast.cats.config.ui.recording.MediaInfoBean.java
public void setFilePath(String filePath) { //FIXME: once video recorder service returns the actual path isntead of 127.0.0.1 this.filePath = substituteFilePath(filePath); try {//ww w.ja v a 2 s . c o m setFileName(this.filePath.substring(this.filePath.lastIndexOf("/") + 1)); setDirectory(this.filePath.substring(0, this.filePath.lastIndexOf("/"))); } catch (StringIndexOutOfBoundsException e) { logger.debug("Invalid Filename " + this.filePath + " meesage: " + e.getMessage()); // invalid Filename. setFileName(DEFAULT_FILE_NAME); } }
From source file:com.jbirdvegas.mgerrit.dialogs.DiffDialog.java
private void setTextView(String result) { Pattern pattern = Pattern.compile("\\Qdiff --git \\E"); String[] filesChanged = pattern.split(result); StringBuilder builder = new StringBuilder(0); Diff currentDiff = null;//from w w w. ja va2 s . co m for (String change : filesChanged) { String concat; try { concat = change.substring(2, change.lastIndexOf(mChangedFile.getPath())).trim(); concat = concat.split(" ")[0]; } catch (StringIndexOutOfBoundsException notFound) { Log.d(TAG, notFound.getMessage()); continue; } if (concat.equals(mChangedFile.getPath())) { builder.append(DIFF); change.replaceAll("\n", mLineSplit); currentDiff = new Diff(getContext(), change); builder.append(change); } } if (builder.length() == 0) { builder.append("Diff not found!"); } // reset text size to default mDiffTextView.setTextAppearance(getContext(), android.R.style.TextAppearance_DeviceDefault_Small); mDiffTextView.setTypeface(Typeface.MONOSPACE); // rebuild text; required to respect the \n SpannableString spannableString = currentDiff.getColorizedSpan(); if (spannableString != null) { mDiffTextView.setText(currentDiff.getColorizedSpan(), TextView.BufferType.SPANNABLE); } else { mDiffTextView.setText("Failed to load diff :("); } }
From source file:no.sesat.search.http.servlet.BoomerangServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException { // clients must not cache these requests res.setHeader("Cache-Control", "no-cache, must-revalidate, post-check=0, pre-check=0"); res.setHeader("Pragma", "no-cache"); // for old browsers res.setDateHeader("Expires", 0); // to be double-safe // entrails is the map of logging information final Map<String, Object> entrails = new HashMap<String, Object>(); // request attribute to keep entrails.put("referer", req.getHeader("Referer")); entrails.put("method", req.getMethod()); entrails.put("ipaddress", req.getRemoteAddr()); entrails.put("user-agent", req.getHeader("User-Agent")); entrails.put("user-id", SearchServlet.getCookieValue(req, "SesamID")); entrails.put("user", SearchServlet.getCookieValue(req, "SesamUser")); if (req.getRequestURI().startsWith(CEREMONIAL)) { // ceremonial boomerang final StringBuffer url = req.getRequestURL(); if (null != req.getQueryString()) { url.append('?' + req.getQueryString()); }//from www. j a v a 2s.c o m // pick out the entrails final int boomerangStart = url.indexOf(CEREMONIAL) + CEREMONIAL.length(); try { final String grub = url.substring(boomerangStart, url.indexOf("/", boomerangStart)); LOG.debug(grub); // the url to return to final String destination = url .substring(url.indexOf("/", url.indexOf(CEREMONIAL) + CEREMONIAL.length() + 1) + 1); // the grub details to add if (0 < grub.length()) { final StringTokenizer tokeniser = new StringTokenizer(grub, ";"); while (tokeniser.hasMoreTokens()) { final String[] entry = tokeniser.nextToken().split("="); entrails.put(entry[0], 1 < entry.length ? entry[1] : entry[0]); } } entrails.put("boomerang", destination); kangerooGrub(entrails); LOG.debug("Ceremonial boomerang to " + destination.toString()); if (ROBOTS.matcher(req.getHeader("User-agent")).find()) { // robots like permanent redirects. and we're not interested in their clicks so ok to cache. res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); res.setHeader("Location", destination.toString()); res.setHeader("Connection", "close"); } else { // default behaviour for users. res.sendRedirect(destination.toString()); } } catch (StringIndexOutOfBoundsException sioobe) { // SEARCH-4668 LOG.error("Boomerang url not to standard --> " + url); LOG.debug(sioobe.getMessage(), sioobe); } } else { // hunting boomerang, just grub, and the grub comes as clean parameters. final DataModel datamodel = (DataModel) req.getSession().getAttribute(DataModel.KEY); entrails.putAll(datamodel.getParameters().getValues()); kangerooGrub(entrails); } }
From source file:dslab.crawler.pack.CrawlerPack.java
public String getFromRemote(String uri) { // clear cache fileSystem.getFilesCache().close();/*from w w w . java 2 s . c o m*/ String remoteContent; String remoteEncoding = "utf-8"; log.debug("Loading remote URI:" + uri); FileContent fileContent; try { // set cookie if cookies set if (0 < this.cookies.size()) { FileSystemOptions fsOptions = new FileSystemOptions(); HttpFileSystemConfigBuilder.getInstance().setCookies(fsOptions, getCookies(uri)); fileContent = fileSystem.resolveFile(uri, fsOptions).getContent(); } else fileContent = fileSystem.resolveFile(uri).getContent(); // 2016-03-22 only pure http/https auto detect encoding if ("http".equalsIgnoreCase(uri.substring(0, 4))) { fileContent.getSize(); // pass a bug {@link https://issues.apache.org/jira/browse/VFS-427} remoteEncoding = fileContent.getContentInfo().getContentEncoding(); } if (null == remoteEncoding) remoteEncoding = "utf-8"; if (!"utf".equalsIgnoreCase(remoteEncoding.substring(0, 3))) { log.debug("remote content encoding: " + remoteEncoding); // force charset encoding if setRemoteEncoding set if (!"utf".equalsIgnoreCase(encoding.substring(0, 3))) { remoteEncoding = encoding; } else { // auto detecting encoding remoteEncoding = detectCharset(IOUtils.toByteArray(fileContent.getInputStream())); log.info("real encoding: " + remoteEncoding); } } // 2016-02-29 fixed remoteContent = IOUtils.toString(fileContent.getInputStream(), remoteEncoding); } catch (FileSystemException fse) { log.warn(fse.getMessage()); remoteContent = null; } catch (IOException ioe) { // return empty log.warn(ioe.getMessage()); remoteContent = null; } catch (StringIndexOutOfBoundsException stre) { log.warn("uri: " + uri); log.warn(stre.getMessage()); remoteContent = null; } clearCookies(); // any exception will return "null" return remoteContent; }
From source file:org.archive.wayback.util.url.AggressiveUrlCanonicalizer.java
public String urlStringToKey(final String urlString) throws URIException { if (urlString.startsWith("dns:")) { return urlString; }//from w ww .ja v a 2 s . c om String searchUrl = canonicalize(urlString); String scheme = UrlOperations.urlToScheme(searchUrl); if (scheme != null) { searchUrl = searchUrl.substring(scheme.length()); } else { scheme = UrlOperations.HTTP_SCHEME; } if (-1 == searchUrl.indexOf("/")) { searchUrl = scheme + searchUrl + "/"; } else { searchUrl = scheme + searchUrl; } // TODO: These next few lines look crazy -- need to be reworked.. This // was the only easy way I could find to get the correct unescaping // out of UsableURIs, possible a bug. Definitely needs some TLC in any case, // as building UsableURIs is *not* a cheap operation. // unescape anything that can be: UsableURI tmpURI = null; try { tmpURI = UsableURIFactory.getInstance(searchUrl); } catch (StringIndexOutOfBoundsException e) { LOGGER.warning(e.getMessage() + ": " + searchUrl); return searchUrl; // } catch(URIException e) { // LOGGER.warning(e.getMessage() + ": " + searchUrl); // return searchUrl; } tmpURI.setPath(tmpURI.getPath()); // convert to UsableURI to perform required URI fixup: UsableURI searchURI = UsableURIFactory.getInstance(tmpURI.getURI()); // replace ' ' with '+' (this is only to match Alexa's canonicalization) String newPath = searchURI.getEscapedPath().replace("%20", "+"); // replace multiple consecutive '/'s in the path. while (newPath.contains("//")) { newPath = newPath.replace("//", "/"); } // this would remove trailing a '/' character, unless the path is empty // but we're not going to do this just yet.. // if((newPath.length() > 1) && newPath.endsWith("/")) { // newPath = newPath.substring(0,newPath.length()-1); // } StringBuilder sb = new StringBuilder(searchUrl.length()); sb.append(searchURI.getHostBasename()); // omit port if scheme default: int defaultSchemePort = UrlOperations.schemeToDefaultPort(scheme); if (searchURI.getPort() != defaultSchemePort && searchURI.getPort() != -1) { sb.append(":").append(searchURI.getPort()); } sb.append(newPath); if (searchURI.getEscapedQuery() != null) { sb.append("?").append(searchURI.getEscapedQuery()); } return sb.toString(); }
From source file:com.github.abola.crawler.CrawlerPack.java
/** * ?? Apache Common VFS ???/*from ww w. ja v a2 s . c om*/ * * ?? * @see <a href="https://commons.apache.org/proper/commons-vfs/filesystems.html">commons-vfs filesystems</a> */ public String getFromRemote(String uri) { // clear cache fileSystem.getFilesCache().close(); String remoteContent; String remoteEncoding = "utf-8"; log.debug("getFromRemote: Loading remote URI=" + uri); FileContent fileContent; try { FileSystemOptions fsOptions = new FileSystemOptions(); // set userAgent HttpFileSystemConfigBuilder.getInstance().setUserAgent(fsOptions, userAgent); // set cookie if cookies set if (0 < this.cookies.size()) { HttpFileSystemConfigBuilder.getInstance().setCookies(fsOptions, getCookies(uri)); } log.debug("getFromRemote: userAgent=" + userAgent); log.debug("getFromRemote: cookieSize=" + cookies.size()); log.debug("getFromRemote: cookies=" + cookies.toString()); fileContent = fileSystem.resolveFile(uri, fsOptions).getContent(); // 2016-03-22 only pure http/https auto detect encoding if ("http".equalsIgnoreCase(uri.substring(0, 4))) { fileContent.getSize(); // pass a bug {@link https://issues.apache.org/jira/browse/VFS-427} remoteEncoding = fileContent.getContentInfo().getContentEncoding(); } log.debug("getFromRemote: remoteEncoding=" + remoteEncoding + "(auto detect) "); // 2016-03-21 zip file getContentEncoding null if (null == remoteEncoding) remoteEncoding = "utf-8"; if (!"utf".equalsIgnoreCase(remoteEncoding.substring(0, 3))) { log.debug("getFromRemote: remote content encoding=" + remoteEncoding); // force charset encoding if setRemoteEncoding set if (!"utf".equalsIgnoreCase(encoding.substring(0, 3))) { remoteEncoding = encoding; } else { // auto detecting encoding remoteEncoding = detectCharset(IOUtils.toByteArray(fileContent.getInputStream())); log.debug("getFromRemote: real encoding=" + remoteEncoding); } } // ?? Apache VFS ?? // 2016-02-29 fixed remoteContent = IOUtils.toString(fileContent.getInputStream(), remoteEncoding); } catch (FileSystemException fse) { log.warn("getFromRemote: FileSystemException=" + fse.getMessage()); remoteContent = null; } catch (IOException ioe) { // return empty log.warn("getFromRemote: IOException=" + ioe.getMessage()); remoteContent = null; } catch (StringIndexOutOfBoundsException stre) { log.warn("getFromRemote: StringIndexOutOfBoundsException=" + stre.getMessage()); log.warn("getFromRemote: uri=" + uri); log.warn(stre.getMessage()); remoteContent = null; } clearCookies(); log.debug("getFromRemote: remoteContent=\n" + remoteContent); // any exception will return "null" return remoteContent; }
From source file:net.sf.jabref.gui.preftabs.PreviewPrefsTab.java
public PreviewPrefsTab(JabRefPreferences prefs) { this.prefs = prefs; GridBagLayout layout = new GridBagLayout(); firstPanel.setLayout(layout);/*from www. ja v a 2 s.c om*/ secondPanel.setLayout(layout); setLayout(layout); JLabel lab = new JLabel(Localization.lang("Preview") + " 1"); GridBagConstraints layoutConstraints = new GridBagConstraints(); layoutConstraints.anchor = GridBagConstraints.WEST; layoutConstraints.gridwidth = GridBagConstraints.REMAINDER; layoutConstraints.fill = GridBagConstraints.BOTH; layoutConstraints.weightx = 1; layoutConstraints.weighty = 0; layoutConstraints.insets = new Insets(2, 2, 2, 2); layout.setConstraints(lab, layoutConstraints); layoutConstraints.weighty = 1; layout.setConstraints(firstScrollPane, layoutConstraints); firstPanel.add(firstScrollPane); layoutConstraints.weighty = 0; layoutConstraints.gridwidth = 1; layoutConstraints.weightx = 0; layoutConstraints.fill = GridBagConstraints.NONE; layoutConstraints.anchor = GridBagConstraints.WEST; layout.setConstraints(testButton, layoutConstraints); firstPanel.add(testButton); layout.setConstraints(defaultButton, layoutConstraints); firstPanel.add(defaultButton); layoutConstraints.gridwidth = GridBagConstraints.REMAINDER; JPanel newPan = new JPanel(); layoutConstraints.weightx = 1; layout.setConstraints(newPan, layoutConstraints); firstPanel.add(newPan); lab = new JLabel(Localization.lang("Preview") + " 2"); layout.setConstraints(lab, layoutConstraints); // p2.add(lab); layoutConstraints.weighty = 1; layoutConstraints.fill = GridBagConstraints.BOTH; layout.setConstraints(secondScrollPane, layoutConstraints); secondPanel.add(secondScrollPane); layoutConstraints.weighty = 0; layoutConstraints.weightx = 0; layoutConstraints.fill = GridBagConstraints.NONE; layoutConstraints.gridwidth = 1; layout.setConstraints(testButton2, layoutConstraints); secondPanel.add(testButton2); layout.setConstraints(defaultButton2, layoutConstraints); secondPanel.add(defaultButton2); layoutConstraints.gridwidth = 1; newPan = new JPanel(); layoutConstraints.weightx = 1; layout.setConstraints(newPan, layoutConstraints); secondPanel.add(newPan); layoutConstraints.weightx = 1; layoutConstraints.weighty = 0; layoutConstraints.fill = GridBagConstraints.BOTH; layoutConstraints.gridwidth = GridBagConstraints.REMAINDER; lab = new JLabel(Localization.lang("Preview") + " 1"); layout.setConstraints(lab, layoutConstraints); add(lab); layoutConstraints.weighty = 1; layout.setConstraints(firstPanel, layoutConstraints); add(firstPanel); lab = new JLabel(Localization.lang("Preview") + " 2"); layoutConstraints.weighty = 0; JSeparator sep = new JSeparator(SwingConstants.HORIZONTAL); layout.setConstraints(sep, layoutConstraints); add(sep); layout.setConstraints(lab, layoutConstraints); add(lab); layoutConstraints.weighty = 1; layout.setConstraints(secondPanel, layoutConstraints); add(secondPanel); layoutConstraints.weighty = 0; defaultButton.addActionListener(e -> { String tmp = layout1.getText().replace("\n", "__NEWLINE__"); PreviewPrefsTab.this.prefs.remove(JabRefPreferences.PREVIEW_0); layout1.setText( PreviewPrefsTab.this.prefs.get(JabRefPreferences.PREVIEW_0).replace("__NEWLINE__", "\n")); PreviewPrefsTab.this.prefs.put(JabRefPreferences.PREVIEW_0, tmp); }); defaultButton2.addActionListener(e -> { String tmp = layout2.getText().replace("\n", "__NEWLINE__"); PreviewPrefsTab.this.prefs.remove(JabRefPreferences.PREVIEW_1); layout2.setText( PreviewPrefsTab.this.prefs.get(JabRefPreferences.PREVIEW_1).replace("__NEWLINE__", "\n")); PreviewPrefsTab.this.prefs.put(JabRefPreferences.PREVIEW_1, tmp); }); testButton.addActionListener(e -> { PreviewPrefsTab.getTestEntry(); try { PreviewPanel testPanel = new PreviewPanel(null, PreviewPrefsTab.entry, null, layout1.getText()); testPanel.setPreferredSize(new Dimension(800, 350)); JOptionPane.showMessageDialog(null, testPanel, Localization.lang("Preview"), JOptionPane.PLAIN_MESSAGE); } catch (StringIndexOutOfBoundsException ex) { LOGGER.warn("Parsing error.", ex); JOptionPane.showMessageDialog(null, Localization.lang("Parsing error") + ": " + Localization.lang("illegal backslash expression") + ".\n" + ex.getMessage(), Localization.lang("Parsing error"), JOptionPane.ERROR_MESSAGE); } }); testButton2.addActionListener(e -> { PreviewPrefsTab.getTestEntry(); try { PreviewPanel testPanel = new PreviewPanel(null, PreviewPrefsTab.entry, null, layout2.getText()); testPanel.setPreferredSize(new Dimension(800, 350)); JOptionPane.showMessageDialog(null, new JScrollPane(testPanel), Localization.lang("Preview"), JOptionPane.PLAIN_MESSAGE); } catch (StringIndexOutOfBoundsException ex) { LOGGER.warn("Parsing error.", ex); JOptionPane.showMessageDialog(null, Localization.lang("Parsing error") + ": " + Localization.lang("illegal backslash expression") + ".\n" + ex.getMessage(), Localization.lang("Parsing error"), JOptionPane.ERROR_MESSAGE); } }); }
From source file:org.python.pydev.core.docutils.StringUtils.java
/** * <p>Find the index of <tt>character</tt> in a <tt>string</tt>.</p> * //from ww w. j a v a 2 s. c o m * <p>This method is like {@link java.lang.String#indexOf(int)} * but has the additional ability to ignore occurrences of * <tt>character</tt> in Python string literals (e.g. enclosed * by single, double or triple quotes). This is done by employing * a very simple statemachine.</p> * * @param string - the source string, e.g. the <i>haystack</i> * @param character - the character to retrieve the index for * @param ignoreInStringLiteral - if <tt>true</tt>, ignore occurrences * of <tt>character</tt> in Python string literals * @return the position of the character in string.<br> * if <tt>string</tt> is <tt>null</tt> or empty, or * if <tt>(int)character < 0</tt>, returns <tt>-1</tt>. * @note escaped (i.e. <tt>\"</tt>) characters are ignored and * control characters, e.g. line delimiters etc., are treated * normally like every other character. */ public static int indexOf(final String string, final char character, final boolean ignoreInStringLiteral) { if (null == string || ((int) character < 0) || string.length() == 0) { return -1; } int index = string.indexOf(character); if (-1 == index) { return index; } if (ignoreInStringLiteral) { final int len = string.length(); boolean inString = false; char nextc = '\0'; char c = '\0'; int i = -1; try { while (i < len) { i++; c = string.charAt(i); if ((i + 1) < len) { nextc = string.charAt(i + 1); } if ('\\' == c) { // ignore escapes i++; continue; } if (!inString && character == c) { index = i; break; } if ('"' == c || '\'' == c) { if ('"' == nextc || '\'' == nextc) { i++; continue; } else { if (inString) { inString = false; } else { inString = true; } } } } } catch (StringIndexOutOfBoundsException e) { // malformed Python string literals may throw a SIOOBE if (DEBUG) { System.err.print(e.getMessage()); } index = -1; } } return index; }
From source file:com.spd.ukraine.lucenewebsearch1.web.IndexingController.java
private String truncateText(String text, String phrase) { StringBuilder inputPhrase = new StringBuilder(); // try { // URL url = new URL(text); // BufferedReader in = new BufferedReader(new InputStreamReader(url // .openStream())); // String inputLine; // while ((inputLine = in.readLine()) != null) { // inputPhrase.append(inputLine); // if (inputPhrase.toString().contains(phrase) // && inputPhrase.length() > MAX_WINDOW_SIZE) { // break; // } // } // in.close(); // } catch (IOException ex) { // return ""; // }/*w ww. ja v a 2 s. c o m*/ inputPhrase = new StringBuilder(text); String lowerText = text.toLowerCase(); int pos = lowerText.indexOf(phrase); try { inputPhrase.delete(0, Math.max(0, pos - MAX_WINDOW_SIZE)) .delete(Math.min(pos + MAX_WINDOW_SIZE, inputPhrase.length()), inputPhrase.length()); } catch (StringIndexOutOfBoundsException e) { System.out.println("pos - MAX_WINDOW_SIZE " + (pos - MAX_WINDOW_SIZE)); System.out.println("pos + MAX_WINDOW_SIZE " + (pos + MAX_WINDOW_SIZE) + " < " + inputPhrase.length()); System.out.println(e.getMessage() + " text " + text); } return highLightPhrase(inputPhrase.toString(), phrase); }