List of usage examples for java.lang String replaceFirst
public String replaceFirst(String regex, String replacement)
From source file:com.threadswarm.imagefeedarchiver.FeedUtils.java
/** * Returns a {@code String} where "http://" has been replaced with "https://" (if present). * <p>/* w w w .j a va 2 s . c om*/ * The match on "http://" is case-insensitive but does stipulate that the aforementioned * pattern be located at the beginning of the {@code urlString} argument. * * @param urlString a {@code String} based representation of a URL * @return a {@code String} where "http://" has been replaced with "https://" */ public static String rewriteUrlStringToHttps(String urlString) { return urlString.replaceFirst("(?s)(?i:^http://)", "https://"); }
From source file:com.alifi.jgenerator.utils.StringFormatUtils.java
/** * ?/*from ww w.j av a 2 s . co m*/ * * @param str * @return */ public static String humpCPix(String pix, String str) { if (StringUtils.isNotEmpty(str)) { String strs = str.toLowerCase(); String pixx = pix.toLowerCase(); return hump(strs.replaceFirst(pixx, "").replaceAll("_", " ")); } return null; }
From source file:Main.java
public static List<String> getAllTables(Uri uri) { List<String> result = new ArrayList<String>(); String mainTable = uri.getLastPathSegment(); result.add(mainTable);// w ww.j a va2s .c om Set<String> queryParameterNames = uri.getQueryParameterNames(); Iterator<String> iterator = queryParameterNames.iterator(); while (iterator.hasNext()) { String table = iterator.next(); if (table.startsWith(TABLE)) { result.add(table.replaceFirst(TABLE, "")); } } return result; }
From source file:com.smallnn.input.FileUtil.java
public static File tildeExpand(String path) { if (path.startsWith("~")) { path = path.replaceFirst("~", getUserHome().getAbsolutePath()); }//ww w . ja v a2 s . c o m return new File(path); }
From source file:Main.java
public static String formatToUrl(String filePath) { if (filePath == null) { return null; }/*from w w w . jav a2 s .c o m*/ filePath = filePath.replaceFirst("file:[/\\\\]*", ""); filePath = filePath.replaceAll("[/\\\\]+", "/"); if (filePath.startsWith("/")) { filePath = "file://" + filePath; } else { filePath = "file:///" + filePath; } return filePath; }
From source file:Main.java
public static String toXxml(Object bean) { StringWriter stringWriter = null; try {/* w w w .j a v a2 s . co m*/ JAXBContext jaxbContext = JAXBContext.newInstance(bean.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); stringWriter = new StringWriter(); marshaller.marshal(bean, stringWriter); String result = stringWriter.toString(); // remove xml declaration result = result.replaceFirst(".*\n", ""); return result; } catch (JAXBException e) { throw new RuntimeException(e); } finally { if (stringWriter != null) try { stringWriter.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:Main.java
public static boolean renameDict(final File dictFile, final File newDictFile) { if (dictFile.isFile()) { return dictFile.renameTo(newDictFile); } else if (dictFile.isDirectory()) { final String dictName = dictFile.getName(); final String newDictName = newDictFile.getName(); if (newDictFile.exists()) { return false; }// www. jav a 2 s . co m for (final File file : dictFile.listFiles()) { if (!file.isFile()) { continue; } final String fileName = file.getName(); final String newFileName = fileName.replaceFirst(Pattern.quote(dictName), Matcher.quoteReplacement(newDictName)); if (!file.renameTo(new File(dictFile, newFileName))) { return false; } } return dictFile.renameTo(newDictFile); } return false; }
From source file:Main.java
public static String toUpperCase(String str, int beginIndex, int endIndex) { return str.replaceFirst(str.substring(beginIndex, endIndex), str.substring(beginIndex, endIndex).toUpperCase(Locale.getDefault())); }
From source file:Main.java
public static String fieldToParams(String fieldName) { for (char a : fieldName.toCharArray()) { if (a >= 65 && a <= 90) { fieldName = fieldName.replaceFirst(String.valueOf(a), "_" + a); }//w w w . jav a2 s . c o m } fieldName = fieldName.toUpperCase(); return fieldName; }
From source file:Main.java
/** * Pings a HTTP URL. This effectively sends a HEAD request and returns <code>true</code> if the response code is in * the 200-399 range.// w w w. j a v a 2s. com * @param url The HTTP URL to be pinged. * @param timeout The timeout in millis for both the connection timeout and the response read timeout. Note that * the total timeout is effectively two times the given timeout. * @return <code>true</code> if the given HTTP URL has returned response code 200-399 on a HEAD request within the * given timeout, otherwise <code>false</code>. */ public static boolean ping(String url, int timeout) { // Otherwise an exception may be thrown on invalid SSL certificates: url = url.replaceFirst("^https", "http"); try { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setConnectTimeout(timeout); connection.setReadTimeout(timeout); connection.setRequestMethod("HEAD"); int responseCode = connection.getResponseCode(); return (200 <= responseCode && responseCode <= 399); } catch (IOException exception) { return false; } }