List of usage examples for java.lang StringBuilder insert
@Override public StringBuilder insert(int offset, double d)
From source file:mdretrieval.UrlLoaderBean.java
public void loadMdFromUrl() { // debug/*from w w w . j a v a2 s . c om*/ GUIrefs.displayAlert(" INFO: trying to load from URL " + url); InputStream instream = FileFetcher.fetchFileFromUrl(url); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { org.apache.commons.io.IOUtils.copy(instream, baos); byte[] bytes = baos.toByteArray(); String extension = "xml"; String filename = UUID.randomUUID().toString(); List<FileData> resultList = FilePreprocessor.extractMDFilesFromXMLEmbedding(bytes, filename, extension); if (null != resultList && resultList.size() > 0) { GUIrefs.updateComponent(GUIrefs.fileDispDlg); GUIrefs.updateComponent(GUIrefs.filesToShow); StringBuilder sb = new StringBuilder(); for (FileData fd : resultList) { if (sb.length() != 0) { sb.append(','); } sb.append(fd.getSourceUrl()); } sb.insert(0, "fireBasicEvent(\'MDEeditedMD\' ,{url:\'["); sb.append("]\'});"); String command = sb.toString(); if (Master.DEBUG_LEVEL > Master.LOW) System.out.println(command); RequestContext.getCurrentInstance().execute(command); RequestContext.getCurrentInstance().execute("PF('fileDispDlg').show();"); } } catch (IOException e) { e.printStackTrace(); GUIrefs.displayAlert(StringUtilities.escapeQuotes(e.getMessage())); } }
From source file:com.espertech.esper.epl.expression.ExprNodeUtility.java
private static ExprNode resolveStaticMethodOrField(ExprIdentNode identNode, ExprValidationException propertyException, ExprValidationContext validationContext) throws ExprValidationException { // Reconstruct the original string StringBuilder mappedProperty = new StringBuilder(identNode.getUnresolvedPropertyName()); if (identNode.getStreamOrPropertyName() != null) { mappedProperty.insert(0, identNode.getStreamOrPropertyName() + '.'); }/*from w w w.j a v a 2 s. c o m*/ // Parse the mapped property format into a class name, method and single string parameter MappedPropertyParseResult parse = parseMappedProperty(mappedProperty.toString()); if (parse == null) { ExprConstantNode constNode = resolveIdentAsEnumConst(mappedProperty.toString(), validationContext.getMethodResolutionService()); if (constNode == null) { throw propertyException; } else { return constNode; } } // If there is a class name, assume a static method is possible. if (parse.getClassName() != null) { List<ExprNode> parameters = Collections .singletonList((ExprNode) new ExprConstantNodeImpl(parse.getArgString())); List<ExprChainedSpec> chain = new ArrayList<ExprChainedSpec>(); chain.add(new ExprChainedSpec(parse.getClassName(), Collections.<ExprNode>emptyList(), false)); chain.add(new ExprChainedSpec(parse.getMethodName(), parameters, false)); ExprNode result = new ExprDotNode(chain, validationContext.getMethodResolutionService().isDuckType(), validationContext.getMethodResolutionService().isUdfCache()); // Validate try { result.validate(validationContext); } catch (ExprValidationException e) { throw new ExprValidationException( "Failed to resolve enumeration method, date-time method or mapped property '" + mappedProperty + "': " + e.getMessage()); } return result; } // There is no class name, try a single-row function String functionName = parse.getMethodName(); try { Pair<Class, EngineImportSingleRowDesc> classMethodPair = validationContext.getMethodResolutionService() .resolveSingleRow(functionName); List<ExprNode> parameters = Collections .singletonList((ExprNode) new ExprConstantNodeImpl(parse.getArgString())); List<ExprChainedSpec> chain = Collections.singletonList( new ExprChainedSpec(classMethodPair.getSecond().getMethodName(), parameters, false)); ExprNode result = new ExprPlugInSingleRowNode(functionName, classMethodPair.getFirst(), chain, classMethodPair.getSecond()); // Validate try { result.validate(validationContext); } catch (RuntimeException e) { throw new ExprValidationException("Plug-in aggregation function '" + parse.getMethodName() + "' failed validation: " + e.getMessage()); } return result; } catch (EngineImportUndefinedException e) { // Not an single-row function } catch (EngineImportException e) { throw new IllegalStateException("Error resolving single-row function: " + e.getMessage(), e); } // Try an aggregation function factory try { AggregationFunctionFactory aggregationFactory = validationContext.getMethodResolutionService() .resolveAggregationFactory(parse.getMethodName()); ExprNode result = new ExprPlugInAggFunctionFactoryNode(false, aggregationFactory, parse.getMethodName()); result.addChildNode(new ExprConstantNodeImpl(parse.getArgString())); // Validate try { result.validate(validationContext); } catch (RuntimeException e) { throw new ExprValidationException("Plug-in aggregation function '" + parse.getMethodName() + "' failed validation: " + e.getMessage()); } return result; } catch (EngineImportUndefinedException e) { // Not an aggregation function } catch (EngineImportException e) { throw new IllegalStateException("Error resolving aggregation: " + e.getMessage(), e); } // There is no class name, try an aggregation function (AggregationSupport version, deprecated) try { AggregationSupport aggregation = validationContext.getMethodResolutionService() .resolveAggregation(parse.getMethodName()); ExprNode result = new ExprPlugInAggFunctionNode(false, aggregation, parse.getMethodName()); result.addChildNode(new ExprConstantNodeImpl(parse.getArgString())); // Validate try { result.validate(validationContext); } catch (RuntimeException e) { throw new ExprValidationException("Plug-in aggregation function '" + parse.getMethodName() + "' failed validation: " + e.getMessage()); } return result; } catch (EngineImportUndefinedException e) { // Not an aggregation function } catch (EngineImportException e) { throw new IllegalStateException("Error resolving aggregation: " + e.getMessage(), e); } // absolutly cannot be resolved throw propertyException; }
From source file:com.krawler.portal.util.StringUtil.java
public static String insert(String s, String insert, int offset) { if (s == null) { return null; }//from w ww .j a v a 2 s . c o m if (insert == null) { return s; } if (offset > s.length()) { offset = s.length(); } StringBuilder sb = new StringBuilder(s); sb.insert(offset, insert); return sb.toString(); }
From source file:com.givon.baseproject.xinlu.act.ActRegist.java
protected String splitPhoneNum(String phone) { StringBuilder builder = new StringBuilder(phone); builder.reverse();// w ww.ja va 2 s.c o m for (int i = 4, len = builder.length(); i < len; i += 5) { builder.insert(i, ' '); } builder.reverse(); return builder.toString(); }
From source file:to.sven.androidrccar.arduino.test.TestSuite.java
/** * Build a report from the {@link TestSuite}. * @return The report// ww w . ja v a 2 s.co m */ public String toString() { StringBuilder builder = new StringBuilder(); int total = tests.length; int runned = 0; int failed = 0; for (Test test : tests) { test.toStringBuilder(builder); runned += test.isRunned ? 1 : 0; failed += test.wasSuccessfull() ? 0 : 1; } builder.insert(0, "Test " + title + "\nTotal: " + total + " Runned: " + runned + " Failed: " + failed + "\n"); return builder.toString(); }
From source file:com.intelligentsia.dowsers.entity.store.fs.FileEntityStore.java
/** * Build a new instance of <code>FileEntityStore</code>. * /*from w w w . j a v a 2 s .co m*/ * @param root * root directory of this {@link EntityStore}. * @param entityMapper * {@link EntityMapper} to use * @param cacheBuilder * cache Builder * @throws NullPointerException * if one of parameters is null * @throws IllegalStateException * if root is not a directory of if it cannot be created */ public FileEntityStore(final File root, final EntityMapper entityMapper, final CacheBuilder<Object, Object> cacheBuilder) throws NullPointerException, IllegalStateException { super(); this.root = Preconditions.checkNotNull(root); this.entityMapper = Preconditions.checkNotNull(entityMapper); // check root if (!root.exists()) { if (!root.mkdirs()) { throw new IllegalStateException(StringUtils.format("unable to create directory '%s'", root)); } } if (!root.isDirectory()) { throw new IllegalStateException(StringUtils.format("'%s' is not a directory", root)); } // cache files = Preconditions.checkNotNull(cacheBuilder).build(new CacheLoader<Reference, File>() { @Override public File load(final Reference urn) throws Exception { final StringBuilder builder = new StringBuilder(urn.getIdentity().replace("-", "")); for (int i = 2; i < builder.length(); i += 2) { builder.insert(i, File.separator); i++; } builder.append(File.separator).append(urn.getIdentity()); return new File(new File(root, urn.getEntityClassName()), builder.toString()); } }); }
From source file:hudson.plugins.robot.model.RobotTestObject.java
/** * Generates the full packagename// w w w . j av a 2s.co m * @return */ public String getRelativePackageName(RobotTestObject thisObject) { StringBuilder sb = new StringBuilder(getName()); String parentPackage = getRelativeParent(thisObject); if (!"".equals(parentPackage)) { sb.insert(0, parentPackage); } return sb.toString(); }
From source file:org.nabucco.alfresco.enhScriptEnv.common.webscripts.processor.ScriptContentAdapter.java
protected String determineStorePath(final String fullPath, final String comparisonDescription) { String result = null;//from w w w.ja v a 2 s. c o m final String[] pathFragments = fullPath.split("/"); final StringBuilder pathBuilder = new StringBuilder(); for (int idx = pathFragments.length - 1; idx >= 0; idx--) { if (pathBuilder.length() != 0) { pathBuilder.insert(0, '/'); } pathBuilder.insert(0, pathFragments[idx]); // brute-force load & verify script with path constructed from the tail final ScriptContent scriptContent = this.scriptLoader.getScript(pathBuilder.toString()); if (scriptContent != null) { final String pathDescription = scriptContent.getPathDescription(); if (comparisonDescription.equals(pathDescription)) { // this is the current script result = pathBuilder.toString(); break; } } } return result; }
From source file:com.epam.reportportal.apache.http.impl.conn.Wire.java
private void wire(final String header, final InputStream instream) throws IOException { final StringBuilder buffer = new StringBuilder(); int ch;/*from ww w. ja va 2 s .co m*/ while ((ch = instream.read()) != -1) { if (ch == 13) { buffer.append("[\\r]"); } else if (ch == 10) { buffer.append("[\\n]\""); buffer.insert(0, "\""); buffer.insert(0, header); log.debug(id + " " + buffer.toString()); buffer.setLength(0); } else if ((ch < 32) || (ch > 127)) { buffer.append("[0x"); buffer.append(Integer.toHexString(ch)); buffer.append("]"); } else { buffer.append((char) ch); } } if (buffer.length() > 0) { buffer.append('\"'); buffer.insert(0, '\"'); buffer.insert(0, header); log.debug(id + " " + buffer.toString()); } }
From source file:de.matzefratze123.heavyspleef.core.FlagManager.java
public void addFlag(AbstractFlag<?> flag) { Class<?> clazz = flag.getClass(); Validate.isTrue(clazz.isAnnotationPresent(Flag.class), "Flag class " + clazz.getCanonicalName() + " must annotate " + Flag.class.getCanonicalName()); Flag flagAnnotation = clazz.getAnnotation(Flag.class); //Generate the full path StringBuilder pathBuilder = new StringBuilder(); Flag lastParentFlagData = flagAnnotation; while (lastParentFlagData != null) { pathBuilder.insert(0, lastParentFlagData.name()); Class<? extends AbstractFlag<?>> parentClass = lastParentFlagData.parent(); lastParentFlagData = parentClass.getAnnotation(Flag.class); if (lastParentFlagData != null) { pathBuilder.insert(0, ":"); }/* ww w. ja v a 2 s .c o m*/ } String path = pathBuilder.toString(); if (flags.containsKey(path)) { return; } flags.put(path, flag); if (clazz.isAnnotationPresent(BukkitListener.class)) { Bukkit.getPluginManager().registerEvents(flag, plugin); } if (flagAnnotation.hasGameProperties()) { Map<GameProperty, Object> flagGamePropertiesMap = new EnumMap<GameProperty, Object>(GameProperty.class); flag.defineGameProperties(flagGamePropertiesMap); if (!flagGamePropertiesMap.isEmpty()) { GamePropertyBundle properties = new GamePropertyBundle(flag, flagGamePropertiesMap); propertyBundles.add(properties); } } }