List of usage examples for java.lang StringBuilder insert
@Override public StringBuilder insert(int offset, double d)
From source file:chat.viska.xmpp.NettyTcpSession.java
private Document preprocessInboundXml(final String xml) throws SAXException { final StringBuilder builder = new StringBuilder(xml); final String openingPrefixBlock = '<' + serverStreamPrefix + ':'; final String closingPrefixBlock = "</" + serverStreamPrefix + ':'; final int openingPrefixBlockIdx = builder.indexOf(openingPrefixBlock); final int firstXmlnsIdx = builder.indexOf(" xmlns=") + 1; if (openingPrefixBlockIdx == 0) { // Remove <stream: prefix and add namespace block builder.delete(1, 1 + serverStreamPrefix.length() + 1); final int closingPrefixBlockIdx = builder.indexOf(closingPrefixBlock); builder.delete(closingPrefixBlockIdx + 2, closingPrefixBlockIdx + 2 + serverStreamPrefix.length() + 1); builder.insert(builder.indexOf(">"), String.format(" xmlns=\"%1s\"", CommonXmlns.STREAM_HEADER)); } else if (firstXmlnsIdx < 0 || firstXmlnsIdx > builder.indexOf(">")) { // No xmlns for the root, which means a stanza builder.insert(builder.indexOf(">"), String.format(" xmlns=\"%1s\"", CommonXmlns.STANZA_CLIENT)); }/*from w w w . ja va 2 s . c o m*/ return DomUtils.readDocument(builder.toString()); }
From source file:ch.mlutz.plugins.t4e.tapestry.TapestryModule.java
private ICompilationUnit findRelatedUnitForHtml(IFile currentFile) throws CoreException { // try to find by component specification IFile specificationFile = TapestryTools.findComponentSpecificationforHtmlFile(currentFile); ICompilationUnit compilationUnit;/* w ww. j av a 2 s . c o m*/ if (specificationFile != null) { compilationUnit = findRelatedUnit(specificationFile); if (compilationUnit != null) { // create component and add to index TapestryHtmlElement component = new TapestryHtmlElement(this, ElementType.COMPONENT, currentFile, specificationFile, compilationUnit); add(component); return compilationUnit; } } // then try to find by page specification specificationFile = TapestryTools.findPageSpecificationforHtmlFile(currentFile); if (specificationFile != null) { compilationUnit = findRelatedUnit(specificationFile); if (compilationUnit != null) { // create page and add to index TapestryHtmlElement page = new TapestryHtmlElement(this, ElementType.PAGE, currentFile, specificationFile, compilationUnit); add(page); return compilationUnit; } } // at last, try directly and assemble fully qualified class name String javaFileName = extractFileBase(currentFile.getName()) + ".java"; // go up until we find a folder named webapp or the project; every folder // on the way up contributes to the packageSuffix StringBuilder sb = new StringBuilder(); IContainer parent = currentFile.getParent(); while (!WEBAPP_FOLDER_NAME.equals(parent.getName().toLowerCase()) && parent.getType() != IResource.PROJECT) { sb.insert(0, parent.getName()); sb.insert(0, '.'); parent = parent.getParent(); } String packageSuffix = sb.toString(); // loop through all page packages Set<String> pageClassPackages = appSpecification.getPageClassPackages(); if (pageClassPackages != null) { compilationUnit = findCompilationUnitInClassPackages(getProject(), pageClassPackages, packageSuffix, javaFileName); // create page and add to index TapestryHtmlElement page = new TapestryHtmlElement(this, ElementType.PAGE, currentFile, specificationFile, compilationUnit); add(page); return compilationUnit; } // resource is null here Set<String> componentClassPackages = appSpecification.getComponentClassPackages(); if (componentClassPackages != null) { compilationUnit = findCompilationUnitInClassPackages(getProject(), componentClassPackages, packageSuffix, javaFileName); // create component and add to index TapestryHtmlElement component = new TapestryHtmlElement(this, ElementType.COMPONENT, currentFile, specificationFile, compilationUnit); add(component); return compilationUnit; } return null; }
From source file:fi.cosky.sdk.API.java
private String readDataFromConnection(HttpURLConnection connection) { InputStream is = null;/* ww w . j a va2 s . c o m*/ BufferedReader br = null; StringBuilder sb = null; try { is = connection.getInputStream(); br = new BufferedReader(new InputStreamReader(is)); sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } String eTag = null; if ((eTag = connection.getHeaderField("ETag")) != null) { sb.insert(sb.lastIndexOf("}"), ",\"VersionNumber\":" + eTag + ""); } } catch (IOException e) { System.out.println("Could not read data from connection"); } return sb.toString(); }
From source file:de.schildbach.wallet.service.BlockchainServiceImpl.java
private void notifyCoinsReceived(final Address from, final BigInteger amount) { if (notificationCount == 1) nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); notificationCount++;/*from w w w .j av a2 s . c o m*/ notificationAccumulatedAmount = notificationAccumulatedAmount.add(amount); if (from != null && !notificationAddresses.contains(from)) notificationAddresses.add(from); final int precision = Integer.parseInt( prefs.getString(Constants.PREFS_KEY_BTC_PRECISION, Integer.toString(Constants.BTC_PRECISION))); final String tickerMsg = getString(R.string.notification_coins_received_msg, GenericUtils.formatValue(amount, precision)) + Constants.NETWORK_SUFFIX; final String msg = getString(R.string.notification_coins_received_msg, GenericUtils.formatValue(notificationAccumulatedAmount, precision)) + Constants.NETWORK_SUFFIX; final StringBuilder text = new StringBuilder(); for (final Address address : notificationAddresses) { if (text.length() > 0) text.append(", "); text.append(address.toString()); } if (text.length() == 0) text.append("unknown"); text.insert(0, "From "); final NotificationCompat.Builder notification = new NotificationCompat.Builder(this); notification.setSmallIcon(R.drawable.stat_notify_received); notification.setTicker(tickerMsg); notification.setContentTitle(msg); notification.setContentText(text); notification .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, WalletActivity.class), 0)); notification.setNumber(notificationCount == 1 ? 0 : notificationCount); notification.setWhen(System.currentTimeMillis()); notification.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received)); nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notification.getNotification()); }
From source file:eu.planets_project.pp.plato.evaluation.evaluators.FITSEvaluator.java
private Value preservedValues(HashMap<String, String> sampleMetadata, HashMap<String, String> resultMetadata, Scale scale) {//from w w w . j a v a 2 s.c om int numMissing = 0; int numChanged = 0; BooleanValue v = (BooleanValue) scale.createValue(); StringBuilder comment = new StringBuilder(); for (String key : sampleMetadata.keySet()) { String sampleValue = sampleMetadata.get(key); String resultValue = resultMetadata.get(key); if (resultValue == null) { numMissing++; comment.append(" - " + key + "\n"); } else if (!resultValue.equals(sampleValue)) { numChanged++; comment.append(" ~ " + key + ": sample=" + sampleValue + ", result=" + resultValue + "\n"); } } if ((numChanged == 0) && (numMissing == 0)) { v.bool(true); v.setComment("result contains complete metadata of sample"); } else { v.bool(false); comment.insert(0, "following differences found: (- .. missing, ~ .. altered):\n"); v.setComment(comment.toString()); } return v; }
From source file:com.feathercoin.wallet.feathercoin.service.BlockchainServiceImpl.java
private void notifyCoinsReceived(final Address from, final BigInteger amount) { if (notificationCount == 1) nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); notificationCount++;/*ww w . j a v a2s . c om*/ notificationAccumulatedAmount = notificationAccumulatedAmount.add(amount); if (from != null && !notificationAddresses.contains(from)) notificationAddresses.add(from); final int precision = Integer.parseInt( prefs.getString(Constants.PREFS_KEY_FTC_PRECISION, Integer.toString(Constants.FTC_PRECISION))); final String tickerMsg = getString(R.string.notification_coins_received_msg, WalletUtils.formatValue(amount, precision)) + Constants.NETWORK_SUFFIX; final String msg = getString(R.string.notification_coins_received_msg, WalletUtils.formatValue(notificationAccumulatedAmount, precision)) + Constants.NETWORK_SUFFIX; final StringBuilder text = new StringBuilder(); for (final Address address : notificationAddresses) { if (text.length() > 0) text.append(", "); text.append(address.toString()); } if (text.length() == 0) text.append("unknown"); text.insert(0, "From "); final NotificationCompat.Builder notification = new NotificationCompat.Builder(this); notification.setSmallIcon(R.drawable.stat_notify_received); notification.setTicker(tickerMsg); notification.setContentTitle(msg); notification.setContentText(text); notification .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, WalletActivity.class), 0)); notification.setNumber(notificationCount == 1 ? 0 : notificationCount); notification.setWhen(System.currentTimeMillis()); notification.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received)); nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notification.getNotification()); }
From source file:de.schildbach.wallet.digitalcoin.service.BlockchainServiceImpl.java
private void notifyCoinsReceived(final Address from, final BigInteger amount) { if (notificationCount == 1) nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); notificationCount++;// w w w. j av a 2s .c om notificationAccumulatedAmount = notificationAccumulatedAmount.add(amount); if (from != null && !notificationAddresses.contains(from)) notificationAddresses.add(from); final int precision = Integer.parseInt( prefs.getString(Constants.PREFS_KEY_WDC_PRECISION, Integer.toString(Constants.WDC_PRECISION))); final String tickerMsg = getString(R.string.notification_coins_received_msg, WalletUtils.formatValue(amount, precision)) + Constants.NETWORK_SUFFIX; final String msg = getString(R.string.notification_coins_received_msg, WalletUtils.formatValue(notificationAccumulatedAmount, precision)) + Constants.NETWORK_SUFFIX; final StringBuilder text = new StringBuilder(); for (final Address address : notificationAddresses) { if (text.length() > 0) text.append(", "); text.append(address.toString()); } if (text.length() == 0) text.append("unknown"); text.insert(0, "From "); final NotificationCompat.Builder notification = new NotificationCompat.Builder(this); notification.setSmallIcon(R.drawable.stat_notify_received); notification.setTicker(tickerMsg); notification.setContentTitle(msg); notification.setContentText(text); notification .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, WalletActivity.class), 0)); notification.setNumber(notificationCount == 1 ? 0 : notificationCount); notification.setWhen(System.currentTimeMillis()); notification.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received)); nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notification.getNotification()); }
From source file:me.doshou.admin.maintain.staticresource.web.controller.StaticResourceVersionController.java
@RequestMapping("batchCompress") @ResponseBody/* w w w.j ava 2s.c o m*/ public String batchCompress(@RequestParam("fileNames[]") String[] fileNames, @RequestParam("contents[]") String[] contents) throws IOException { String rootRealPath = sc.getRealPath("/WEB-INF"); String versionedResourceRealPath = sc.getRealPath(versionedResourcePath); StringBuilder success = new StringBuilder(); StringBuilder error = new StringBuilder(); for (int i = 0, l = fileNames.length; i < l; i++) { try { String fileName = fileNames[i]; String content = contents[i]; String minFilePath = compressStaticResource(rootRealPath, versionedResourceRealPath + fileName, content); success.append("?" + minFilePath + "<br/>"); } catch (Exception e) { error.append("" + e.getMessage() + "<br/>"); } } return success.insert(0, "?<br/>").append("<br/><br/>").append(error) .toString(); }
From source file:de.schildbach.wallet.goldcoin.service.BlockchainServiceImpl.java
private void notifyCoinsReceived(final Address from, final BigInteger amount) { if (notificationCount == 1) nm.cancel(NOTIFICATION_ID_COINS_RECEIVED); notificationCount++;//from w w w.j av a2 s .c om notificationAccumulatedAmount = notificationAccumulatedAmount.add(amount); if (from != null && !notificationAddresses.contains(from)) notificationAddresses.add(from); final int precision = Integer.parseInt( prefs.getString(Constants.PREFS_KEY_GLD_PRECISION, Integer.toString(Constants.GLD_PRECISION))); final String tickerMsg = getString(R.string.notification_coins_received_msg, WalletUtils.formatValue(amount, precision)) + Constants.NETWORK_SUFFIX; final String msg = getString(R.string.notification_coins_received_msg, WalletUtils.formatValue(notificationAccumulatedAmount, precision)) + Constants.NETWORK_SUFFIX; final StringBuilder text = new StringBuilder(); for (final Address address : notificationAddresses) { if (text.length() > 0) text.append(", "); text.append(address.toString()); } if (text.length() == 0) text.append("unknown"); text.insert(0, "From "); final NotificationCompat.Builder notification = new NotificationCompat.Builder(this); notification.setSmallIcon(R.drawable.stat_notify_received); notification.setTicker(tickerMsg); notification.setContentTitle(msg); notification.setContentText(text); notification .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, WalletActivity.class), 0)); notification.setNumber(notificationCount == 1 ? 0 : notificationCount); notification.setWhen(System.currentTimeMillis()); notification.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received)); nm.notify(NOTIFICATION_ID_COINS_RECEIVED, notification.getNotification()); }
From source file:loggerplusplus.LogEntry.java
public void processResponse(IHttpRequestResponse requestResponse) { if (!isImported) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date responseDate = new Date(); this.responseTime = sdf.format(responseDate); try {//from www .ja v a 2 s. c o m Date requestDate = sdf.parse(this.requestTime); this.requestResponseDelay = formatDelay(responseDate.getTime() - requestDate.getTime()); } catch (ParseException e) { } } //Finalise request,response by saving to temp file and clearing from memory. if (requestResponse instanceof IHttpRequestResponsePersisted) { this.requestResponse = requestResponse; } else { this.requestResponse = LoggerPlusPlus.getCallbacks().saveBuffersToTempFiles(requestResponse); } IResponseInfo tempAnalyzedResp = LoggerPlusPlus.getCallbacks().getHelpers() .analyzeResponse(requestResponse.getResponse()); String strFullResponse = new String(requestResponse.getResponse()); this.responseBodyOffset = tempAnalyzedResp.getBodyOffset(); this.responseLength = requestResponse.getResponse().length - responseBodyOffset; LogTable logTable = LoggerPlusPlus.getInstance().getLogTable(); List<String> lstFullResponseHeader = tempAnalyzedResp.getHeaders(); responseHeaders = StringUtils.join(lstFullResponseHeader, ", "); this.status = tempAnalyzedResp.getStatusCode(); if (logTable.getColumnModel().isColumnEnabled("MimeType")) // This is good to increase the speed when it is time consuming this.responseMimeType = tempAnalyzedResp.getStatedMimeType(); if (logTable.getColumnModel().isColumnEnabled("InferredType")) // This is good to increase the speed when it is time consuming this.responseInferredMimeType = tempAnalyzedResp.getInferredMimeType(); if (logTable.getColumnModel().isColumnEnabled("newCookies")) // This is good to increase the speed when it is time consuming for (ICookie cookieItem : tempAnalyzedResp.getCookies()) { this.newCookies += cookieItem.getName() + "=" + cookieItem.getValue() + "; "; } this.hasSetCookies = !newCookies.isEmpty(); if (logTable.getColumnModel().isColumnEnabled("responseContentType")) { // This is good to increase the speed when it is time consuming for (String item : lstFullResponseHeader) { item = item.toLowerCase(); if (item.startsWith("content-type: ")) { String[] temp = item.split("content-type:\\s", 2); if (temp.length > 0) this.responseContentType = temp[1]; } } } Pattern titlePattern = Pattern.compile("(?<=<title>)(.)+(?=</title>)"); Matcher titleMatcher = titlePattern.matcher(strFullResponse); if (titleMatcher.find()) { this.title = titleMatcher.group(1); } // RegEx processing for responses - should be available only when we have a RegEx rule! // There are 5 RegEx rule for requests for (int i = 0; i < 5; i++) { String regexVarName = "regex" + (i + 1) + "Resp"; if (logTable.getColumnModel().isColumnEnabled(regexVarName)) { // so this rule is enabled! // check to see if the RegEx is not empty LogTableColumn regexColumn = logTable.getColumnModel().getColumnByName(regexVarName); String regexString = regexColumn.getRegExData().getRegExString(); if (!regexString.isEmpty()) { // now we can process it safely! Pattern p = null; try { if (regexColumn.getRegExData().isRegExCaseSensitive()) p = Pattern.compile(regexString); else p = Pattern.compile(regexString, Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(strFullResponse); StringBuilder allMatches = new StringBuilder(); int counter = 1; while (m.find()) { if (counter == 2) { allMatches.insert(0, ""); allMatches.append(""); } if (counter > 1) { allMatches.append("" + m.group() + ""); } else { allMatches.append(m.group()); } counter++; } this.regexAllResp[i] = allMatches.toString(); } catch (Exception e) { LoggerPlusPlus.getCallbacks().printError("Error in regular expression: " + regexString); } } } } if (!logTable.getColumnModel().isColumnEnabled("response") && !logTable.getColumnModel().isColumnEnabled("request")) { this.requestResponse = null; } this.complete = true; }