Example usage for java.lang StringBuffer StringBuffer

List of usage examples for java.lang StringBuffer StringBuffer

Introduction

In this page you can find the example usage for java.lang StringBuffer StringBuffer.

Prototype

@HotSpotIntrinsicCandidate
public StringBuffer() 

Source Link

Document

Constructs a string buffer with no characters in it and an initial capacity of 16 characters.

Usage

From source file:com.basho.contact.ContactConsole.java

public static void main(String[] args) throws IOException {
    CommandLine commandLine = processArgs(args);
    ConsoleReader reader = new ConsoleReader();
    reader.setBellEnabled(false);/*  ww w  .j a  va  2  s . com*/
    reader.setExpandEvents(false); // TODO: look into this
    // TODO: Pasting in text with tabs prints out a ton of completions
    //reader.addCompleter(new jline.console.completer.StringsCompleter(keywords));

    String line;
    PrintWriter out = new PrintWriter(System.out);
    DefaultConnectionProvider connections = new DefaultConnectionProvider();
    RuntimeContext ctx = new RuntimeContext(connections, System.out, System.err);
    if (!commandLine.hasOption("nosignals")) {
        ConsoleSignalHander.install("INT", ctx);
    }
    ContactWalker walker = new ContactWalker(ctx);
    ContactAdminWalker adminWalker = new ContactAdminWalker(ctx);
    List<ContactBaseListener> walkers = new ArrayList<ContactBaseListener>();
    walkers.add(walker);
    walkers.add(adminWalker);

    boolean nextLinePrompt = false;

    ANSIBuffer buf = new ANSIBuffer();
    buf.setAnsiEnabled(!commandLine.hasOption("nocolor"));
    buf.blue("Welcome to Riak Contact\n");
    buf.blue("(c) 2013 Dave Parfitt\n");
    System.out.println(buf.toString());

    if (!commandLine.hasOption("noconfig")) {
        String config = null;
        try {
            config = readConfig();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (config != null && !config.trim().isEmpty()) {
            processInput(config, walkers, ctx);
            processOutput(ctx, out, !commandLine.hasOption("nocolor"));
        }
    }

    if (commandLine.hasOption("infile")) {
        String filename = commandLine.getOptionValue("infile");
        readInputFile(filename, walkers, ctx);
        ctx.getActionListener().term();
        System.exit(0);
    }

    StringBuffer lines = new StringBuffer();
    ANSIBuffer ansiprompt = new ANSIBuffer();
    ansiprompt.setAnsiEnabled(true);
    ansiprompt.green("> ");
    String prompt = ansiprompt.toString(!commandLine.hasOption("nocolor"));
    boolean inHereDoc = false;

    while ((line = reader.readLine(nextLinePrompt ? "" : prompt)) != null) {
        out.flush();
        String chunks[] = line.split(" ");
        String consoleCommandCheck = chunks[0].toLowerCase().trim();
        if (consoleOnlyCommands.containsKey(consoleCommandCheck)) {
            consoleOnlyCommands.get(consoleCommandCheck).run(line, reader);
            continue;
        }

        if (line.contains("~%~") && !line.contains("\\~%~")) {
            inHereDoc = !inHereDoc;
        }

        if (!line.trim().endsWith(";")) {
            nextLinePrompt = true;
            lines.append(line);
            lines.append("\n");
        } else if (line.trim().endsWith(";") && !inHereDoc) {
            lines.append(line);
            String input = lines.toString();
            nextLinePrompt = false;
            processInput(input, walkers, ctx);
            processOutput(ctx, out, !commandLine.hasOption("nocolor"));
            lines = new StringBuffer();
        } else if (inHereDoc) {
            lines.append(line);
            lines.append("\n");
        }

    }
    ctx.getActionListener().term();
}

From source file:Util.java

public static String dumpHex(byte[] bytes) {
    StringBuffer buf = new StringBuffer();
    int aByte;/*  w w w .  ja v a  2  s .c  o  m*/
    for (int i = 0; i < bytes.length; i++) {
        aByte = bytes[i];
        if (aByte < 0)
            aByte += 0x100;
        buf.append("[" + Integer.toString(aByte, 16) + "]");
    }
    return buf.toString();
}

From source file:Main.java

public static String buildInfoHuafei() {
    StringBuffer sb = new StringBuffer();
    sb.append("<r>").append("<p n=\"");
    sb.append("mobilevoucher");
    sb.append("\"/>").append("</r>");
    return sb.toString();
}

From source file:Main.java

private static String getString(byte[] b) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < b.length; i++) {
        sb.append(b[i]);/*  w  w  w.  j a  v a  2 s . c o m*/
    }
    return sb.toString();
}

From source file:Main.java

public static String buffer(String... array) {
    StringBuffer s = new StringBuffer();
    for (String str : array) {
        s.append(str);//from  www  .  j a  va  2  s .  c  o  m
    }
    return s.toString();
}

From source file:Main.java

static String HexForBytes(byte[] bytes) {
    StringBuffer sb = new StringBuffer();
    for (byte b : bytes)
        sb.append(HexForByte(b));/*from w w w.jav a 2 s  .  co  m*/
    return sb.toString();
}

From source file:Main.java

private static String toHexString(byte[] bytes) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < bytes.length; i++) {
        sb.append(Integer.toHexString(bytes[i] >> 4 & 0x0f)).append(Integer.toHexString(bytes[i] & 0x0f));
    }//ww  w .ja va 2  s  . co  m
    return sb.toString();
}

From source file:Main.java

public static String getCnASCII(String str) {
    StringBuffer sb = new StringBuffer();
    byte[] strByte = str.getBytes();
    for (int i = 0; i < strByte.length; i++) {
        sb.append(Integer.toHexString(strByte[i] & 0xff));
    }//from   w  w  w  .ja v  a2  s.com
    return sb.toString();
}

From source file:Main.java

public static String encodeBytes(byte[] bytes) {
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < bytes.length; i++) {
        sb.append((char) (((bytes[i] >> 4) & 0xF) + ((int) 'a')));
        sb.append((char) (((bytes[i]) & 0xF) + ((int) 'a')));
    }/*from   w ww.  j  a v a  2s  .  com*/
    return sb.toString();
}

From source file:Main.java

public static String toCsv(String[] array) {
    StringBuffer result = new StringBuffer();
    for (int s = 0; s < array.length; s++) {
        if (s > 0)
            result.append(", ");
        result.append(array[s]);/*from   ww  w  .j  a  v  a 2  s.c  o  m*/
    }
    return result.toString();
}