public String toString() { StringBuffer sb = new StringBuffer(url.length() + 17); sb.append("[MyMockCachedUrl: "); sb.append(url); sb.append("]"); return sb.toString(); }
public static String replaceStringNew(String line, String oldstr, String newstr) { StringBuffer sb = null; int oldLen = oldstr.length(); if (oldLen == 0) { return line; } if (oldLen == newstr.length()) { if (oldstr.equals(newstr)) { return line; } sb = new StringBuffer(line); int prevIdx = 0; while ((prevIdx = line.indexOf(oldstr, prevIdx)) >= 0) { sb.replace(prevIdx, prevIdx + oldLen, newstr); prevIdx += oldLen; } } else { int lineLen = line.length(); sb = new StringBuffer(lineLen); int oldIdx = 0; int thisIdx; while ((thisIdx = line.indexOf(oldstr, oldIdx)) >= 0) { for (int ix = oldIdx; ix < thisIdx; ix++) { sb.append(line.charAt(ix)); } sb.append(newstr); oldIdx = thisIdx + oldLen; } for (int ix = oldIdx; ix < lineLen; ix++) { sb.append(line.charAt(ix)); } } return sb.toString(); }
public static String replaceStringOld(String line, String oldstr, String newstr) { if (oldstr.compareTo(newstr) == 0) { return line; } StringBuffer sb = null; if (oldstr.length() == newstr.length()) { sb = new StringBuffer(line); int lastIdx = line.indexOf(oldstr); if (lastIdx >= 0) { do { sb.replace(lastIdx, lastIdx + newstr.length(), newstr); } while ((lastIdx = line.indexOf(oldstr, lastIdx + 1)) >= 0); } } else { sb = new StringBuffer(); int oldStrIdx = 0; int lastIdx = line.indexOf(oldstr); if (lastIdx >= 0) { do { for (int ix = oldStrIdx; ix < lastIdx; ix++) { sb.append(line.charAt(ix)); } sb.append(newstr); oldStrIdx = lastIdx + oldstr.length(); } while ((lastIdx = line.indexOf(oldstr, lastIdx + 1)) >= 0); } for (int ix = oldStrIdx; ix < line.length(); ix++) { sb.append(line.charAt(ix)); } } return sb.toString(); }
private String makeContent(String url, String openTag, String closeTag) { StringBuffer sb = new StringBuffer(100); sb.append("<html><head><title>Test</title></head><body>"); sb.append(openTag); sb.append(url); sb.append(">"); sb.append(closeTag); sb.append("</body></html>"); return sb.toString(); }
private String mkStr(char kar, int num) { StringBuffer sb = new StringBuffer(num); for (int ix = 0; ix < num; ix++) { sb.append(kar); } return sb.toString(); }
public static String replaceString2(String line, String oldstr, String newstr) { int oldLen = oldstr.length(); if (oldLen == 0 || oldstr.equals(newstr)) { return line; } int lineLen = line.length(); StringBuffer sb = new StringBuffer(lineLen + 10); int oldIdx = 0; int thisIdx; while ((thisIdx = line.indexOf(oldstr, oldIdx)) >= 0) { for (int ix = oldIdx; ix < thisIdx; ix++) { sb.append(line.charAt(ix)); } sb.append(newstr); oldIdx = thisIdx + oldLen; } for (int ix = oldIdx; ix < lineLen; ix++) { sb.append(line.charAt(ix)); } return sb.toString(); }
public static void timeOne(int btwnLen, int oldLen, int newLen, int rpt) { String os = longString.substring(0, oldLen); String ns = longString.substring(1, newLen + 1); String btwn = xString.substring(0, btwnLen); StringBuffer sb = new StringBuffer(); for (int ix = 0; ix < rpt; ix++) { sb.append(os); sb.append(btwn); } String s = sb.toString(); System.out.print( s.length() + " char string, rep " + rpt + " copies of " + oldLen + " chars with " + newLen + " chars"); // System.out.println(s+" | "+os+" | "+ns); System.out.println(" 1/2: " + timeRep1(s, os, ns) + " / " + timeRep2(s, os, ns)); }
// Log the error private void log(int level, SAXParseException e) { int line = e.getLineNumber(); int col = e.getColumnNumber(); String publicId = e.getPublicId(); String systemId = e.getSystemId(); StringBuffer sb = new StringBuffer(); sb.append(e.getMessage()); if (line > 0 || col > 0) { sb.append(": line="); sb.append(line); sb.append(", col="); sb.append(col); } if (publicId != null || systemId != null) { sb.append(": publicId="); sb.append(publicId); sb.append(", systemId="); sb.append(systemId); } // Log the message log.log(level, sb.toString()); }
public String toString() { StringBuffer sb = new StringBuffer(); sb.append("[Resp: "); sb.append(event); sb.append(" -> "); if (isAction()) { sb.append(action); } else if (isTransition()) { sb.append(newState); } else { sb.append("[???]"); } sb.append("]"); return sb.toString(); }