List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast
public static String substringAfterLast(final String str, final String separator)
Gets the substring after the last occurrence of a separator.
From source file:com.projectsontracks.model.CaribooKey.java
/** * Open an AES key stored in an encrypted and password protected ZIP file * Then store the key in local variable byte[] key * * @param inputFileName/*from ww w .j a v a2 s . c o m*/ * @param password * @throws java.security.GeneralSecurityException * @throws java.io.FileNotFoundException * @throws net.lingala.zip4j.exception.ZipException * @throws com.projectsontracks.model.CaribooException */ public void loadKey(String inputFileName, String password) throws GeneralSecurityException, FileNotFoundException, IOException, ZipException, CaribooException { // read private key to be used to decrypt the AES key // Name of the file inside the ZIP String keyFileName = StringUtils.substringBeforeLast(inputFileName, ".") + "." + KEY_FILE_EXTENSION; keyFileName = StringUtils.substringAfterLast(keyFileName, "\\"); // Initiate ZipFile object with the path/name of the zip file. ZipFile zipFile = new ZipFile(inputFileName); //System.out.println("ZIP Key file: " + inputFileName); //System.out.println("Key file: " + keyFileName); ZipParameters parameters = new ZipParameters(); //parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to store compression //parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); if (zipFile.isEncrypted()) { zipFile.setPassword(password); } //parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES); //parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256); //Get a list of FileHeader. FileHeader is the header information for all the files in the ZipFile List fileHeaderList = zipFile.getFileHeaders(); // Loop through all the fileHeaders for (int i = 0; i < fileHeaderList.size(); i++) { FileHeader fileHeader = (FileHeader) fileHeaderList.get(i); if (fileHeader != null) { String fileName = fileHeader.getFileName(); //System.out.println(" Zip contains : " + fileName); if (keyFileName != null && keyFileName.equalsIgnoreCase(fileName)) { //Get the InputStream from the ZipFile ZipInputStream is = zipFile.getInputStream(fileHeader); File file = new File(fileName); // read the InputStream int readLen = -1; byte[] buff = new byte[32]; while ((readLen = is.read(buff)) != -1) { } // Assign to local variable this.key = buff; keySpec = new SecretKeySpec(this.key, "AES"); //System.out.println("Key: " + new String(this.key)); } else { throw new CaribooException(fileName + " does not match " + keyFileName); } } } //for }
From source file:io.wcm.handler.media.impl.ImageFileServlet.java
@Override protected String getContentType(Resource resource, SlingHttpServletRequest request) { // get filename from suffix to get extension String fileName = request.getRequestPathInfo().getSuffix(); if (StringUtils.isNotEmpty(fileName)) { // if extension is PNG use PNG content type, otherwise fallback to JPEG String fileExtension = StringUtils.substringAfterLast(fileName, "."); if (StringUtils.equalsIgnoreCase(fileExtension, FileExtension.PNG)) { return ContentType.PNG; }/*from w w w .ja va2s . c om*/ } // for rendered images use JPEG mime type as default fallback return ContentType.JPEG; }
From source file:io.knotx.mocks.adapter.MockServiceHandler.java
private String getFilePath(RoutingContext context) { return catalogue + File.separator + StringUtils.substringAfterLast(context.request().path(), SEPARATOR); }
From source file:com.thinkbiganalytics.schema.QueryRunner.java
/** * Initializes the query result with the specified metadata. * * @param queryResult the query result to initialize * @param rsMetaData the result set metadata for the query * @throws SQLException if the metadata is not available *///from w w w . j a v a2s .co m private void initQueryResult(@Nonnull final DefaultQueryResult queryResult, @Nonnull final ResultSetMetaData rsMetaData) throws SQLException { final List<QueryResultColumn> columns = new ArrayList<>(); final Map<String, Integer> displayNameMap = new HashMap<>(); for (int i = 1; i <= rsMetaData.getColumnCount(); i++) { final DefaultQueryResultColumn column = new DefaultQueryResultColumn(); column.setField(rsMetaData.getColumnName(i)); String displayName = rsMetaData.getColumnLabel(i); column.setHiveColumnLabel(displayName); //remove the table name if it exists displayName = StringUtils.contains(displayName, ".") ? StringUtils.substringAfterLast(displayName, ".") : displayName; Integer count = 0; if (displayNameMap.containsKey(displayName)) { count = displayNameMap.get(displayName); count++; } displayNameMap.put(displayName, count); column.setDisplayName(displayName + "" + (count > 0 ? count : "")); column.setTableName(StringUtils.substringAfterLast(rsMetaData.getColumnName(i), ".")); column.setDataType(ParserHelper.sqlTypeToHiveType(rsMetaData.getColumnType(i))); column.setNativeDataType(rsMetaData.getColumnTypeName(i)); columns.add(column); } queryResult.setColumns(columns); }
From source file:com.savoirfairelinux.jmeter.openstack.test.AbstractOpenstackSamplerTest.java
private String getTestConfiguration(String className, String key, String defaultValue) { return configuration.getProperty("sampler." + StringUtils.substringAfterLast(className, ".") + "." + key, defaultValue);// w w w .j av a2s .c o m }
From source file:de.crowdcode.movmvn.core.ContextImpl.java
private String getGroupDirectoryName() { String nameResult = StringUtils.substringAfterLast(this.groupDirectory, "/"); if (nameResult.equals("")) { // We have no "/" instead "\\" nameResult = StringUtils.substringAfterLast(this.groupDirectory, "\\"); }//from w w w . j a v a 2s .c o m return nameResult; }
From source file:com.netflix.spinnaker.clouddriver.ecs.services.EcsCloudMetricService.java
private Set<String> buildResourceList(List<String> metricAlarmArn, String serviceName) { return metricAlarmArn.stream().filter(arn -> arn.contains(serviceName)).map(arn -> { String resource = StringUtils.substringAfterLast(arn, ":resource/"); resource = StringUtils.substringBeforeLast(resource, ":policyName"); return resource; }).collect(Collectors.toSet()); }
From source file:com.neatresults.mgnltweaks.ui.contentapp.browser.QueryableJcrContainer.java
private String buildExtends(String path) { // one nasty bugger ... generate all possible combinations of extends for search // /a/b/c/d:// w ww.j a v a 2 s . c o m // /d : /a/b/c // /c/d : /a/b // /b/c/d : /a // /a/b/c/d : -- String end = StringUtils.substringAfterLast(path, "/"); String limit = StringUtils.substringBeforeLast(path, "/" + end); // extends w/ absolute path or too deeply nested StringBuilder or = new StringBuilder(" or t.extends like '%" + path + "' "); // and all other possible relative extends while (StringUtils.isNotEmpty(limit)) { or.append(" or (t.extends like '%/" + end + "' and ISDESCENDANTNODE([" + limit + "]))"); end = StringUtils.substringAfterLast(limit, "/") + "/" + end; limit = StringUtils.substringBeforeLast(limit, "/"); } return or.toString(); }
From source file:io.wcm.handler.mediasource.dam.impl.DamRenditionMetadataService.java
/** * Handle dam event if certain conditions are fulfilled. * @param event DAM event/*from w ww. j av a 2s .c o m*/ */ private void handleDamEvent(DamEvent event) { // make sure rendition file extension is an image extensions String renditionPath = event.getAdditionalInfo(); String renditionNodeName = Text.getName(renditionPath); String fileExtension = StringUtils.substringAfterLast(renditionNodeName, "."); if (!FileExtension.isImage(fileExtension)) { return; } // open admin session for reading/writing rendition metadata ResourceResolver adminResourceResolver = null; try { adminResourceResolver = resourceResolverFactory.getServiceResourceResolver(null); // make sure asset exists Asset asset = getAsset(event.getAssetPath(), adminResourceResolver); if (asset == null) { return; } if (event.getType() == DamEvent.Type.RENDITION_UPDATED) { renditionAddedOrUpdated(asset, renditionPath, event.getUserId(), adminResourceResolver); } else if (event.getType() == DamEvent.Type.RENDITION_REMOVED) { renditionRemoved(asset, renditionPath, event.getUserId(), adminResourceResolver); } } catch (LoginException ex) { log.warn("Getting service resource resolver failed. " + "Please make sure a service user is defined for bundle 'io.wcm.handler.media'.", ex); } finally { if (adminResourceResolver != null) { adminResourceResolver.close(); } } }
From source file:com.norconex.commons.lang.url.HttpURL.java
/** * Gets the last URL path segment without the query string. * If there are segment to return, /* ww w . j a v a 2 s. c o m*/ * an empty string will be returned instead. * @return the last URL path segment */ public String getLastPathSegment() { if (StringUtils.isBlank(path)) { return StringUtils.EMPTY; } String segment = path; segment = StringUtils.substringAfterLast(segment, "/"); return segment; }