Example usage for java.lang StringBuffer charAt

List of usage examples for java.lang StringBuffer charAt

Introduction

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

Prototype

@Override
public synchronized char charAt(int index) 

Source Link

Usage

From source file:Main.java

/**
 * Handles XML encoding of text, e.g. & to &
 * /*from  w w  w  .  j  a va2s  . c o m*/
 * @param sText Text to XML encode
 * @return XML Encoded text
 */
public static String encodeXMLText(String sText) {
    StringBuffer sBuff2 = new StringBuffer(sText);
    StringBuffer sNewBuff = new StringBuffer();

    for (int i = 0; i < sBuff2.length(); i++) {
        char currChar = sBuff2.charAt(i);
        Character currCharObj = new Character(sBuff2.charAt(i));
        if (currChar == '&') {
            if ((sBuff2.length() - 1 - i) >= 4 && sBuff2.charAt(i + 1) == 'a' && sBuff2.charAt(i + 2) == 'm'
                    && sBuff2.charAt(i + 3) == 'p' && sBuff2.charAt(i + 4) == ';') {
                i = i + 4;
                sNewBuff.append("&amp;");
            } else {
                sNewBuff.append("&amp;");
            }
        } else if (currChar == '>') {
            sNewBuff.append("&gt;");
        } else if (currChar == '<') {
            sNewBuff.append("&lt;");
        } else {
            sNewBuff.append(currChar);
        }
    }

    return sNewBuff.toString();

}

From source file:edu.buffalo.fusim.ExtractSeq.java

public static StringBuffer reverseComplement(StringBuffer seq) {
    StringBuffer revc = new StringBuffer();

    seq.reverse();//from   w ww .  ja v a  2s  .com
    for (int i = 0; i < seq.length(); i++) {
        revc.append(symbolMap.get(seq.charAt(i)));
    }

    return revc;
}

From source file:ro.nextreports.server.web.core.UrlUtil.java

public static StringBuffer getServerBaseUrl(StorageService storageService, boolean withEndingSlash) {
    StringBuffer buffer = new StringBuffer();

    Settings settings = storageService.getSettings();

    buffer.append(settings.getBaseUrl());
    if ('/' != buffer.charAt(buffer.length() - 1)) {
        buffer.append("/");
    }/* ww  w  .j  a  v  a2  s .c o m*/
    String contextPath = NextServerApplication.get().getServletContext().getContextPath();
    if (!StringUtils.isEmpty(contextPath)) {
        if ('/' == contextPath.charAt(0)) {
            contextPath = contextPath.substring(1);
        }
        buffer.append(contextPath);
        if (withEndingSlash) {
            buffer.append("/");
        }
    }

    return buffer;
}

From source file:Main.java

public static String[] stringtoArray(String s) {
    s = s.substring(1, s.length() - 1);/*from  ww w . j av a2 s. co m*/
    // convert a String s to an Array, the elements
    // are delimited by sep
    // NOTE : for old JDK only (<1.4).
    //        for JDK 1.4 +, use String.split() instead
    StringBuffer buf = new StringBuffer(s);
    String sep = ",";
    int arraysize = 1;
    for (int i = 0; i < buf.length(); i++) {
        if (sep.indexOf(buf.charAt(i)) != -1)
            arraysize++;
    }
    String[] elements = new String[arraysize];
    int y, z = 0;
    if (buf.toString().indexOf(sep) != -1) {
        while (buf.length() > 0) {
            if (buf.toString().indexOf(sep) != -1) {
                y = buf.toString().indexOf(sep);
                if (y != buf.toString().lastIndexOf(sep)) {
                    elements[z] = buf.toString().substring(0, y);
                    z++;
                    buf.delete(0, y + 1);
                } else if (buf.toString().lastIndexOf(sep) == y) {
                    elements[z] = buf.toString().substring(0, buf.toString().indexOf(sep));
                    z++;
                    buf.delete(0, buf.toString().indexOf(sep) + 1);
                    elements[z] = buf.toString();
                    z++;
                    buf.delete(0, buf.length());
                }
            }
        }
    } else {
        elements[0] = buf.toString();
    }
    buf = null;
    return elements;
}

From source file:com.orientechnologies.orient.jdbc.H2.java

private static void trim(StringBuffer section) {
    while (section.charAt(section.length() - 1) == SPACE_CHAR)
        section.deleteCharAt(section.length() - 1);
}

From source file:org.trianacode.taskgraph.tool.ToolTableUtils.java

/**
 * Returns the string representation for the path of this tools source code file.
 *
 * @param tool The tool we want the source code for.
 * @return the absolute path to the source file
 *///from  ww  w. j  ava2 s .  co m
public static String getUnitSourceFilePath(Tool tool) {
    if (!(tool.getProxy() instanceof JavaProxy)) {
        return null;
    }

    JavaProxy proxy = (JavaProxy) tool.getProxy();

    StringBuffer buff = new StringBuffer(tool.getToolBox().getPath());
    if (buff.charAt(buff.length() - 1) != File.separatorChar) {
        buff.append(File.separator);
    }
    buff.append(proxy.getUnitPackage().replace(".", File.separator));
    buff.append(File.separator);
    buff.append("src");
    buff.append(File.separator);

    buff.append(proxy.getUnitName().substring(proxy.getUnitName().lastIndexOf('.') + 1));
    buff.append(".java");
    return buff.toString();
}

From source file:ju.ehealthservice.graphs.RespRateGraphImage.java

public static boolean save(String fileName, String img) {
    try {/* w w w.j  a va 2  s.c o m*/
        StringBuffer data = new StringBuffer(img);
        data = new StringBuffer(data.substring(23));
        int c = 0;
        for (int i = 0; i < data.length(); i++) {
            if (data.charAt(i) == ' ') {
                c++;
                data.setCharAt(i, '+');
            }
        }
        byte[] imageByteArray = Base64.decodeBase64(data.toString());
        String ID = fileName.substring(0, fileName.indexOf('_'));
        String path = Constants.GRAPH_REPOSITORY_PATH + ID + "\\RespRate\\";
        fileName = fileName + ".jpg";
        FileOutputStream imageOutFile = new FileOutputStream(path + fileName);
        imageOutFile.write(imageByteArray);
        imageOutFile.close();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:ju.ehealthservice.graphs.ECGGraphImage.java

public static boolean save(String fileName, String img) {
    try {/* w  ww  .  j a v  a2s  . c om*/
        StringBuffer data = new StringBuffer(img);
        data = new StringBuffer(data.substring(23));
        int c = 0;
        for (int i = 0; i < data.length(); i++) {
            if (data.charAt(i) == ' ') {
                c++;
                data.setCharAt(i, '+');
            }
        }
        byte[] imageByteArray = Base64.decodeBase64(data.toString());
        String ID = fileName.substring(0, fileName.indexOf('_'));
        String path = Constants.GRAPH_REPOSITORY_PATH + ID + "\\ECG\\";
        fileName = fileName + ".jpg";
        FileOutputStream imageOutFile = new FileOutputStream(path + fileName);
        imageOutFile.write(imageByteArray);
        imageOutFile.close();
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

/**
 * Replaces successive XML space characters by a single space character (<tt>' '</tt>)
 * then removes leading and trailing space characters if any.
 * /*from   w w  w.ja  v a2s  . co  m*/
 * @param value string to be processed
 * @return processed string
 */
public static final String collapseWhiteSpace(CharSequence value) {
    StringBuffer buffer = new StringBuffer();
    compressWhiteSpace(value, buffer);

    int last = buffer.length() - 1;
    if (last >= 0) {
        if (buffer.charAt(last) == ' ') {
            buffer.deleteCharAt(last);
            --last;
        }

        if (last >= 0 && buffer.charAt(0) == ' ')
            buffer.deleteCharAt(0);
    }

    return buffer.toString();
}

From source file:Main.java

/** 
 * Erases the mIRC colorcodes from a String. 
 * The documentation of the evil color codes is available on 
 * <a href="http://www.mirc.co.uk/help/color.txt" 
 * target="_blank">http://www.mirc.co.uk/help/color.txt</a>. 
 * @param buf The line which should be parsed. 
 * @return A line as <code>StringBuffer</code> object which is cleaned from 
 *         any mIRC colorcodes./*from  www.  j a v a 2  s  .co m*/
 * @see #parseColors(String)
 */
public static StringBuffer parseColors(StringBuffer buf) {
    int len = buf.length();

    for (int i = 0, j = 0, c; i < len; i++, j = i) {
        c = buf.charAt(i);
        try {
            // COLORS Beginning 
            // (format: <colorIndicator><int>[<int>][[,<int>[<int>]]
            if (c == colorIndicator) {
                c = buf.charAt(++j);
                if ('0' <= c && c <= '9') { // first int
                    c = buf.charAt(++j);
                    if ('0' <= c && c <= '9')
                        c = buf.charAt(++j); // second int
                }
                if (c == ',')
                    c = buf.charAt(++j); // comma 
                if ('0' <= c && c <= '9') { // first int
                    c = buf.charAt(++j);
                    if ('0' <= c && c <= '9')
                        c = buf.charAt(++j); // second int
                }
                // ACTION / BOLD / UNDERLINE / COLOR END 
                // (format: <actionIndicator> / <boldIndicator> etc.)
            } else if (c == actionIndicator || c == boldIndicator || c == underlinedIndicator
                    || c == colorEndIndicator || c == colorReverseIndicator) {
                j++;
            }
        } catch (StringIndexOutOfBoundsException exc) {
            // we got the end of the string with a call to charAt(++iIndexEnd)
            // nothing
        }

        if (j > i) {
            buf = buf.delete(i, j); // remove the cars
            len -= (j - i);
            i -= (j - i);
        }
    }
    return buf;
}