List of usage examples for java.lang StringBuffer replace
@Override public synchronized StringBuffer replace(int start, int end, String str)
From source file:fr.gouv.diplomatie.applitutoriel.utility.Graphique.java
/** * permet de soit complter le libell pour viter d'avoir 2 lgendes sur la mme ligne, soit de dcouper * le libell s'il ne loge pas en longueur sur une seule ligne. * * @param chaine//from w w w .ja va2 s .co m * the chaine * @param longueur * the longueur * @return the string */ public static String genererLibellePourLegende(final String chaine, final int longueur) { final StringBuffer retour = new StringBuffer(); if (chaine.length() <= longueur) { retour.append(StringUtils.rightPad(chaine, longueur, ' ')); } else { retour.append(chaine); final int index = StringUtils.lastIndexOf(" ", chaine.substring(0, longueur)); if (index > 0) { retour.replace(index, index + 1, "\r\n"); } } return retour.toString(); }
From source file:de.uniwue.info6.misc.StringTools.java
/** * * * @param stringBuffer//w w w. j a v a2 s . co m * @param places * @return */ public static StringBuffer removeLastCharacters(StringBuffer stringBuffer, int places) { return stringBuffer.replace(stringBuffer.length() - places, stringBuffer.length(), ""); }
From source file:de.uniwue.info6.misc.StringTools.java
/** * * * @param stringBuffer//from www .j a v a 2 s . com * @param places * @return */ public static StringBuffer removeFirstCharacters(StringBuffer stringBuffer, int places) { return stringBuffer.replace(0, places, ""); }
From source file:com.vertica.hadoop.VerticaOutputFormat.java
public static void checkOutputSpecs(VerticaConfiguration vtconfig) throws IOException { Relation vTable = new Relation(vtconfig.getOutputTableName()); if (vTable.isNull()) throw new IOException("Vertica output requires a table name defined by " + VerticaConfiguration.OUTPUT_TABLE_NAME_PROP); String[] def = vtconfig.getOutputTableDef(); boolean dropTable = vtconfig.getDropTable(); Statement stmt = null;/* ww w.j a v a2 s . c o m*/ try { Connection conn = vtconfig.getConnection(true); DatabaseMetaData dbmd = conn.getMetaData(); ResultSet rs = dbmd.getTables(null, vTable.getSchema(), vTable.getTable(), null); boolean tableExists = rs.next(); stmt = conn.createStatement(); if (tableExists && dropTable) { stmt = conn.createStatement(); stmt.execute("TRUNCATE TABLE " + vTable.getQualifiedName().toString()); } // create table if it doesn't exist if (!tableExists) { if (def == null) throw new RuntimeException("Table " + vTable.getQualifiedName().toString() + " does not exist and no table definition provided"); if (!vTable.isDefaultSchema()) { stmt.execute("CREATE SCHEMA IF NOT EXISTS " + vTable.getSchema()); } StringBuffer tabledef = new StringBuffer("CREATE TABLE ") .append(vTable.getQualifiedName().toString()).append(" ("); for (String column : def) tabledef.append(column).append(","); tabledef.replace(tabledef.length() - 1, tabledef.length(), ")"); stmt.execute(tabledef.toString()); } } catch (Exception e) { throw new RuntimeException(e); } finally { if (stmt != null) try { stmt.close(); } catch (SQLException e) { throw new RuntimeException(e); } } }
From source file:com.vertica.hivestoragehandler.VerticaOutputFormat.java
public static void checkOutputSpecs(VerticaConfiguration vtconfig) throws IOException { VerticaRelation vTable = new VerticaRelation(vtconfig.getOutputTableName()); if (vTable.isNull()) throw new IOException("Vertica output requires a table name defined by " + VerticaConfiguration.OUTPUT_TABLE_NAME_PROP); String[] def = vtconfig.getOutputTableDef(); boolean dropTable = vtconfig.getDropTable(); Statement stmt = null;//w w w. ja va 2s.co m try { Connection conn = vtconfig.getConnection(true); DatabaseMetaData dbmd = conn.getMetaData(); ResultSet rs = dbmd.getTables(null, vTable.getSchema(), vTable.getTable(), null); boolean tableExists = rs.next(); stmt = conn.createStatement(); if (tableExists && dropTable) { stmt = conn.createStatement(); stmt.execute("TRUNCATE TABLE " + vTable.getQualifiedName().toString()); } // create table if it doesn't exist if (!tableExists) { if (def == null) throw new RuntimeException("Table " + vTable.getQualifiedName().toString() + " does not exist and no table definition provided"); if (!vTable.isDefaultSchema()) { stmt.execute("CREATE SCHEMA IF NOT EXISTS " + vTable.getSchema()); } StringBuffer tabledef = new StringBuffer("CREATE TABLE ") .append(vTable.getQualifiedName().toString()).append(" ("); for (String column : def) tabledef.append(column).append(","); tabledef.replace(tabledef.length() - 1, tabledef.length(), ")"); stmt.execute(tabledef.toString()); } } catch (Exception e) { throw new RuntimeException(e); } finally { if (stmt != null) try { stmt.close(); } catch (SQLException e) { throw new RuntimeException(e); } } }
From source file:org.hyperic.util.jdbc.DBUtil.java
public static void replacePlaceHolder(StringBuffer buf, String repl) { int index = buf.indexOf("?"); if (index >= 0) buf.replace(index, index + 1, repl); }
From source file:org.onehippo.cms7.essentials.dashboard.utils.GlobalUtils.java
/** * * Replaces {@code #placeholder#} variable with string replacement provided * * @param input input string/* w ww . j a v a 2 s . co m*/ * @param placeholder placeholder name * @param replacement replacement string * @return input string replaced with replacements */ public static String replacePlaceholders(final String input, final String placeholder, final String replacement) { if (Strings.isNullOrEmpty(input)) { return ""; } final StringBuffer buffer = new StringBuffer(input); try { final Pattern pattern = Pattern.compile("(#" + placeholder + "#)", Pattern.MULTILINE); Matcher matcher = pattern.matcher(buffer); while (matcher.find()) { buffer.replace(matcher.start(), matcher.end(), replacement); } } catch (Exception ignore) { //ignore } return buffer.toString(); }
From source file:com.mg.framework.utils.StringUtils.java
/** * Replaces all occurances of oldString in mainString with newString * * @param mainString The original string * @param oldString The string to replace * @param newString The string to insert in place of the old * @return mainString with all occurances of oldString replaced by newString *///from ww w . ja v a 2 s . c om public static String replaceString(String mainString, String oldString, String newString) { if (mainString == null) { return null; } if (oldString == null || oldString.length() == 0) { return mainString; } if (newString == null) { newString = ""; } int i = mainString.lastIndexOf(oldString); if (i < 0) return mainString; StringBuffer mainSb = new StringBuffer(mainString); while (i >= 0) { mainSb.replace(i, i + oldString.length(), newString); i = mainString.lastIndexOf(oldString, i - 1); } return mainSb.toString(); }
From source file:Main.java
/** * Convert entities to umlaute//from w w w . j ava2s. co m */ public static String decode(String value) { StringBuffer buffer = new StringBuffer(value); int pos; boolean found; for (int i = 0; i < buffer.length(); i++) { if (buffer.charAt(i) == '_' && buffer.charAt(i + 1) == '_') { pos = i + 2; found = false; while (buffer.charAt(pos) >= '0' && buffer.charAt(pos) <= '9') { found = true; pos++; } if (found == true && pos > i + 2 && buffer.charAt(pos) == ';') { int ent = new Integer(buffer.substring(i + 2, pos)).intValue(); buffer.replace(i, pos + 1, "" + (char) ent); } } } return buffer.toString(); }
From source file:com.amazonaws.services.kinesis.aggregators.StreamAggregatorUtils.java
/** * Returns a statement which can be used to create an External Table in Hive * which wraps the Aggregator Table indicated, using the required name in * Hive./*from ww w .j av a 2s .c o m*/ * * @param dynamoClient Dynamo DB Client to use for connection to Dynamo DB. * @param hiveTableName The table name to generate for the Hive Table. * @param dynamoTable The name of the aggregator table in Dynamo DB. * @return A CREATE EXTERNAL TABLE statement to be used in Hive * @throws Exception */ public static String getDynamoHiveWrapper(AmazonDynamoDB dynamoClient, String hiveTableName, String dynamoTable) throws Exception { LOG.info("Generating Hive Integration Statement"); StringBuffer sb = new StringBuffer(); sb.append(String.format("CREATE EXTERNAL TABLE %s(", hiveTableName)); // add the hive table spec List<String> tableDefinition = DynamoUtils.getDictionaryEntry(dynamoClient, dynamoTable); for (String s : tableDefinition) { sb.append(String.format("%s string,", s)); } sb.replace(sb.length() - 1, sb.length(), ""); sb.append(String.format( ") STORED BY 'org.apache.hadoop.hive.dynamodb.DynamoDBStorageHandler' TBLPROPERTIES (\"dynamodb.table.name\" = \"%s\", \"dynamodb.column.mapping\" = \"", dynamoTable)); for (String s : tableDefinition) { sb.append(String.format("%s:%s,", s, s)); } sb.replace(sb.length() - 1, sb.length(), ""); sb.append("))"); return sb.toString(); }