List of usage examples for java.lang String replaceFirst
public String replaceFirst(String regex, String replacement)
From source file:mamo.vanillaVotifier.util.JsonUtils.java
public static String jsonToPrettyString(JSONObject jsonObject) { String[] prettyStringLines = jsonObject.toString(1) .split("\\u000D\\u000A|[\\u000A\\u000B\\u000C\\u000D\\u0085\\u2028\\u2029]"); String prettyString = ""; for (String prettyStringLine : prettyStringLines) { for (int i = 0; i < prettyStringLine.length(); i++) { if (prettyStringLine.charAt(i) == ' ') { prettyStringLine = prettyStringLine.replaceFirst(" ", "\t"); } else { // If it's not a space, therefore I don't need to replace with tabs anymore, break; }//from ww w. j a v a 2s . co m } prettyString += prettyStringLine + System.getProperty("line.separator"); } return prettyString.substring(0, prettyString.length() - System.getProperty("line.separator").length()); }
From source file:io.github.jeddict.jcode.util.JavaUtil.java
public static String removeBeanMethodPrefix(String methodName) { if (methodName.startsWith("get")) { methodName = methodName.replaceFirst("get", EMPTY); }// w ww.ja v a 2 s . co m if (methodName.startsWith("set")) { methodName = methodName.replaceFirst("set", EMPTY); } if (methodName.startsWith("is")) { methodName = methodName.replaceFirst("is", EMPTY); } return methodName; }
From source file:Main.java
public static String timeAgo(String iso8601) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); ParsePosition position = new ParsePosition(0); Date date = null;//from w w w .j av a 2s .c om try { date = simpleDateFormat.parse(iso8601.replaceFirst("Z", "+00:00"), position); } catch (Exception e) { System.out.println("could not parese date"); } String timeAgo = date == null ? "" : DateUtils.getRelativeTimeSpanString(date.getTime()).toString(); return timeAgo; }
From source file:com.autentia.tnt.xml.UtilitiesXML.java
/** * Esta funcion recoge un path y devuelve el nombre del fichero referido sin extension * @return// ww w . ja va2 s . c o m */ public static String cleanReport(String path) { String pathCleaned = ""; pathCleaned = path.substring(path.indexOf("Informe")); pathCleaned = pathCleaned.replaceFirst(".jrxml", ""); return pathCleaned; }
From source file:gridool.db.partitioning.monetdb.MonetDBCopyIntoOperation.java
private static String complementCopyIntoQuery(final String query, final File loadFile) { String path = loadFile.getAbsolutePath(); return query.replaceFirst("<src>", path); }
From source file:io.github.azige.whitespace.Cli.java
static void compile(InputStream input, String path) throws IOException { Interpreter interpreter = createInterpreter(); Program program = interpreter.interpret(createReader(input)); path = path.replaceFirst("\\.[^\\.]+$", WHITESPACE_BINARY_FILE_SUFFIX); try (ObjectOutputStream output = new ObjectOutputStream( new GZIPOutputStream(Files.newOutputStream(Paths.get(path))))) { output.writeObject(program);/* www . jav a 2 s. c o m*/ } }
From source file:org.acme.insurance.policyquote.test.WorkServiceMain.java
private static void invokeWorkService(String scheme, int port, Element assertion) throws Exception { String soapRequest = new StringPuller().pull("/xml/soap-request.xml"); LOGGER.info("Assertion: " + XMLHelper.toString(assertion)); if (assertion != null) { soapRequest = soapRequest.replaceFirst("<!-- Assertion -->", XMLHelper.toString(assertion)); }//from www. j a va 2 s .c o m HTTPMixIn http = new HTTPMixIn(); http.initialize(); try { String endpoint = String.format( "%s://" + serverHostname + ":%s/policy-quote-saml/PolicyQuoteEntityWSService", scheme, port); //LOGGER.info(String.format("Invoking work service at endpoint: %s with request: %s", endpoint, soapRequest)); LOGGER.info(String.format("Invoking work service at endpoint: %s", endpoint)); String soapResponse = http.postString(endpoint, soapRequest); //LOGGER.info(String.format("Received work service response: %s", soapResponse)); if (soapResponse.toLowerCase().contains("fault")) { throw new Exception("Error invoking work service (check server log)"); } } finally { http.uninitialize(); } }
From source file:info.dolezel.fatrat.plugins.helpers.NativeHelpers.java
private static Set<Class> findClasses(File directory, String packageName, Class annotation) throws ClassNotFoundException, IOException { Set<Class> classes = new HashSet<Class>(); if (!directory.exists()) { String fullPath = directory.toString(); String jarPath = fullPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", ""); JarFile jarFile = new JarFile(jarPath); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); String entryName = entry.getName(); if (entryName.endsWith(".class") && !entryName.contains("$")) { String className = entryName.replace('/', '.').replace('\\', '.').replace(".class", ""); Class cls = loader.loadClass(className); if (annotation == null || cls.isAnnotationPresent(annotation)) classes.add(cls);/*from w w w. j ava 2 s. c o m*/ } } } else { File[] files = directory.listFiles(); for (File file : files) { if (file.isDirectory()) { assert !file.getName().contains("."); classes.addAll(findClasses(file, packageName + "." + file.getName(), annotation)); } else if (file.getName().endsWith(".class")) { Class cls = loader.loadClass( packageName + '.' + file.getName().substring(0, file.getName().length() - 6)); if (annotation == null || cls.isAnnotationPresent(annotation)) classes.add(cls); } } } return classes; }
From source file:com.elasticbox.jenkins.k8s.repositories.api.charts.github.GitHubUrl.java
private static String normalize(String url) { if (StringUtils.isBlank(url)) { return null; }//from w ww .j a v a2 s.c om // Strip "/tree/..." if (url.contains("/tree/")) { url = url.replaceFirst("/tree/.*$", ""); } if (!url.endsWith("/")) { url += '/'; } return url; }
From source file:com.palantir.atlasdb.keyvalue.rdbms.utils.AtlasSqlUtils.java
public static final String USR_TABLE(String tableName) { return USER_TABLE_PREFIX + tableName.replaceFirst("\\.", "_"); }