Example usage for java.lang StringBuffer setLength

List of usage examples for java.lang StringBuffer setLength

Introduction

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

Prototype

@Override
public synchronized void setLength(int newLength) 

Source Link

Usage

From source file:org.latticesoft.util.common.DateUtil.java

/**
 * Returns the first day of the month //from   w  w  w.ja  va 2s  .c  o  m
 * @param year which year
 * @param month which month
 */
public static Date getFirstDayOfMonth(int year, int month) {
    StringBuffer sb = new StringBuffer();
    sb.setLength(0);
    sb.append(DateUtil.FORMAT_DIGIT4.format(year));
    sb.append(DateUtil.FORMAT_DIGIT2.format(month));
    sb.append("01000000");
    return DateUtil.parseUtilDate("yyyyMMddHHmmss", sb.toString());
}

From source file:org.latticesoft.util.common.DateUtil.java

/**
 * Returns the first day of the month//from  w  w w.jav  a 2s . c  om
 * @param date the date 
 */
public static Date getFirstDayOfMonth(Date date) {
    StringBuffer sb = new StringBuffer();
    sb.setLength(0);
    sb.append(DateUtil.FORMAT_DIGIT4.format(DateUtil.getYear(date)));
    sb.append(DateUtil.FORMAT_DIGIT2.format(DateUtil.getMonth(date)));
    sb.append("01000000");
    return DateUtil.parseUtilDate("yyyyMMddHHmmss", sb.toString());
}

From source file:org.dcm4che2.tool.dcmwado.DcmWado.java

private static void append(List<String> ss, StringBuffer sb) {
    for (String s : ss)
        sb.append(s).append(',');
    sb.setLength(sb.length() - 1);
}

From source file:org.dcm4che2.tool.dcmwado.DcmWado.java

private static void append(String[] ss, StringBuffer sb) {
    for (String s : ss)
        sb.append(s).append(',');
    sb.setLength(sb.length() - 1);
}

From source file:jdiff.API.java

/** 
 * Convert text with stuffed HTML tags ("lEsS_tHaN", etc) into HTML text.
 *//*from   w  ww.  ja v a  2  s  .  com*/
public static String showHTMLTags(String text) {
    StringBuffer sb = new StringBuffer(text);
    StringBuffer res = new StringBuffer();
    int len = sb.length();
    res.setLength(len);
    int i = 0;
    int resIdx = 0;
    while (i < len) {
        char c = sb.charAt(i);
        if (len - i > 8 && c == 'l' && sb.charAt(i + 1) == 'E' && sb.charAt(i + 2) == 's'
                && sb.charAt(i + 3) == 'S' && sb.charAt(i + 4) == '_' && sb.charAt(i + 5) == 't'
                && sb.charAt(i + 6) == 'H' && sb.charAt(i + 7) == 'a' && sb.charAt(i + 8) == 'N') {
            res.setCharAt(resIdx, '<');
            i += 8;
        } else if (len - i > 9 && c == 'q' && sb.charAt(i + 1) == 'U' && sb.charAt(i + 2) == 'o'
                && sb.charAt(i + 3) == 'T' && sb.charAt(i + 4) == 'e' && sb.charAt(i + 5) == '_'
                && sb.charAt(i + 6) == 'c' && sb.charAt(i + 7) == 'H' && sb.charAt(i + 8) == 'a'
                && sb.charAt(i + 9) == 'R') {
            res.setCharAt(resIdx, '"');
            i += 9;
        } else if (len - i > 7 && c == 'a' && sb.charAt(i + 1) == 'N' && sb.charAt(i + 2) == 'd'
                && sb.charAt(i + 3) == '_' && sb.charAt(i + 4) == 'c' && sb.charAt(i + 5) == 'H'
                && sb.charAt(i + 6) == 'a' && sb.charAt(i + 7) == 'R') {
            res.setCharAt(resIdx, '&');
            i += 7;
        } else {
            res.setCharAt(resIdx, c);
        }
        i++;
        resIdx++;
    }
    res.setLength(resIdx);
    return res.toString();
}

From source file:org.broad.igv.util.StringUtils.java

public static List<String> breakQuotedString(String string, char splitToken) {
    if (string == null)
        return null;
    ArrayList<String> strings = new ArrayList<String>();
    if (string.length() == 0) {
        return strings;
    }//from ww w  .j av  a  2s.com

    char[] characters = string.toCharArray();
    char c;
    boolean isQuoted = false;
    StringBuffer buff = new StringBuffer(100);
    for (int i = 0; i < characters.length; i++) {
        c = characters[i];
        if (isQuoted) {
            if (c == '"') {
                isQuoted = false;
            }
            buff.append(c);
        } else if (c == '"') {
            isQuoted = true;
            buff.append(c);
        } else {
            if (c == splitToken) {
                strings.add(buff.toString().trim());
                buff.setLength(0);
            } else {
                buff.append(c);
            }
        }
    }
    if (buff.length() > 0) {
        strings.add(buff.toString().trim());
    }
    return strings;

}

From source file:org.modmine.web.GBrowseParser.java

/**
 * Method to read the list of GBrowse tracks for a given organism
 *
 * @param organism organism (i.e. fly or worm)
 * @return map of submissions-tracks/* w w w  .  jav  a 2s.co m*/
 */
public static Map<String, List<GBrowseTrack>> readTracks(String organism) {
    Map<String, List<GBrowseTrack>> submissionsToTracks = new HashMap<String, List<GBrowseTrack>>();
    try {
        URL url = new URL(GBROWSE_BASE_URL + organism + GBROWSE_ST_URL_END);
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String line;

        // examples of lines:
        //
        // [Henikoff_Salt_H3_WIG]
        // key      = H3.3 Chromatin fractions extracted with NaCl
        // select   = 80mM fraction;2534 350mM fraction;2535 600mM fraction;2536
        // citation = <h1> H3.3 NaCl Salt Extracted Chromatin ....
        //
        // [LIEB_WIG_CHROMNUC_ENV]
        // key      = Chromosome-Nuclear Envelope Interaction
        // select   = SDQ3891_LEM2_N2_MXEMB_1;2729 SDQ3897_NPP13_N2_MXEMB_1;2738
        // citation = <h1> Chromosome-Nuclear Envelope Interaction proteins...
        //
        // note: subtracks have also names with spaces
        //
        // entries with only tracks (no subtrack)
        //
        // [marco1_G_sorted]
        // key      = small RACE products -pool G
        // citation = ...
        // data source = 2482 2501
        // track source = 3355
        //
        // TODO--done? test!
        // in this case we should link only to the first data source
        // (nr of sources = nr of tracks according to peter ...)
        // wait for document on parsing and news about fgb2

        StringBuffer trackName = new StringBuffer();
        StringBuffer toAppend = new StringBuffer();
        boolean hasSelected = false;
        String[] dataSourceItems = null;
        while ((line = reader.readLine()) != null) {
            if (line.startsWith("[")) {
                LOG.debug("GB: " + line);
                // this is a track
                hasSelected = false;
                trackName.setLength(0);
                trackName.append(line.substring(1, line.indexOf(']')));
            }
            if (line.startsWith("select")) {
                LOG.debug("GB: " + line);
                // here subtracks are listed
                hasSelected = true;
                String data = line.replace("select   = ", "");
                String[] result = data.split("\\s");
                for (String token : result) {
                    if (token.indexOf(SEPARATOR) < 0) {
                        // we are dealing with a bit of name
                        toAppend.append(token + " ");
                    } else {
                        // this is a token with subId
                        String subTrack = toAppend.toString() + token.substring(0, token.indexOf(SEPARATOR));
                        String dcc = token.substring(token.indexOf(SEPARATOR) + 1, token.length());
                        if (!StringUtils.isNumeric(dcc)) {
                            LOG.error("[SUBTRACKS] " + subTrack + " has a non numeric dccId: " + dcc);
                            continue;
                        }
                        String dccId = DCC_PREFIX + dcc;
                        LOG.debug("SUBTRACK: " + subTrack + "|" + dccId);
                        toAppend.setLength(0); // empty buffer
                        GBrowseTrack newTrack = new GBrowseTrack(organism, trackName.toString(), subTrack,
                                dccId);
                        addToGBMap(submissionsToTracks, dccId, newTrack);
                    }
                }
            }
            // added for tracks without subtrack
            if (line.startsWith("data source") && hasSelected == false) {
                String data = line.replace("data source = ", "");
                dataSourceItems = data.split("\\s");
            }

            if (line.startsWith("track source") && hasSelected == false && dataSourceItems.length >= 1) {
                String data = line.replace("track source = ", "");
                String[] tracks = data.split("\\s");
                if (tracks.length == dataSourceItems.length) {
                    for (String token : dataSourceItems) {
                        String dccId = DCC_PREFIX + token;
                        GBrowseTrack newTrack = new GBrowseTrack(organism, trackName.toString(),
                                trackName.toString(), dccId);
                        LOG.debug("GBds: " + dccId + "|" + trackName.toString());
                        addToGBMap(submissionsToTracks, dccId, newTrack);
                    }
                } else {
                    // assign only the first one, the other are related subs
                    String dccId = DCC_PREFIX + dataSourceItems[0];
                    GBrowseTrack newTrack = new GBrowseTrack(organism, trackName.toString(),
                            trackName.toString(), dccId);
                    LOG.debug("GBts: " + dccId + "|" + trackName.toString());
                    addToGBMap(submissionsToTracks, dccId, newTrack);
                }
                dataSourceItems = null;
            }
        }
        reader.close();
    } catch (Exception err) {
        err.printStackTrace();
    }
    return submissionsToTracks;
}

From source file:Util.java

public static String isoDateTimeToDate(String isoDate) {
    StringBuffer sb = new StringBuffer(isoDate);
    int maxlen;/*from  www .java2 s .  c o  m*/

    if (isoDate.length() >= 10) {
        //2007-01-01 -> 20070101
        //remove hyphens between year, month, and day
        sb.deleteCharAt(4);
        sb.deleteCharAt(6);

        maxlen = 8;

        //20070101T17:30:12 -> 20070101T173012
        if (isoDate.length() >= 19) {
            maxlen = 15;

            //remove colons between hours, minutes, and seconds
            sb.deleteCharAt(11);
            sb.deleteCharAt(13);

            if (isoDate.indexOf("Z") >= 0) {
                sb.insert(15, 'Z');
                ++maxlen;
            }
        }
        if (sb.length() > maxlen)
            sb.setLength(maxlen);
    }

    return sb.toString();
}

From source file:com.sec.ose.osi.sdk.protexsdk.bom.BOMEntFactory.java

public static ArrayList<BOMEnt> createBOMEntList(String pProjectName, boolean containDefaultComponent,
        UIResponseObserver observer) {/*from   www  .j  a v  a  2s.co m*/
    String mComponentID = "";
    String mComponentName = "";
    String mComponentVersion = "";
    String mLicenseName = "";
    String mHasDeclaredLicenseConflict = "";
    StringBuffer mComponentComment = new StringBuffer("");
    String mFileCountIdentified = "";

    ReportEntityList BillOfMaterialList = ReportAPIWrapper.getBillOfMaterials(pProjectName, observer, true);
    ArrayList<BOMEnt> bomEntList = new ArrayList<BOMEnt>();

    if (BillOfMaterialList == null)
        return null;
    if (BillOfMaterialList.size() == 0)
        return null;

    int cnt = 0;
    for (ReportEntity entity : BillOfMaterialList) {
        if (++cnt % 100 == 0)
            log.debug("entity#" + cnt);

        mComponentComment.setLength(0);
        mComponentName = entity.getValue(ReportInfo.BILL_OF_MATERIALS.COMPONENT);
        mComponentVersion = entity.getValue(ReportInfo.BILL_OF_MATERIALS.VERSION);

        // get license name
        mLicenseName = entity.getValue(ReportInfo.BILL_OF_MATERIALS.LICENSE);
        if (mLicenseName.contains("[") && !mLicenseName.contains("template")) {
            int startIndex = mLicenseName.indexOf("[");
            mLicenseName = mLicenseName.substring(0, startIndex);
            mLicenseName = mLicenseName.trim();
        }

        if (entity.getValue(ReportInfo.BILL_OF_MATERIALS.LICENSE_CONFLICT)
                .contains("Declared License Conflict")) {
            mHasDeclaredLicenseConflict = "true";
        } else {
            mHasDeclaredLicenseConflict = "false";
        }

        // get Component Comment
        String componentComment = entity.getValue(ReportInfo.BILL_OF_MATERIALS.COMMENT);
        if (componentComment != null && componentComment.length() > 0) {
            mComponentComment
                    .append("<" + mComponentName + " - " + mComponentVersion + ">\n" + componentComment);
        }

        mFileCountIdentified = entity.getValue(ReportInfo.BILL_OF_MATERIALS.NUM_OF_CODE_MATCH);

        if (mFileCountIdentified.equals("0")) {
            mFileCountIdentified = entity.getValue(ReportInfo.BILL_OF_MATERIALS.NUM_OF_SERACH);
        }

        bomEntList.add(new BOMEnt(pProjectName, mComponentName, mComponentID, mComponentVersion, mLicenseName,
                mHasDeclaredLicenseConflict, mComponentComment.toString(), mFileCountIdentified));
        if (observer != null) {
            observer.pushMessageWithHeader(
                    " > " + mComponentName + " - " + mComponentVersion + " : " + mLicenseName);
        }
    }
    return bomEntList;
}

From source file:org.latticesoft.util.common.ClassUtil.java

/**
 * Returns the names of the settable attributes or gettable attributes
 * @param c the class to be analysse/*from  w  w  w .j ava 2s  .  c om*/
 * @param isSettable set or get attributes
 * @return a string array of attributes
 */
public static Collection getAttributeNames(Class c, boolean isSettable) {
    ArrayList a = new ArrayList();
    if (c == null)
        return a;
    try {
        Method[] m = c.getMethods();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < m.length; i++) {
            String name = m[i].getName();
            if (isSettable) {
                if (name.startsWith("set")) {
                    String attribute = name.substring(4, name.length());
                    char ch = Character.toLowerCase(name.charAt(3));
                    sb.setLength(0);
                    sb.append(ch);
                    sb.append(attribute);
                    a.add(sb.toString());
                }
            } else {
                if (name.startsWith("get")) {
                    String attribute = name.substring(4, name.length());
                    char ch = Character.toLowerCase(name.charAt(3));
                    sb.setLength(0);
                    sb.append(ch);
                    sb.append(attribute);
                    a.add(sb.toString());
                }
                if (name.startsWith("is")) {
                    String attribute = name.substring(3, name.length());
                    char ch = Character.toLowerCase(name.charAt(2));
                    sb.setLength(0);
                    sb.append(ch);
                    sb.append(attribute);
                    a.add(sb.toString());
                }
            }
        }
    } catch (Exception e) {
    }
    return a;
}