List of usage examples for java.lang String replaceFirst
public String replaceFirst(String regex, String replacement)
From source file:de.appplant.cordova.plugin.notification.Asset.java
/** * The URI for a resource.//from ww w . jav a 2 s .com * * @param path * The given relative path * * @return The URI pointing to the given path */ private Uri getUriForResourcePath(String path) { String resPath = path.replaceFirst("res://", ""); String fileName = resPath.substring(resPath.lastIndexOf('/') + 1); String resName = fileName.substring(0, fileName.lastIndexOf('.')); String extension = resPath.substring(resPath.lastIndexOf('.')); File dir = activity.getExternalCacheDir(); if (dir == null) { Log.e("Asset", "Missing external cache dir"); return Uri.EMPTY; } String storage = dir.toString() + STORAGE_FOLDER; int resId = getResId(resPath); File file = new File(storage, resName + extension); if (resId == 0) { Log.e("Asset", "File not found: " + resPath); return Uri.EMPTY; } new File(storage).mkdir(); try { Resources res = activity.getResources(); FileOutputStream outStream = new FileOutputStream(file); InputStream inputStream = res.openRawResource(resId); copyFile(inputStream, outStream); outStream.flush(); outStream.close(); return Uri.fromFile(file); } catch (Exception e) { e.printStackTrace(); } return Uri.EMPTY; }
From source file:hydrograph.ui.dataviewer.utilities.Utils.java
/** * //from w w w . ja v a 2s .c om * Return tools Installation path * * @return {@link String} */ public String getInstallationPath() { String installationPath = Platform.getInstallLocation().getURL().getPath(); if (OSValidator.isWindows()) { if (installationPath.startsWith("/")) { installationPath = installationPath.replaceFirst("/", "").replace("/", "\\"); } } return installationPath; }
From source file:com.jkoolcloud.tnt4j.streams.utils.StreamsThread.java
/** * Sets default name for a Streams thread. * <p>// w w w .j av a2 s . c om * Prefixes current (default) thread name with thread's ID and strips off leading "com.jkoolcloud.tnt4j.streams." * from thread name. * * @param name * user defined thread name or {@code null} if undefined */ protected void setDefaultName(String name) { String dName = StringUtils.isEmpty(name) ? getClass().getName() : name; dName = String.format("%s:%s", getId(), dName.replaceFirst("com.jkoolcloud.tnt4j.streams.", "")); // NON-NLS setName(dName); }
From source file:de.knurt.fam.core.model.config.FileUploadController.java
private String getNewFilename(String filename) { String suffix = filename.replaceFirst(".*\\.", ""); String result = filename.substring(0, filename.length() - suffix.length() - 1).replaceAll("[^a-zA-Z0-9]", "_"); while (result != result.replaceAll("__", "_")) result = result.replaceAll("__", "_"); result += "." + suffix.toLowerCase(); // check if this one exists boolean exists = false; for (File e : this.getExistingFileNames()) { if (e.getName().equalsIgnoreCase(result)) { exists = true;//from w w w . ja v a 2 s. c om break; } } if (exists) { result = result.substring(0, result.length() - suffix.length() - 1) + "_copy." + suffix; return this.getNewFilename(result); } else { return result; } }
From source file:net.sourceforge.atunes.kernel.modules.repository.ImportFilesProcess.java
/** * Prepares the directory structure in which the song will be written. * /*from w w w . j a v a 2 s.c o m*/ * @param song * Song to be written * @param destinationBaseFolder * Destination path * @return Returns the directory structure with full path where the file * will be written */ public File getDirectory(AudioFile song, File destinationBaseFolder) { // Get base folder or the first folder if there is any error File baseFolder = null; for (File folder : folders) { if (song.getFile().getAbsolutePath().startsWith(folder.getParentFile().getAbsolutePath())) { baseFolder = folder.getParentFile(); break; } } if (baseFolder == null) { baseFolder = folders.get(0); } String songPath = song.getFile().getParentFile().getAbsolutePath(); String songRelativePath = songPath .replaceFirst(baseFolder.getAbsolutePath().replace("\\", "\\\\").replace("$", "\\$"), ""); if (ApplicationState.getInstance().getImportExportFolderPathPattern() != null) { songRelativePath = FileNameUtils.getValidFolderName(FileNameUtils .getNewFolderPath(ApplicationState.getInstance().getImportExportFolderPathPattern(), song)); } return new File(StringUtils.getString(destinationBaseFolder.getAbsolutePath(), SystemProperties.FILE_SEPARATOR, songRelativePath)); }
From source file:com.eharmony.services.swagger.SwaggerResourceServer.java
/** * Serves static resources. Would be better to just punt all this to Jetty, but couldn't figure * out how to make that happen without mucking with Jetty configurations separately for each service. * Doing it here compartmentalizes this from normal service handling flow. *///from w w w .ja v a 2 s. co m @GET @Path("/{fileName:.*}") public Response getStatic(@PathParam("fileName") String file) throws IOException, URISyntaxException { int qp = file.indexOf('?'); file = (qp > 0) ? file.substring(0, qp) : file; file = file.contains("theme") ? file.replaceFirst("theme", themePath) : file; if (!file.contains("..")) { byte[] data = cache.get(file); if (data == null) { Resource[] rz = resolver.getResources(String.format(SWAGGER_UI_PATH, file)); if (rz.length > 0) { try (InputStream result = rz[0].getInputStream()) { data = ByteStreams.toByteArray(result); cache.putIfAbsent(file, data); } } } if (data != null) { String mimeType = URLConnection.guessContentTypeFromName(file); CacheControl cacheControl = new CacheControl(); cacheControl.setMaxAge(600); return Response.ok(data, mimeType).cacheControl(cacheControl).build(); } } throw new WebApplicationException(Response.Status.NOT_FOUND); }
From source file:edu.rit.flick.config.FileArchiverExtensionRegistry.java
public synchronized void registerFileArchiverExtensions(final RegisterFileDeflatorInflator fileDIP) throws InstantiationException, IllegalAccessException { final List<String> extensions = Arrays.asList(fileDIP.inflatedExtensions()); for (int e = 0; e < extensions.size(); e++) { String extension = extensions.get(e); if (!extension.startsWith(".")) extension = "." + extension; if (extension.matches("\\.{2,}.+")) extension = extension.replaceFirst("\\.{2,}", "."); extensions.set(e, extension);//from w w w .j a v a2 s .co m } for (final String extension : extensions) { registry.put(extension, new FileDeflatorInflator(fileDIP.fileDeflator().newInstance(), fileDIP.fileInflator().newInstance(), extensions)); } deflationOptionSets.add(fileDIP.fileDeflatorOptionSet().newInstance()); inflationOptionSets.add(fileDIP.fileInflatorOptionSet().newInstance()); }
From source file:org.openmrs.module.yank.web.controller.QueryController.java
private String renderMessage(List<String> list, String description) { if (list.isEmpty()) return null; if (list.size() > LIST_THRESHOLD) { if (list.size() == 1) description = description.replaceAll("items", "item"); return description.replaceFirst("\\$count", "" + list.size()); }//from w ww . j ava 2s . c om return Joiner.on("<br/>").join(list); }
From source file:cfa.vo.iris.AbstractIrisApplication.java
@Override protected void initialize(String[] args) { List<String> properties = new ArrayList<>(); List<String> arguments = new ArrayList<>(); for (String arg : args) { if (arg.startsWith("--")) { arg = arg.replaceFirst("--", ""); properties.add(arg);/* ww w .jav a 2s . com*/ } else { arguments.add(arg); } } if (arguments.size() >= 1) { isBatch = true; componentName = arguments.get(0); componentArgs = new String[arguments.size() - 1]; for (int i = 1; i < arguments.size(); i++) { componentArgs[i - 1] = arguments.get(i); } } setProperties(properties); }
From source file:com.xinlei.core.app.cas.web.ProxyTicketSampleServlet.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // NOTE: The CasAuthenticationToken can also be obtained using // SecurityContextHolder.getContext().getAuthentication() final CasAuthenticationToken token = (CasAuthenticationToken) request.getUserPrincipal(); // proxyTicket could be reused to make calls to to the CAS service even if the // target url differs final String proxyTicket = token.getAssertion().getPrincipal().getProxyTicketFor(targetUrl); // Make a remote call to ourselves. This is a bit silly, but it works well to // demonstrate how to use proxy tickets. final String serviceUrl = targetUrl + "?ticket=" + URLEncoder.encode(proxyTicket, "UTF-8"); String proxyResponse = CommonUtils.getResponseFromServer(new URL(serviceUrl), new HttpsURLConnectionFactory(), "UTF-8"); // modify the response and write it out to inform the user that it was obtained // using a proxy ticket. proxyResponse = proxyResponse.replaceFirst("Secure Page", "Secure Page using a Proxy Ticket"); proxyResponse = proxyResponse.replaceFirst("<p>", "<p>This page is rendered by " + getClass().getSimpleName() + " by making a remote call to the Secure Page using a proxy ticket (" + proxyTicket + ") and inserts this message. "); response.setContentType("text/html;charset=UTF-8"); final PrintWriter writer = response.getWriter(); writer.write(proxyResponse);// w ww . java2 s.c o m }