List of usage examples for org.apache.commons.lang StringUtils remove
public static String remove(String str, char remove)
Removes all occurrences of a character from within the source string.
From source file:org.openflamingo.fs.s3.S3ObjectProvider.java
@Override public FileInfo getFileInfo(String path) { Assert.hasLength(path, "Enter the file or directory."); boolean isDir = path.endsWith("/"); try {/*w ww. j a v a 2s . c o m*/ String bucket = S3Utils.getBucket(path); String objectKey = null; if (isDir) { objectKey = S3Utils.getObjectKey(path); if (path.equals("/" + S3Utils.getBucket(path) + "/")) { // Bucket List<Bucket> buckets = awsClient.listBuckets(); for (Bucket b : buckets) { if (b.getName().equals(bucket)) { return new S3BucketInfo(b); } } } else { S3Object object = awsClient.getObject(bucket, objectKey); return new S3DirectoryInfo(path, object); } } objectKey = "/" + S3Utils.getBucket(path) + "/"; objectKey = StringUtils.remove(path, objectKey); S3Object object = awsClient.getObject(bucket, objectKey); return new S3ObjectInfo(object, objectKey); } catch (Exception ex) { // throw new FileSystemException(" '" + path + "'? ? ? .", ex); throw new FileSystemException("Cannot get file information.", ex); } }
From source file:org.openflamingo.fs.s3.S3ObjectProvider.java
@Override public InputStream getContent(String path) { Assert.hasLength(path, "Enter the path."); try {/*from ww w . j av a 2s . c om*/ String bucket = S3Utils.getBucket(path); String relativePath = StringUtils.remove(path, "/" + bucket + "/"); return awsClient.getObject(bucket, relativePath).getObjectContent(); } catch (Exception ex) { throw new FileSystemException( "The specified path can not get the file input stream file system, please check.", ex); } }
From source file:org.openflamingo.fs.s3.S3ObjectProvider.java
@Override public boolean delete(String path) { Assert.hasLength(path, "Please enter the file path."); if (S3Utils.isDirectory(path)) { ObjectListing objectListing = awsClient.listObjects(new ListObjectsRequest() .withBucketName(S3Utils.getBucket(path)).withPrefix(S3Utils.getObjectKey(path))); for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { awsClient.deleteObject(objectSummary.getBucketName(), objectSummary.getKey()); }/*from ww w . j ava2 s .c o m*/ } else { String bucket = S3Utils.getBucket(path); String relativePath = StringUtils.remove(path, "/" + bucket + "/"); awsClient.deleteObject(bucket, relativePath); } // auditService.delete(FileSystemType.S3, username, path); return true; }
From source file:org.openflamingo.fs.s3.S3ObjectProvider.java
@Override public boolean copy(String from, String to) { // Assert.hasLength(from, " ?? ? 'from'? ."); Assert.hasLength(from, "Please enter the source path."); // Assert.hasLength(to, " ? 'to' ."); Assert.hasLength(to, "Please enter the destination path."); String fromBucket = S3Utils.getBucket(from); String toBucket = S3Utils.getBucket(to); String fromKey = StringUtils.remove(from, "/" + fromBucket + "/"); String toKey = S3Utils.getObjectKey(to); String fileName = getFileName(fromKey); try {/*from w w w.j av a2 s. c o m*/ CopyObjectRequest copyObjectRequest = new CopyObjectRequest(fromBucket, fromKey, toBucket, toKey + fileName); awsClient.copyObject(copyObjectRequest); return true; } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, " + "which means your request made it " + "to Amazon S3, but was rejected with an error " + "response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); // throw new FileSystemException("?? . ? ? ? .", ase); throw new FileSystemException("Cannot copy the file.", ase); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, " + "which means the client encountered " + "an internal error while trying to " + " communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); // throw new FileSystemException("?? . ? ? ? .", ace); throw new FileSystemException("Cannot copy the file.", ace); } }
From source file:org.openflamingo.fs.s3.S3ObjectProvider.java
public boolean save(InputStream is, long size, String path) { // Assert.notNull(is, " ?? 'is'? ."); Assert.notNull(is, "Please enter the input stream."); // Assert.hasLength(path, "?? ? ?? 'path'? ."); Assert.hasLength(path, "Please enter the path."); try {/*from w w w . j a v a 2s .co m*/ String bucket = S3Utils.getBucket(path); String key = StringUtils.remove(path, "/" + bucket + "/"); ObjectMetadata metadata = new ObjectMetadata(); metadata.setHeader(Headers.CONTENT_LENGTH, size); awsClient.putObject(new PutObjectRequest(bucket, key, is, metadata)); return true; } catch (AmazonServiceException ase) { System.out.println("Caught an AmazonServiceException, " + "which means your request made it " + "to Amazon S3, but was rejected with an error " + "response for some reason."); System.out.println("Error Message: " + ase.getMessage()); System.out.println("HTTP Status Code: " + ase.getStatusCode()); System.out.println("AWS Error Code: " + ase.getErrorCode()); System.out.println("Error Type: " + ase.getErrorType()); System.out.println("Request ID: " + ase.getRequestId()); // throw new FileSystemException("?? . ? ? ? .", ase); throw new FileSystemException("Connot copy the file.", ase); } catch (AmazonClientException ace) { System.out.println("Caught an AmazonClientException, " + "which means the client encountered " + "an internal error while trying to " + " communicate with S3, " + "such as not being able to access the network."); System.out.println("Error Message: " + ace.getMessage()); // throw new FileSystemException("?? . ? ? ?.", ace); throw new FileSystemException("Connot copy the file.", ace); } }
From source file:org.openflamingo.uploader.QuartzJob.java
@Override public void execute(JobExecutionContext context) throws JobExecutionException { ////////////////////////////////////// // Quartz Job Scheduler Context? // ? //from w w w . j av a2 s. c o m ////////////////////////////////////// JobDataMap dataMap = context.getMergedJobDataMap(); model = (Flamingo) dataMap.get("model"); job = (org.openflamingo.uploader.jaxb.Job) dataMap.get("job"); jobContext = (JobContext) dataMap.get("context"); ////////////////////////////////////// // ? ////////////////////////////////////// Date startDate = new Date(); String jobLoggerName = StringUtils.remove(job.getName(), " ") + "_" + DateUtils.parseDate(startDate, "yyyyMMddHHmm") + "_" + JVMIDUtils.generateUUID(); logger = LoggerFactory.getLogger(jobLoggerName); logger.info("--------------------------------------------"); logger.info("Job '{}'? ", job.getName()); logger.info("--------------------------------------------"); Handler handler = null; if (job.getPolicy().getIngress().getLocal() != null) { Local local = job.getPolicy().getIngress().getLocal(); handler = new LocalToHdfsHandler(jobContext, job, local, logger); } else if (job.getPolicy().getIngress().getHttp() != null) { Http http = job.getPolicy().getIngress().getHttp(); handler = new HttpToLocalHandler(jobContext, job, http, logger); } try { handler.validate(); handler.execute(); } catch (Exception ex) { String msg = " ? ? ? Quartz Job? ."; logger.warn(msg, ex); throw new JobExecutionException(msg, ex, false); } Date endDate = new Date(); logger.info("Job '{}'? ", job.getName()); logger.info("Job '{}'? ? ? ? ? {} (: {} / : {}).", new String[] { job.getName(), DateUtils.formatDiffTime(endDate, startDate), DateUtils.parseDate(startDate, "yyyy-MM-dd HH:mm:ss"), DateUtils.parseDate(endDate, "yyyy-MM-dd HH:mm:ss") }); }
From source file:org.openhab.binding.homematic.internal.communicator.parser.DisplayOptionsParser.java
/** * {@inheritDoc}//from w ww . j a v a 2 s . c o m */ @Override public Void parse(Object value) throws IOException { String optionsString = StringUtils.remove(toString(value), ' '); if (optionsString != null) { int idxFirstSep = optionsString.indexOf(","); if (idxFirstSep == -1) { text = optionsString; optionsString = ""; } else { text = optionsString.substring(0, idxFirstSep); optionsString = optionsString.substring(idxFirstSep + 1); } String[] options = StringUtils.split(optionsString, ","); String[] availableSymbols = getAvailableSymbols(channel); String[] availableBeepOptions = getAvailableOptions(channel, DATAPOINT_NAME_BEEP); String[] availableBacklightOptions = getAvailableOptions(channel, DATAPOINT_NAME_BACKLIGHT); String[] availableUnitOptions = getAvailableOptions(channel, DATAPOINT_NAME_UNIT); String deviceAddress = channel.getDevice().getAddress(); if (logger.isDebugEnabled()) { logger.debug("Remote control '{}' supports these beep options: {}", deviceAddress, availableBeepOptions); logger.debug("Remote control '{}' supports these backlight options: {}", deviceAddress, availableBacklightOptions); logger.debug("Remote control '{}' supports these unit options: {}", deviceAddress, availableUnitOptions); logger.debug("Remote control '{}' supports these symbols: {}", deviceAddress, symbols); } if (options != null) { for (String parameter : options) { logger.debug("Parsing remote control option '{}'", parameter); beep = getIntParameter(availableBeepOptions, beep, parameter, DATAPOINT_NAME_BEEP, deviceAddress); backlight = getIntParameter(availableBacklightOptions, backlight, parameter, DATAPOINT_NAME_BACKLIGHT, deviceAddress); unit = getIntParameter(availableUnitOptions, unit, parameter, DATAPOINT_NAME_UNIT, deviceAddress); if (ArrayUtils.contains(availableSymbols, parameter)) { logger.debug("Symbol '{}' found for remote control '{}'", parameter, deviceAddress); symbols.add(parameter); } } } } return null; }
From source file:org.openhab.binding.homematic.internal.communicator.RemoteControlOptionParser.java
/** * Extracts the possible options from the remote control and parses the * specified./*ww w.j av a 2 s . c o m*/ */ public HmRemoteControlOptions parse(String remoteControlAddress, String options) throws HomematicClientException { this.remoteControlAddress = remoteControlAddress; String[] parms = StringUtils.split(StringUtils.remove(options, ' '), ","); String[] symbols = getSymbols(); String[] beepValueList = getValueItems("BEEP"); String[] backlightValueList = getValueItems("BACKLIGHT"); String[] unitValueList = getValueItems("UNIT"); if (logger.isDebugEnabled()) { logger.debug("Remote control {} supports these beep parameter: {}", remoteControlAddress, beepValueList); logger.debug("Remote control {} supports these backlight parameter: {}", remoteControlAddress, backlightValueList); logger.debug("Remote control {} supports these unit parameter: {}", remoteControlAddress, unitValueList); logger.debug("Remote control {} supports these symbols: {}", remoteControlAddress, symbols); } HmRemoteControlOptions rcd = new HmRemoteControlOptions(); if (parms != null) { for (String parameter : parms) { logger.debug("Parsing remote control parameter {}", parameter); rcd.setBeep(getIntParameter(beepValueList, rcd.getBeep(), parameter, "BEEP")); rcd.setBacklight(getIntParameter(backlightValueList, rcd.getBacklight(), parameter, "BACKLIGHT")); rcd.setUnit(getIntParameter(unitValueList, rcd.getUnit(), parameter, "UNIT")); if (ArrayUtils.contains(symbols, parameter)) { logger.debug("Symbol {} found for remote control {}", parameter, remoteControlAddress); rcd.addSymbol(parameter); } } } return rcd; }
From source file:org.openhab.binding.plugwise.internal.PlugwiseUtils.java
public static String upperUnderscoreToLowerCamel(String text) { String upperCamel = StringUtils.remove(WordUtils.capitalizeFully(text, new char[] { '_' }), "_"); return upperCamel.substring(0, 1).toLowerCase() + upperCamel.substring(1); }
From source file:org.openhab.binding.weather.internal.converter.property.FeetConverter.java
/** * {@inheritDoc}/*from w w w . ja v a 2s . c om*/ */ @Override public Double convert(String value) throws Exception { value = StringUtils.trim(StringUtils.remove(value, "ft")); if (value != null) { return UnitUtils.feetToMeter(Double.valueOf(value)); } return null; }