List of usage examples for java.lang StringBuilder insert
@Override public StringBuilder insert(int offset, double d)
From source file:immf.growl.GrowlNotifier.java
private boolean send(ImodeMail mail) { List<NameValuePair> formparams = new ArrayList<NameValuePair>(); StringBuilder apiStringBuilder = new StringBuilder(); for (GrowlKey growlKey : this.growlApiKeyList) { if (GrowlKeyState.VALID == growlKey.getState()) { apiStringBuilder.append(growlKey.getKey()); apiStringBuilder.append(","); }/*from w ww . j av a2 s . c om*/ } if (apiStringBuilder.length() == 0) return false; String apiKey = apiStringBuilder.substring(0, apiStringBuilder.length() - 1); formparams.add(new BasicNameValuePair("apikey", apiKey)); formparams.add(new BasicNameValuePair("application", "imoten")); StringBuilder eventStringBuilder = new StringBuilder("??????"); if (mail.getFromAddr().getPersonal() != null && this.config.isForwardPushFrom()) { eventStringBuilder.insert(0, "??"); eventStringBuilder.insert(0, mail.getFromAddr().getPersonal()); } else if (this.config.isForwordPushNotifyAddress() || this.config.isForwardPushNotifyUnknownAddress()) { eventStringBuilder.insert(0, "?"); eventStringBuilder.insert(0, mail.getFromAddr().getAddress()); } formparams.add(new BasicNameValuePair("event", eventStringBuilder.toString())); StringBuilder message = new StringBuilder(); SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT); if (mail.getFromAddr().getPersonal() != null && this.config.isForwordPushNotifyAddress()) { message.append("From:").append(mail.getFromAddr().getAddress()).append("\r\n"); } message.append(":").append(df.format(mail.getTimeDate())).append("\r\n"); if (this.config.isForwardPushSubject()) message.append("??:").append(EmojiUtil.replaceToLabel(mail.getSubject())).append("\r\n"); if (this.config.isForwordPushNotifyBody()) { message.append(":\r\n"); String messageBody = mail.getBody(); if (mail.isDecomeFlg()) { messageBody = Util.html2text(messageBody); } message.append(messageBody); } if (message.length() > MAX_DISCRIPTION_LENGTH) { formparams.add(new BasicNameValuePair("description", message.substring(0, MAX_DISCRIPTION_LENGTH - 1))); } else { formparams.add(new BasicNameValuePair("description", message.toString())); } return this.client.post(formparams); }
From source file:com.edgenius.wiki.render.RenderUtil.java
/** * @param input/*from w w w. ja va 2s . com*/ * @param key * @param regions * @param newlineKey * @return */ public static CharSequence createRegion(CharSequence input, String key, Collection<Region> regions, String newlineKey) { if (regions == null || regions.size() == 0) return input; //first, web split whole text by special border tag string some think like "key_regionKey_S|E" input = createRegionBorder(input, key, regions, newlineKey); //then we split them one by one. The split is dependent on the RegionComparator(), which ensure the split //from end to start, and from inside to outside. And this makes easier on below replacement process. Set<Region> sortRegions = new TreeSet<Region>(new RegionComparator()); sortRegions.addAll(regions); StringBuilder buf = new StringBuilder(input); StringBuilder regKey = new StringBuilder(key); int ks = key.length(); for (Region region : sortRegions) { //See our issue http://bug.edgenius.com/issues/34 //and SUN Java bug: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6337993 Pattern pat = Pattern.compile(new StringBuilder(key).append(region.getKey()).append("S(.*?)") .append(key).append(region.getKey()).append("E").toString(), Pattern.DOTALL); try { Matcher matcher = pat.matcher(buf); if (matcher.find()) { region.setBody(matcher.group(1)); buf.delete(matcher.start(), matcher.end()); regKey.delete(ks, regKey.length()); buf.insert(matcher.start(), regKey.append(region.getKey()).append(Region.REGION_SUFFIX)); } } catch (StackOverflowError e) { AuditLogger.error("StackOverflow Error in RenderUtil.createRegion. Input[" + buf + "] Pattern [" + pat.pattern() + "]"); } catch (Throwable e) { AuditLogger.error("Unexpected error in RenderUtil.createRegion. Input[" + buf + "] Pattern [" + pat.pattern() + "]", e); } } return buf; }
From source file:com.moss.appsnap.keeper.windows.MSWindowsAppHandler.java
private StringBuilder launchCommand(final ResolvedJavaLaunchSpec launch) { StringBuilder text = launchArgs(launch); final String pathToJava = "javaw"; text.insert(0, " "); text.insert(0, pathToJava);/*from ww w . ja va 2 s.c om*/ return text; }
From source file:org.wso2.emm.agent.services.operation.OperationManager.java
public static String getOperationResponseFromLogcat(Context context, String logcat) throws IOException { File logcatFile = new File(logcat); if (logcatFile.exists() && logcatFile.canRead()) { DeviceInfo deviceInfo = new DeviceInfo(context); EventPayload eventPayload = new EventPayload(); eventPayload.setPayload(logcat); eventPayload.setType("LOGCAT"); eventPayload.setDeviceIdentifier(deviceInfo.getDeviceId()); StringBuilder emmBuilder = new StringBuilder(); StringBuilder publisherBuilder = new StringBuilder(); int index = 0; String line;/* w ww . ja va 2 s.c o m*/ ReversedLinesFileReader reversedLinesFileReader = new ReversedLinesFileReader(logcatFile, Charset.forName("US-ASCII")); while ((line = reversedLinesFileReader.readLine()) != null) { publisherBuilder.insert(0, "\n"); publisherBuilder.insert(0, line); //OPERATION_RESPONSE filed in the DM_DEVICE_OPERATION_RESPONSE is declared as a blob and hence can only hold 64Kb. //So we don't want to throw exceptions in the server. Limiting the response in here to limit the server traffic also. if (emmBuilder.length() < Character.MAX_VALUE - 8192) { //Keeping 8kB for rest of the response payload. emmBuilder.insert(0, "\n"); emmBuilder.insert(0, line); } if (++index >= Constants.LogPublisher.NUMBER_OF_LOG_LINES) { break; } } LogPublisherFactory publisher = new LogPublisherFactory(context); if (publisher.getLogPublisher() != null) { eventPayload.setPayload(publisherBuilder.toString()); publisher.getLogPublisher().publish(eventPayload); if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Logcat published size: " + eventPayload.getPayload().length()); } } eventPayload.setPayload(emmBuilder.toString()); Gson logcatResponse = new Gson(); logcatFile.delete(); if (Constants.DEBUG_MODE_ENABLED) { Log.d(TAG, "Logcat payload size: " + eventPayload.getPayload().length()); } return logcatResponse.toJson(eventPayload); } else { throw new IOException("Unable to find or read log file."); } }
From source file:com.zimbra.cs.fb.ExchangeMessage.java
private String minutesSinceMsEpoch(long millis) { // filetime or ms epoch is calculated as minutes since Jan 1 1601 // standard epoch is Jan 1 1970. the offset in seconds is // 11644473600 long mins = (millis / 1000 + 11644473600L) / 60; // convert to hex in little endian. StringBuilder buf = new StringBuilder(); for (int i = 0; i < 8; i++) { int b = (int) (mins & 0xF); buf.insert(0, HEX[b]); mins >>= 4;// ww w .j av a2s . co m } buf.insert(0, "0x"); return buf.toString(); }
From source file:com.jeans.iservlet.model.asset.Asset.java
@Transient @Field// w w w. j av a2 s . c o m public String getFullName() { if (StringUtils.isBlank(name)) { return ""; } else { StringBuilder fn = new StringBuilder(name); if (type == AssetConstants.SOFTWARE_ASSET) { if (!StringUtils.isBlank(vendor)) { fn.insert(0, " ").insert(0, vendor); } if (!StringUtils.isBlank(modelOrVersion)) { fn.append(" ").append(modelOrVersion); } } else { if (!StringUtils.isBlank(vendor)) { fn.append(" ").append(vendor); } if (!StringUtils.isBlank(modelOrVersion)) { fn.append(" ").append(modelOrVersion); } } return fn.toString(); } }
From source file:edu.wisc.my.stats.query.support.UWDataWareHouseInformationProvider.java
/** * @see edu.wisc.my.stats.query.DatabaseInformationProvider#getSelectResolutionsString(edu.wisc.my.stats.domain.TimeResolution) *//*w ww. j av a 2 s.c om*/ public String getSelectResolutionsString(TimeResolution resolution) { final StringBuilder resolutionBuilder = new StringBuilder(); switch (resolution) { case MINUTE: resolutionBuilder.append("TD.MINUTE"); case FIVE_MINUTE: if (resolutionBuilder.length() > 0) { resolutionBuilder.insert(0, ", "); } resolutionBuilder.insert(0, "TD.FIVE_MINUTE_INCREMENT"); case HOUR: if (resolutionBuilder.length() > 0) { resolutionBuilder.insert(0, ", "); } resolutionBuilder.insert(0, "TD.HOUR"); case DAY: if (resolutionBuilder.length() > 0) { resolutionBuilder.insert(0, ", "); } resolutionBuilder.insert(0, "DD.CALENDAR_DAY_NUMBER"); case WEEK: if (resolutionBuilder.length() > 0) { resolutionBuilder.insert(0, ", "); } resolutionBuilder.insert(0, "DD.CALENDAR_WEEK_NUMBER"); case MONTH: if (resolutionBuilder.length() > 0) { resolutionBuilder.insert(0, ", "); } resolutionBuilder.insert(0, "DD.CALENDAR_MONTH_NUMBER"); case YEAR: if (resolutionBuilder.length() > 0) { resolutionBuilder.insert(0, ", "); } resolutionBuilder.insert(0, "DD.CALENDAR_YEAR_NUMBER"); } return resolutionBuilder.toString(); }
From source file:net.triptech.metahive.model.Definition.java
/** * Find the definitions that could be potentially related to the supplied definition. * * @param definition the definition/* w w w .j av a 2 s.c o m*/ * @return the list */ public static List<Definition> findPotentialRelatedDefinitions(final Definition definition) { List<Definition> relatedDefinitions = new ArrayList<Definition>(); HashMap<String, Object> variables = new HashMap<String, Object>(); StringBuilder sql = new StringBuilder(); if (definition != null) { StringBuilder where = new StringBuilder(); List<Definition> defs = new ArrayList<Definition>(); if (definition.getDefinitionType() == DefinitionType.CALCULATED) { defs = definition.getCalculatedDefinitions(); } if (definition.getDefinitionType() == DefinitionType.SUMMARY) { defs = definition.getSummarisedDefinitions(); } for (Definition def : defs) { if (where.length() > 0) { where.append(" AND "); } where.append("d.id != "); where.append(def.getId()); } if (where.length() > 0) { where.insert(0, "("); where.append(")"); } if (definition.getDefinitionType() == DefinitionType.CALCULATED) { if (where.length() > 0) { where.append(" AND "); } where.append("(d.dataType = :dataType1 OR d.dataType = :dataType2"); where.append(" OR d.dataType = :dataType3)"); variables.put("dataType1", DataType.TYPE_CURRENCY); variables.put("dataType2", DataType.TYPE_NUMBER); variables.put("dataType3", DataType.TYPE_PERCENTAGE); } if (definition.getDefinitionType() == DefinitionType.SUMMARY) { if (where.length() > 0) { where.append(" AND "); } where.append("d.definitionType != :definitionType"); where.append(" AND d.summaryDefinition is null"); variables.put("definitionType", DefinitionType.SUMMARY); } if (definition.getDefinitionType() == DefinitionType.CALCULATED || definition.getDefinitionType() == DefinitionType.SUMMARY) { // Load all of the definitions, less the definitions already associated sql.append("SELECT d FROM Definition d"); if (where.length() > 0) { sql.append(" WHERE "); sql.append(where.toString()); } sql.append(" ORDER BY d.name ASC"); } } if (sql.length() > 0) { TypedQuery<Definition> q = entityManager().createQuery(sql.toString(), Definition.class); for (String variable : variables.keySet()) { q.setParameter(variable, variables.get(variable)); } relatedDefinitions = q.getResultList(); } return relatedDefinitions; }
From source file:de.matzefratze123.heavyspleef.core.flag.FlagRegistry.java
public void registerFlag(Class<? extends AbstractFlag<?>> clazz) { Validate.notNull(clazz, "clazz cannot be null"); Validate.isTrue(!registeredFlagsMap.containsValue(clazz), "Cannot register flag twice"); /* Check if the class provides the required Flag annotation */ Validate.isTrue(clazz.isAnnotationPresent(Flag.class), "Flag-Class must be annotated with the @Flag annotation"); Flag flagAnnotation = clazz.getAnnotation(Flag.class); String name = flagAnnotation.name(); Validate.isTrue(!name.isEmpty(),/*from www . j a v a 2 s . c om*/ "name() of annotation of flag for class " + clazz.getCanonicalName() + " cannot be empty"); /* Generate a path */ StringBuilder pathBuilder = new StringBuilder(); Flag parentFlagData = flagAnnotation; do { pathBuilder.insert(0, parentFlagData.name()); Class<? extends AbstractFlag<?>> parentFlagClass = parentFlagData.parent(); parentFlagData = parentFlagClass.getAnnotation(Flag.class); if (parentFlagData != null && parentFlagClass != NullFlag.class) { pathBuilder.insert(0, FLAG_PATH_SEPERATOR); } } while (parentFlagData != null); String path = pathBuilder.toString(); /* Check for name collides */ for (String flagPath : registeredFlagsMap.primaryKeySet()) { if (flagPath.equalsIgnoreCase(path)) { throw new IllegalArgumentException( "Flag " + clazz.getName() + " collides with " + registeredFlagsMap.get(flagPath).getName()); } } /* Check if the class can be instantiated */ try { Constructor<? extends AbstractFlag<?>> constructor = clazz.getDeclaredConstructor(); //Make the constructor accessible for future uses constructor.setAccessible(true); } catch (NoSuchMethodException | SecurityException e) { throw new IllegalArgumentException("Flag-Class must provide an empty constructor"); } HookManager hookManager = heavySpleef.getHookManager(); boolean allHooksPresent = true; for (HookReference ref : flagAnnotation.depend()) { if (!hookManager.getHook(ref).isProvided()) { allHooksPresent = false; } } if (allHooksPresent) { for (Method method : clazz.getDeclaredMethods()) { if (!method.isAnnotationPresent(FlagInit.class)) { continue; } if ((method.getModifiers() & Modifier.STATIC) == 0) { throw new IllegalArgumentException("Flag initialization method " + method.getName() + " in type " + clazz.getCanonicalName() + " is not declared as static"); } queuedInitMethods.add(method); } if (flagAnnotation.hasCommands()) { CommandManager manager = heavySpleef.getCommandManager(); manager.registerSpleefCommands(clazz); } } registeredFlagsMap.put(path, flagAnnotation, clazz); }
From source file:bammerbom.ultimatecore.bukkit.configuration.YamlConfiguration.java
@Override protected String buildHeader() { String header = options().header(); if (options().copyHeader()) { MemoryConfiguration def = getDefaults(); if ((def != null) && (def instanceof FileConfiguration)) { FileConfiguration filedefaults = (FileConfiguration) def; String defaultsHeader = filedefaults.buildHeader(); if ((defaultsHeader != null) && (defaultsHeader.length() > 0)) { return defaultsHeader; }//from www . jav a2 s. c o m } } if (header == null) { return ""; } StringBuilder builder = new StringBuilder(); String[] lines = header.split("\r?\n", -1); boolean startedHeader = false; for (int i = lines.length - 1; i >= 0; i--) { builder.insert(0, "\n"); if ((startedHeader) || (lines[i].length() != 0)) { builder.insert(0, lines[i]); builder.insert(0, COMMENT_PREFIX); startedHeader = true; } } return builder.toString(); }