Example usage for java.lang StringBuffer substring

List of usage examples for java.lang StringBuffer substring

Introduction

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

Prototype

@Override
public synchronized String substring(int start) 

Source Link

Usage

From source file:Main.java

public static void main(String[] arg) {

    StringBuffer buffer = new StringBuffer("from java2s.com");

    System.out.println(buffer.substring(2));
}

From source file:Main.java

public static void main(String[] args) {
    StringBuffer sb = new StringBuffer("this is a test");

    System.out.println(sb);/*  ww w  .  j  a v a 2s  . com*/
    String strPart1 = sb.substring(5);

    System.out.println(strPart1);
    String strPart2 = sb.substring(0, 17);

    System.out.println(strPart2);
}

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

public static boolean save(String fileName, String img) {
    try {// w  ww. ja  v a2s .  co  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 a 2 s.co  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 + "\\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:com.hsbc.frc.SevenHero.ClientProxyAuthentication.java

private static boolean isHeaderEnd(StringBuffer sb) {
    int len = sb.length();
    if (len > 2) {
        if ("\n\n".equals(sb.substring(len - 2))) {
            return true;
        }//from  w  w  w .  jav a 2  s.  c  o m
    }

    if (len > 4) {
        if ("\r\n\r\n".equals(sb.substring(len - 4))) {
            return true;
        }
    }

    return false;
}

From source file:Main.java

public static String getLocalMacAddress(Context mc) {
    String defmac = "00:00:00:00:00:00";
    InputStream input = null;/*  ww  w.  j a v  a2s  .  c  o m*/
    String wifimac = getWifiMacAddress(mc);
    if (null != wifimac) {
        if (!wifimac.equals(defmac))
            return wifimac;
    }
    try {

        ProcessBuilder builder = new ProcessBuilder("busybox", "ifconfig");
        Process process = builder.start();
        input = process.getInputStream();

        byte[] b = new byte[1024];
        StringBuffer buffer = new StringBuffer();
        while (input.read(b) > 0) {
            buffer.append(new String(b));
        }
        String value = buffer.substring(0);
        String systemFlag = "HWaddr ";
        int index = value.indexOf(systemFlag);
        // List <String> address = new ArrayList <String> ();
        if (0 < index) {
            value = buffer.substring(index + systemFlag.length());
            // address.add(value.substring(0,18));
            defmac = value.substring(0, 17);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return defmac;
}

From source file:Main.java

public static boolean writeFile(StringBuffer sb, String fileName, String path) {
    String string;/*w ww  .java2s . com*/
    DataOutputStream bfo = null;
    File fileDir = new File(path);
    if (!fileDir.exists())
        fileDir.mkdirs();

    try {
        string = sb.substring(0);
        bfo = new DataOutputStream(new FileOutputStream(path + fileName));
        bfo.write(string.getBytes("gbk"));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return true;
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedHeadFragment.java

public static String getFeedObjectClause() {
    String[] types = DbObjects.getRenderableTypes();
    StringBuffer allowed = new StringBuffer();
    for (String type : types) {
        allowed.append(",'").append(type).append("'");
    }/*  w  ww  . j a  va  2s  .c  o  m*/
    return DbObject.TYPE + " in (" + allowed.substring(1) + ")";
}

From source file:ServletUtils.java

/**
 * NOT UNIT TESTED Returns the URL (including query parameters) minus the scheme, host, and
 * context path.  This method probably be moved to a more general purpose
 * class./*from   ww w.j a v  a  2s  . com*/
 */
public static String getRelativeUrl(HttpServletRequest request) {

    String baseUrl = null;

    if ((request.getServerPort() == 80) || (request.getServerPort() == 443))
        baseUrl = request.getScheme() + "://" + request.getServerName() + request.getContextPath();
    else
        baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
                + request.getContextPath();

    StringBuffer buf = request.getRequestURL();

    if (request.getQueryString() != null) {
        buf.append("?");
        buf.append(request.getQueryString());
    }

    return buf.substring(baseUrl.length());
}

From source file:Main.java

public static String encodeUnicode(String str) {
    char[] utfBytes = str.toCharArray();
    StringBuffer buffer = new StringBuffer();
    for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++) {
        String hexB = Integer.toHexString(utfBytes[byteIndex]);
        if (hexB.length() <= 2) {
            hexB = "00" + hexB;
        }/*from   w  ww  . j  a v  a  2s . c o m*/
        buffer.append("\\u" + hexB);
    }
    return buffer.substring(0);
}