本文整理匯總了Java中java.lang.StringBuffer.length方法的典型用法代碼示例。如果您正苦於以下問題:Java StringBuffer.length方法的具體用法?Java StringBuffer.length怎麽用?Java StringBuffer.length使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.StringBuffer
的用法示例。
在下文中一共展示了StringBuffer.length方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dumpProperties
import java.lang.StringBuffer; //導入方法依賴的package包/類
public static String dumpProperties(Properties p)
{
if ( p == null ) return "Null Properties";
StringBuffer sb = new StringBuffer();
TreeMap sm = new TreeMap(p);
Set keySet = sm.keySet();
Iterator iter = keySet.iterator();
while (iter.hasNext()) {
String key = (String)iter.next();
String value = (String)sm.get(key);
if ( key.indexOf("secret") >= 0 ) value = "** suppressed ("+value.length()+") **";
if ( sb.length() > 0 ) sb.append("\n");
sb.append(key);
sb.append(": ");
sb.append(value);
}
if ( sb.length() < 1 ) sb.append("Empty Properties");
return sb.toString();
}
示例2: parseChars
import java.lang.StringBuffer; //導入方法依賴的package包/類
public String parseChars(String allText) {
char cursor;
int lastEm = -1;
int lastStrong = -1;
StringBuffer text = new StringBuffer(allText);
for (int i = 0; i < text.length(); i++) {
cursor = text.charAt(i);
switch (cursor) {
case '_':
//checks if previous was whitespace
// is there two? (strong)
if (text.charAt(i + 1) == '_') {
// is this the left one?
if (lastStrong == -1) {
if (i - 1 < 0 || Character.isWhitespace(text.charAt(i - 1))) {
lastStrong = i;
// increment to get past double "__"
i++;
}
} else {
// i is on the left "_" of the closing "__"
if (i + 2 > text.length() || Character.isWhitespace(text.charAt(i + 2))) {
text = replaceSurrounding("__", "strong", lastStrong, i, text);
lastStrong = -1;
}
}
}
}
}
return text.toString();
}
示例3: decode
import java.lang.StringBuffer; //導入方法依賴的package包/類
public String decode() {
NodeTree tree = new NodeTree();
int out_file_length = uncompressed_size();
//String sb = "";
// immutable Strings replaced with more efficient string handling, suggested by wlbaker:
StringBuffer sb = new StringBuffer(out_file_length);
// System.out.println("About to enter decoding while loop...");
while (source_index < source_buffer.length && sb.length() != out_file_length) {
//System.out.println("Have entered decoding while loop...");
Node node = tree.getRoot();
// System.out.println("About to enter leaf finding while loop...");
while (!node.is_leaf()) {
// find leaf node
// System.out.println("now searching for leaf node...");
if (read_next_bit() != 0) {
// if (read_next_bit(source_index, source_char, bit, source_buffer) != 0) {
node = node.left;
// System.out.println("Picking left node, source bit != 0.");
} else {
node = node.right;
// System.out.println("Picking right node, source bit == 0.");
}
}
// System.out.println("Node symbol: " + (char)(node.symbol));
// System.out.println("Node symbol as toString: " + node);
sb.append((char)node.symbol); // more efficient string building, thanks wlbaker
//sb = sb + (char)(node.symbol);
// sb = sb + node;
// sb = sb + ((char)(node.symbol & 0xff));
// node.weight += 1;
node.incrementWeight();
// System.out.println("decoded text so far is: " +
// sb + ", now to update tree...");
tree.update_tree(node);
}
//source_buffer = null; // not needed for standalone utility
//is_filled = false;
return sb.toString();
}
示例4: writeBuildFiles
import java.lang.StringBuffer; //導入方法依賴的package包/類
/**
* Copy the build template files into a service patch location and update
* the properties with values from the current service patch.
*
* @param confdir Directory containing the config files
* @param destdir Destination directory
* @param variables Variables to be replaced in the files
* @param build Base product build information
*/
private void writeBuildFiles(File confdir, File destdir, Map variables, CMnBuildData build) {
// Use a stack to process the version number,
// popping the end digit if no matching directory is found
StringTokenizer vernumTokenizer = new StringTokenizer(CMnPatchUtil.getVersionNumber(build.getBuildVersion()), ".");
Stack<String> vernumStack = new Stack<String>();
while(vernumTokenizer.hasMoreTokens()) {
vernumStack.push((String) vernumTokenizer.nextToken());
}
// Select the most appropriate template directory
File templatedir = null;
while(!vernumStack.empty() && (templatedir == null)) {
StringBuffer dirname = new StringBuffer();
Iterator stackIter = vernumStack.iterator();
while(stackIter.hasNext()) {
if (dirname.length() > 0) {
dirname.append(".");
}
dirname.append((String) stackIter.next());
}
// Check to see if the most specific directory exists
File currentdir = new File(confdir.getAbsolutePath() + File.separator + dirname);
if (currentdir.isDirectory()) {
templatedir = currentdir;
} else {
// Remove the least significant digit and make another pass
vernumStack.pop();
}
}
// Make sure the destination directory exists
boolean destfound = false;
if (!destdir.exists()) {
destfound = destdir.mkdirs();
} else {
destfound = true;
}
// Copy the template files to the output directory
if ((templatedir != null) && destfound) {
destdir.mkdirs();
File[] files = templatedir.listFiles();
for (int idx = 0; idx < files.length; idx++) {
String filename = files[idx].getName();
File srcfile = files[idx];
File destfile = new File(destdir.getAbsolutePath() + File.separator + filename);
try {
// Replace any variables in the file with build values
display("Copying template file from " + srcfile + " to " + destfile);
replaceVariables(srcfile, destfile, variables);
} catch (FileNotFoundException nfex) {
display("Unable to locate file: " + srcfile.getName());
} catch (IOException ioex) {
display("Unable to copy file: " + destfile.getName());
}
// Make sure any script files are executable
if (filename.endsWith(".sh")) {
try {
destfile.setExecutable(true);
} catch (java.lang.SecurityException sex) {
display("Unable to make build script executable: " + destfile.getAbsolutePath());
}
}
}
} else {
display("Unable to copy template files: src=" + templatedir + ", dest=" + destdir);
}
}