protected String getRallyXML(String apiUrl) throws Exception { String responseXML = ""; DefaultHttpClient httpClient = new DefaultHttpClient(); Base64 base64 = new Base64(); String encodeString = new String(base64.encode((rallyApiHttpUsername + ":" + rallyApiHttpPassword).getBytes())); HttpGet httpGet = new HttpGet(apiUrl); httpGet.addHeader("Authorization", "Basic " + encodeString); HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); if (entity != null) { InputStreamReader reader = new InputStreamReader(entity.getContent()); BufferedReader br = new BufferedReader(reader); StringBuilder sb = new StringBuilder(); String line = ""; while ((line = br.readLine()) != null) { sb.append(line); } responseXML = sb.toString(); } log.debug("responseXML=" + responseXML); return responseXML; }
@Override protected Transferable createTransferable(JComponent c) { JTextPane aTextPane = (JTextPane) c; HTMLEditorKit kit = ((HTMLEditorKit) aTextPane.getEditorKit()); StyledDocument sdoc = aTextPane.getStyledDocument(); int sel_start = aTextPane.getSelectionStart(); int sel_end = aTextPane.getSelectionEnd(); int i = sel_start; StringBuilder output = new StringBuilder(); while (i < sel_end) { Element e = sdoc.getCharacterElement(i); Object nameAttr = e.getAttributes().getAttribute(StyleConstants.NameAttribute); int start = e.getStartOffset(), end = e.getEndOffset(); if (nameAttr == HTML.Tag.BR) { output.append("\n"); } else if (nameAttr == HTML.Tag.CONTENT) { if (start < sel_start) { start = sel_start; } if (end > sel_end) { end = sel_end; } try { String str = sdoc.getText(start, end - start); output.append(str); } catch (BadLocationException ble) { Debug.error(me + "Copy-paste problem!\n%s", ble.getMessage()); } } i = end; } return new StringSelection(output.toString()); }
/** * Returns a map with variable bindings. * * @param opts main options * @return bindings */ public static HashMap<String, String> bindings(final MainOptions opts) { final HashMap<String, String> bindings = new HashMap<>(); final String bind = opts.get(MainOptions.BINDINGS).trim(); final StringBuilder key = new StringBuilder(); final StringBuilder val = new StringBuilder(); boolean first = true; final int sl = bind.length(); for (int s = 0; s < sl; s++) { final char ch = bind.charAt(s); if (first) { if (ch == '=') { first = false; } else { key.append(ch); } } else { if (ch == ',') { if (s + 1 == sl || bind.charAt(s + 1) != ',') { bindings.put(key.toString().trim(), val.toString()); key.setLength(0); val.setLength(0); first = true; continue; } // literal commas are escaped by a second comma s++; } val.append(ch); } } if (key.length() != 0) bindings.put(key.toString().trim(), val.toString()); return bindings; }
public String _range(String args[]) { verifyCommand(args, _rangeHelp, _rangePattern, 2, 3); Version version = null; if (args.length >= 3) version = new Version(args[2]); else { String v = domain.getProperty("@"); if (v == null) return null; version = new Version(v); } String spec = args[1]; Matcher m = RANGE_MASK.matcher(spec); m.matches(); String floor = m.group(1); String floorMask = m.group(2); String ceilingMask = m.group(3); String ceiling = m.group(4); String left = version(version, floorMask); String right = version(version, ceilingMask); StringBuilder sb = new StringBuilder(); sb.append(floor); sb.append(left); sb.append(","); sb.append(right); sb.append(ceiling); String s = sb.toString(); VersionRange vr = new VersionRange(s); if (!(vr.includes(vr.getHigh()) || vr.includes(vr.getLow()))) { domain.error( "${range} macro created an invalid range %s from %s and mask %s", s, version, spec); } return sb.toString(); }
/** * Convert all special tags in a string to local URL (e.g [sprite: NameOfPony] => * file://path/to/local/sprite.png); allowed special tags are: sprite, type, movetype * * @return The converted string */ public static String toLocalURL(final String msg) { StringBuilder converted = new StringBuilder(); boolean parsingTag = false; boolean inTagName = true; StringBuilder tagName = new StringBuilder(10); StringBuilder tagArg = new StringBuilder(30); for (int i = 0; i < msg.length(); ++i) { char c = msg.charAt(i); switch (c) { case '[': if (!parsingTag) { parsingTag = true; } else { if (inTagName) tagName.append(c); else tagArg.append(c); } break; case ']': if (parsingTag) { parsingTag = false; converted.append( convertLocalURLTag(tagName.toString().trim(), tagArg.toString().trim())); tagName.setLength(0); tagArg.setLength(0); inTagName = true; } else { converted.append(c); } break; case ':': if (parsingTag) { if (inTagName) inTagName = false; else tagArg.append(c); } else { converted.append(c); } break; default: if (parsingTag) { if (inTagName) tagName.append(c); else tagArg.append(c); } else { converted.append(c); } } } return converted.toString(); }
public String getCoordinates(RevisionRef r) { StringBuilder sb = new StringBuilder(r.groupId).append(":").append(r.artifactId).append(":"); if (r.classifier != null) sb.append(r.classifier).append("@"); sb.append(r.version); return sb.toString(); }
/** * Removes comments from the specified string and returns the first characters of a query. * * @param qu query string * @param max maximum length of string to return * @return result */ public static String removeComments(final String qu, final int max) { final StringBuilder sb = new StringBuilder(); int m = 0; boolean s = false; final int cl = qu.length(); for (int c = 0; c < cl && sb.length() < max; ++c) { final char ch = qu.charAt(c); if (ch == 0x0d) continue; if (ch == '(' && c + 1 < cl && qu.charAt(c + 1) == ':') { if (m == 0 && !s) { sb.append(' '); s = true; } ++m; ++c; } else if (m != 0 && ch == ':' && c + 1 < cl && qu.charAt(c + 1) == ')') { --m; ++c; } else if (m == 0) { if (ch > ' ') sb.append(ch); else if (!s) sb.append(' '); s = ch <= ' '; } } if (sb.length() >= max) sb.append("..."); return sb.toString().trim(); }
/** * If the outbound level is BINARY, convert the string field to binary, then pad to the left with * the appropriate number of zero bits to reach a number of bits specified by the bitLength * attribute of the TDT definition file. */ private void binaryPadding(Map<String, String> extraparams, Field tdtfield) { String fieldname = tdtfield.getName(); int reqbitlength = tdtfield.getBitLength(); String value; String binaryValue = fieldToBinary(tdtfield, extraparams); if (binaryValue.length() < reqbitlength) { int extraBitLength = reqbitlength - binaryValue.length(); StringBuilder zeroPaddedBinaryValue = new StringBuilder(""); for (int i = 0; i < extraBitLength; i++) { zeroPaddedBinaryValue.append("0"); } zeroPaddedBinaryValue.append(binaryValue); value = zeroPaddedBinaryValue.toString(); } else { if (binaryValue.length() > reqbitlength) throw new TDTException( "Binary value [" + binaryValue + "] for field " + fieldname + " exceeds maximum allowed " + reqbitlength + " bits. Decimal value was " + extraparams.get(fieldname)); value = binaryValue; } extraparams.put(fieldname, value); }
public static void verifyCommand( String args[], @SuppressWarnings("unused") String help, Pattern[] patterns, int low, int high) { String message = ""; if (args.length > high) { message = "too many arguments"; } else if (args.length < low) { message = "too few arguments"; } else { for (int i = 0; patterns != null && i < patterns.length && i < args.length; i++) { if (patterns[i] != null) { Matcher m = patterns[i].matcher(args[i]); if (!m.matches()) message += String.format( "Argument %s (%s) does not match %s%n", i, args[i], patterns[i].pattern()); } } } if (message.length() != 0) { StringBuilder sb = new StringBuilder(); String del = "${"; for (String arg : args) { sb.append(del); sb.append(arg); del = ";"; } sb.append("}, is not understood. "); sb.append(message); throw new IllegalArgumentException(sb.toString()); } }
private static String convert(List<List<Particle>> lists) { StringBuilder sb = new StringBuilder(); for (List<Particle> list : lists) { if (list.isEmpty()) sb.append('.'); else sb.append('X'); } return sb.toString(); }
private String blankSectionHeaders(String markup, StringBuffer context) { Pattern p = Pattern.compile("(={2,})([^=]+)\\1"); Matcher m = p.matcher(markup); int lastPos = 0; StringBuilder sb = new StringBuilder(); while (m.find()) { sb.append(markup.substring(lastPos, m.start())); sb.append(getSpaceString(m.group().length())); String title = m.group(2).trim(); if (!title.equalsIgnoreCase("see also") && !title.equalsIgnoreCase("external links") && !title.equalsIgnoreCase("references") && !title.equalsIgnoreCase("further reading")) context.append("\n").append(title); lastPos = m.end(); } sb.append(markup.substring(lastPos)); return sb.toString(); }
private static String expand(String str) { if (str == null) { return null; } StringBuilder result = new StringBuilder(); Pattern re = Pattern.compile("^(.*?)\\$\\{([^}]*)\\}(.*)"); while (true) { Matcher matcher = re.matcher(str); if (matcher.matches()) { result.append(matcher.group(1)); String property = matcher.group(2); if (property.equals("/")) { property = "file.separator"; } String value = System.getProperty(property); if (value != null) { result.append(value); } str = matcher.group(3); } else { result.append(str); break; } } return result.toString(); }
private String getAuthorizeUrl() { StringBuilder url = new StringBuilder(); url.append(this.service_.getAuthorizationEndpoint()); boolean hasQuery = url.toString().indexOf('?') != -1; url.append(hasQuery ? '&' : '?') .append("client_id=") .append(Utils.urlEncode(this.service_.getClientId())) .append("&redirect_uri=") .append(Utils.urlEncode(this.service_.getGenerateRedirectEndpoint())) .append("&scope=") .append(Utils.urlEncode(this.scope_)) .append("&response_type=code") .append("&state=") .append(Utils.urlEncode(this.oAuthState_)); return url.toString(); }
static String outputOf(Reader r) throws IOException { final StringBuilder sb = new StringBuilder(); final char[] buf = new char[1024]; int n; while ((n = r.read(buf)) > 0) sb.append(buf, 0, n); return sb.toString(); }
public String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != // ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); }
public static String dropNonLetters(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (Character.isLetter(c)) sb.append(c); } return sb.toString(); }
private String ns1() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b) && b != ' ')) { // when nextLine, sb.appendCodePoint(b); b = readByte(); } return sb.toString(); }
// todo: give options for document splitting. A line or the whole file or // sentence splitting as now public Iterator<List<IN>> getIterator(Reader r) { Tokenizer<IN> tokenizer = tokenizerFactory.getTokenizer(r); // PTBTokenizer.newPTBTokenizer(r, false, true); List<IN> words = new ArrayList<IN>(); IN previous = tokenFactory.makeToken(); StringBuilder prepend = new StringBuilder(); /* * This changes SGML tags into whitespace -- it should maybe be moved * elsewhere */ while (tokenizer.hasNext()) { IN w = tokenizer.next(); String word = w.get(CoreAnnotations.TextAnnotation.class); Matcher m = sgml.matcher(word); if (m.matches()) { String before = StringUtils.getNotNullString(w.get(CoreAnnotations.BeforeAnnotation.class)); String after = StringUtils.getNotNullString(w.get(CoreAnnotations.AfterAnnotation.class)); prepend.append(before).append(word); String previousTokenAfter = StringUtils.getNotNullString(previous.get(CoreAnnotations.AfterAnnotation.class)); previous.set(AfterAnnotation.class, previousTokenAfter + word + after); // previous.appendAfter(w.word() + w.after()); } else { String before = StringUtils.getNotNullString(w.get(CoreAnnotations.BeforeAnnotation.class)); if (prepend.length() > 0) { w.set(BeforeAnnotation.class, prepend.toString() + before); // w.prependBefore(prepend.toString()); prepend = new StringBuilder(); } words.add(w); previous = w; } } List<List<IN>> sentences = wts.process(words); String after = ""; IN last = null; for (List<IN> sentence : sentences) { int pos = 0; for (IN w : sentence) { w.set(PositionAnnotation.class, Integer.toString(pos)); after = StringUtils.getNotNullString(w.get(CoreAnnotations.AfterAnnotation.class)); w.remove(AfterAnnotation.class); last = w; } } if (last != null) { last.set(AfterAnnotation.class, after); } return sentences.iterator(); }
/** * Converts an upper case character string input into a binary string, using 5-bit compaction of * each ASCII byte */ private String uppercasefive2bin(String uppercasefive) { String binary; StringBuilder buffer = new StringBuilder(""); int len = uppercasefive.length(); byte[] bytes = uppercasefive.getBytes(); for (int i = 0; i < len; i++) { buffer.append(padBinary(dec2bin(Integer.toString(bytes[i] % 32)), 8).substring(3, 8)); } binary = buffer.toString(); return binary; }
/** * Converts a binary string input into a character string output, assuming that 5-bit compaction * was used */ private String bin2uppercasefive(String binary) { String uppercasefive; StringBuilder buffer = new StringBuilder(""); int len = binary.length(); for (int i = 0; i < len; i += 5) { int j = Integer.parseInt(bin2dec(padBinary(binary.substring(i, i + 5), 8))); buffer.append((char) (j + 64)); } uppercasefive = buffer.toString(); return uppercasefive; }
/** Converts a binary string input into a byte string, using 8-bits per character byte */ private String bytestring2bin(String bytestring) { String binary; StringBuilder buffer = new StringBuilder(""); int len = bytestring.length(); byte[] bytes = bytestring.getBytes(); for (int i = 0; i < len; i++) { buffer.append(padBinary(dec2bin(Integer.toString(bytes[i])), 8)); } binary = buffer.toString(); return binary; }
/** Converts a byte string input into a binary string, using 8-bits per character byte */ private String bin2bytestring(String binary) { String bytestring; StringBuilder buffer = new StringBuilder(""); int len = binary.length(); for (int i = 0; i < len; i += 8) { int j = Integer.parseInt(bin2dec(padBinary(binary.substring(i, i + 8), 8))); buffer.append((char) j); } bytestring = buffer.toString(); return bytestring; }
public String toString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < urls.size(); i++) { if (i > 0) { sb.append("|"); } sb.append( String.format("%d,%d=\"%s\"", locations.get(i)[0], locations.get(i)[1], urls.get(i))); } return sb.toString(); }
/** * Converts a binary string input into an ASCII string output, assuming that 7-bit compaction was * used */ private String bin2asciiseven(String binary) { String asciiseven; StringBuilder buffer = new StringBuilder(""); int len = binary.length(); for (int i = 0; i < len; i += 7) { int j = Integer.parseInt(bin2dec(padBinary(binary.substring(i, i + 7), 8))); buffer.append((char) j); } asciiseven = buffer.toString(); return asciiseven; }
/** * Return a string that describes the statistics for the top n entries, sorted by descending * order of total time spent dealing with the query. This will always include the totals entry * in the first position. * * @param n the desired number of entries to describe * @return a string describing the statistics for the top n entries */ public synchronized String toStringTop(int n) { StringBuilder out = new StringBuilder(); List<Entry> list = entries(); if (list.isEmpty()) return "<no queries executed>"; Collections.sort(list, TOTAL_TIME_DESCENDING); int maxCountLength = COUNT_FORMAT.format(list.get(0).numQueries).length(); double totalDuration = list.get(0).queryTime; for (Entry entry : list.subList(0, Math.min(n, list.size()))) out.append(entry.toString(maxCountLength, totalDuration)).append('\n'); return out.toString(); }
protected void selected(CharPos start, CharPos end) { StringBuilder buf = new StringBuilder(); synchronized (msgs) { boolean sel = false; for (Message msg : msgs) { if (!(msg.text() instanceof RichText)) continue; RichText rt = (RichText) msg.text(); RichText.Part part = null; if (sel) { part = rt.parts; } else if (msg == start.msg) { sel = true; for (part = rt.parts; part != null; part = part.next) { if (part == start.part) break; } } if (sel) { for (; part != null; part = part.next) { if (!(part instanceof RichText.TextPart)) continue; RichText.TextPart tp = (RichText.TextPart) part; CharacterIterator iter = tp.ti(); int sch; if (tp == start.part) sch = tp.start + start.ch.getInsertionIndex(); else sch = tp.start; int ech; if (tp == end.part) ech = tp.start + end.ch.getInsertionIndex(); else ech = tp.end; for (int i = sch; i < ech; i++) buf.append(iter.setIndex(i)); if (part == end.part) { sel = false; break; } buf.append(' '); } if (sel) buf.append('\n'); } if (msg == end.msg) break; } } Clipboard cl; if ((cl = java.awt.Toolkit.getDefaultToolkit().getSystemSelection()) == null) cl = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard(); try { final CharPos ownsel = selstart; cl.setContents( new StringSelection(buf.toString()), new ClipboardOwner() { public void lostOwnership(Clipboard cl, Transferable tr) { if (selstart == ownsel) selstart = selend = null; } }); } catch (IllegalStateException e) { } }
/** * Converts an alphanumeric string input into a binary string, using 6-bit compaction of each * ASCII byte */ private String alphanumsix2bin(String alphanumsix) { String binary; StringBuilder buffer = new StringBuilder(""); int len = alphanumsix.length(); byte[] bytes = alphanumsix.getBytes(); for (int i = 0; i < len; i++) { buffer.append(padBinary(dec2bin(Integer.toString(bytes[i] % 64)), 8).substring(2, 8)); } binary = buffer.toString(); return binary; }
/** * Converts an ASCII string input into a binary string, using 7-bit compaction of each ASCII byte */ private String asciiseven2bin(String asciiseven) { String binary; StringBuilder buffer = new StringBuilder(""); int len = asciiseven.length(); byte[] bytes = asciiseven.getBytes(); for (int i = 0; i < len; i++) { buffer.append(padBinary(dec2bin(Integer.toString(bytes[i] % 128)), 8).substring(1, 8)); } binary = buffer.toString(); return binary; }
@Nonnull private static String getRelativeSubPathToOutputDir(@Nonnull String filePath) { StringBuilder cssRelPath = new StringBuilder(); int n = PATH_SEPARATOR.split(filePath).length; for (int i = 1; i < n; i++) { cssRelPath.append("../"); } return cssRelPath.toString(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); String del = "["; for (Link r = this; r != null; r = r.previous) { sb.append(del); sb.append(r.key); del = ","; } sb.append("]"); return sb.toString(); }