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, int end) 

Source Link

Usage

From source file:dk.defxws.fgssolrremote.OperationsImpl.java

public String updateIndex(String action, String value, String repositoryName, String indexName,
        String indexDocXslt, String resultPageXslt) throws java.rmi.RemoteException {
    insertTotal = 0;/*from  w w w  .j a va2 s  .  com*/
    updateTotal = 0;
    deleteTotal = 0;
    emptyTotal = 0;
    StringBuffer resultXml = new StringBuffer();
    try {
        resultXml = sendToSolr("/select?q=*%3A*&rows=0");
    } catch (Exception e) {
        throw new GenericSearchException("updateIndex sendToSolr:\n" + e, e);
    }
    int i = resultXml.indexOf("numFound=");
    int j = resultXml.indexOf("\"", i + 10);
    String numFound = resultXml.substring(i + 10, j);
    try {
        docCount = Integer.parseInt(numFound);
    } catch (NumberFormatException e) {
        throw new GenericSearchException(
                "updateIndex NumberFormatException numFound=" + numFound + "\n" + resultXml, e);
    }
    int initDocCount = 0;
    resultXml = new StringBuffer();
    resultXml.append("<solrUpdateIndex");
    resultXml.append(" indexName=\"" + indexName + "\"");
    resultXml.append(">\n");
    try {
        initDocCount = docCount;
        if ("createEmpty".equals(action)) {
            createEmpty(indexName, resultXml);
            initDocCount = 0;
        } else {
            if ("deletePid".equals(action))
                deletePid(value, indexName, resultXml);
            else {
                if ("fromPid".equals(action))
                    fromPid(value, repositoryName, indexName, resultXml, indexDocXslt);
                else {
                    if ("fromFoxmlFiles".equals(action))
                        fromFoxmlFiles(value, repositoryName, indexName, resultXml, indexDocXslt);
                    else if ("optimize".equals(action))
                        optimize(indexName, resultXml);
                }
            }
        }
    } finally {
        docCount = initDocCount + insertTotal - deleteTotal;
    }
    logger.info("updateIndex " + action + " indexName=" + indexName + " docCount=" + docCount);
    resultXml.append("<counts");
    resultXml.append(" insertTotal=\"" + insertTotal + "\"");
    resultXml.append(" updateTotal=\"" + updateTotal + "\"");
    resultXml.append(" deleteTotal=\"" + deleteTotal + "\"");
    resultXml.append(" emptyTotal=\"" + emptyTotal + "\"");
    resultXml.append(" docCount=\"" + docCount + "\"");
    resultXml.append(" warnCount=\"" + warnCount + "\"");
    resultXml.append("/>\n");
    resultXml.append("</solrUpdateIndex>\n");
    if (logger.isDebugEnabled())
        logger.debug("resultXml =\n" + resultXml.toString());
    params = new String[12];
    params[0] = "OPERATION";
    params[1] = "updateIndex";
    params[2] = "ACTION";
    params[3] = action;
    params[4] = "VALUE";
    params[5] = value;
    params[6] = "REPOSITORYNAME";
    params[7] = repositoryName;
    params[8] = "INDEXNAME";
    params[9] = indexName;
    params[10] = "RESULTPAGEXSLT";
    params[11] = resultPageXslt;
    String xsltPath = config.getConfigName() + "/index/" + config.getIndexName(indexName) + "/"
            + config.getUpdateIndexResultXslt(indexName, resultPageXslt);
    StringBuffer sb = (new GTransformer()).transform(xsltPath, resultXml, params);
    return sb.toString();
}

From source file:com.isecpartners.gizmo.HttpRequest.java

private String mk_header(StringBuffer workingContents) {
    return workingContents.substring(0, workingContents.indexOf("\r\n"));
}

From source file:org.aselect.server.utils.Utils.java

/**
 * Serialize attributes contained in a HashMap. <br>
 * <br>//from ww w  . j av  a 2s.  c  o  m
 * <b>Description:</b> <br>
 * This method serializes attributes contained in a HashMap:
 * <ul>
 * <li>They are formatted as attr1=value1&attr2=value2;...
 * <li>If a "&amp;" or a "=" appears in either the attribute name or value, they are transformed to %26 or %3d
 * respectively.
 * <li>The end result is base64 encoded.
 * </ul>
 * <br>
 * 
 * @param htAttributes - HashMap containing all attributes
 * @return Serialized representation of the attributes
 * @throws ASelectException - If serialization fails.
 */
public static String serializeAttributes(HashMap htAttributes) throws ASelectException {
    final String sMethod = "serializeAttributes";
    try {
        if (htAttributes == null || htAttributes.isEmpty())
            return null;
        StringBuffer sb = new StringBuffer();

        Set keys = htAttributes.keySet();
        for (Object s : keys) {
            String sKey = (String) s;
            // for (Enumeration e = htAttributes.keys(); e.hasMoreElements(); ) {
            // String sKey = (String)e.nextElement();
            Object oValue = htAttributes.get(sKey);

            if (oValue instanceof Vector) {// it's a multivalue attribute
                Vector vValue = (Vector) oValue;

                sKey = URLEncoder.encode(sKey + "[]", "UTF-8");
                Enumeration eEnum = vValue.elements();
                while (eEnum.hasMoreElements()) {
                    String sValue = (String) eEnum.nextElement();

                    // add: key[]=value
                    sb.append(sKey).append("=").append(URLEncoder.encode(sValue, "UTF-8"));
                    if (eEnum.hasMoreElements())
                        sb.append("&");
                }
            } else if (oValue instanceof String) {// it's a single value attribute
                String sValue = (String) oValue;
                sb.append(URLEncoder.encode(sKey, "UTF-8")).append("=")
                        .append(URLEncoder.encode(sValue, "UTF-8"));
            }

            // if (e.hasMoreElements())
            sb.append("&");
        }
        int len = sb.length();
        String result = sb.substring(0, len - 1);
        BASE64Encoder b64enc = new BASE64Encoder();
        return b64enc.encode(result.getBytes("UTF-8"));
    } catch (Exception e) {
        ASelectSystemLogger logger = ASelectSystemLogger.getHandle();
        logger.log(Level.WARNING, MODULE, sMethod, "Could not serialize attributes", e);
        throw new ASelectException(Errors.ERROR_ASELECT_INTERNAL_ERROR);
    }
}

From source file:com.jims.oauth2.common.utils.OAuthUtils.java

/**
 * Construct a WWW-Authenticate header//from w  w w  .j  a  v a2 s  .  c  o m
 */
public static String encodeOAuthHeader(Map<String, Object> entries) {
    StringBuffer sb = new StringBuffer();
    sb.append(OAuth.OAUTH_HEADER_NAME).append(" ");
    /*
     * Android 4.1 requires realm as first parameter!
     * If not set, it will throw an IOException
     * see parseChallenges in
     * https://android.googlesource.com/platform/libcore/+/android-4.1.2_r2/luni/src/main/java/libcore/net/http/HeaderParser.java 
     * more information:
     * http://stackoverflow.com/questions/11810447/httpurlconnection-worked-fine-in-android-2-x-but-not-in-4-1-no-authentication-c
     */
    if (entries.get("realm") != null) {
        String value = String.valueOf(entries.get("realm"));
        if (!OAuthUtils.isEmpty(value)) {
            sb.append("realm=\"");
            sb.append(value);
            sb.append("\",");
        }
        entries.remove("realm");
    }
    for (Map.Entry<String, Object> entry : entries.entrySet()) {
        String value = entry.getValue() == null ? null : String.valueOf(entry.getValue());
        if (!OAuthUtils.isEmpty(entry.getKey()) && !OAuthUtils.isEmpty(value)) {
            sb.append(entry.getKey());
            sb.append("=\"");
            sb.append(value);
            sb.append("\",");
        }
    }

    return sb.substring(0, sb.length() - 1);
}

From source file:com.stromberglabs.jopensurf.Surf.java

public String getStringRepresentation(boolean freeOriented) {
    StringBuffer buffer = new StringBuffer();
    for (SURFInterestPoint point : freeOriented ? getFreeOrientedInterestPoints()
            : getUprightInterestPoints()) {
        for (double val : point.getDescriptor()) {
            buffer.append(Double.doubleToLongBits(val) + ",");
        }/*from   w  w  w  .  jav  a  2s.  c  o m*/
    }
    buffer.substring(0, buffer.length() - 1);
    return buffer.toString();
}

From source file:eu.cloud4soa.repository.utils.RepositoryManager.java

protected String getDBConnectString() {
    StringBuffer dbConnectString;
    String serverName;/*from ww w. j a  v  a  2  s .  c o  m*/
    String portNumber;

    dbConnectString = new StringBuffer("");
    dbConnectString.append(this.dbProtocol);
    if (dbHost != null && !dbHost.equals("")) {
        if (dbConnectString.length() > 2 && !dbConnectString
                .substring(dbConnectString.length() - 2, dbConnectString.length()).equals("//")) {
            logger.info("^^^^^^ "
                    + dbConnectString.substring(dbConnectString.length() - 2, dbConnectString.length()));
            dbConnectString.append("//");
        }
        dbConnectString.append(this.dbHost);
        if (this.dbPort != null && !this.dbPort.equals("")) {
            dbConnectString.append(":").append(this.dbPort);
        }
        if (this.dbName != null && !dbName.equals("")) {
            dbConnectString.append("/").append(this.dbName);
        }
    }
    if (dbProperties != null) {
        dbConnectString.append(dbProperties);
    }

    /*        if ( this.dbType.equals("hsqldb") ) {
    dbConnectString.append(";sql.enforce_size=false");
            }
     * 
     */

    logger.debug("DB connection string: " + dbConnectString.toString());
    return dbConnectString.toString();
}

From source file:org.nuxeo.ecm.webengine.DefaultWebContext.java

public String getBaseURL() {
    StringBuffer sb = request.getRequestURL();
    int p = sb.indexOf(getBasePath());
    if (p > -1) {
        return sb.substring(0, p);
    }/*from ww  w  . j  av a 2  s  . c  o m*/
    return sb.toString();
}

From source file:uk.org.funcube.fcdw.server.processor.WholeOrbitDataProcessorImpl.java

private void extractAndSaveWod(final Long satelliteId, final long seqNo, final List<String> frames,
        final Date receivedDate) {

    final Date frameTime = new Date(receivedDate.getTime() - 104 * 60 * 1000);

    final StringBuffer sb = new StringBuffer();

    for (int i = 0; i < 12; i++) {
        sb.append(StringUtils.right(frames.get(i), 400));
    }/*from w  ww  .j av a 2 s  . c  om*/

    int start = 0;
    int end = 46;

    for (int i = 0; i < 104; i++) {

        final long frameNumber = seqNo * 2 + i;

        if (wholeOrbitDataDao.findBySatelliteIdAndFrameNumber(satelliteId, frameNumber).size() == 0) {

            WholeOrbitDataEntity wod = null;

            switch (satelliteId.intValue()) {
            case 0:
                wod = new GomSpaceWODEntity(satelliteId, seqNo, frameNumber,
                        convertHexBytePairToBinary(sb.substring(start, end)), frameTime);
                break;
            case 1:
                wod = new ClydeSpaceWODEntity(satelliteId, seqNo, frameNumber,
                        convertHexBytePairToBinary(sb.substring(start, end)), frameTime);
                break;
            case 2:
                wod = new GomSpaceWODEntity(satelliteId, seqNo, frameNumber,
                        convertHexBytePairToBinary(sb.substring(start, end)), frameTime);
                break;
            default:
                break;
            }

            if (wod != null) {
                wholeOrbitDataDao.save(wod);
            }

            start += 46;
            end += 46;
        }

        // move the frame time forward a minute
        frameTime.setTime(frameTime.getTime() + 60 * 1000);
    }
}

From source file:org.auraframework.util.javascript.MultiStreamReaderTest.java

private void assertReadingMultipleStreams(int numChunks, String... content) throws Exception {
    Collection<URL> urls = Lists.newLinkedList();
    StringBuffer result = new StringBuffer();
    for (String conString : content) {
        urls.add(getStringStreamURL(conString));
        result.append(conString);/*from  ww w . j  a v a2 s  .c  o  m*/
    }
    MultiStreamReader reader = new MultiStreamReader(urls);
    int chunkLength = (result.length() / numChunks) + 1;

    for (int i = 0; i < numChunks; i++) {
        int expectedReadCount;
        String expectedString;
        if (result.length() == 0) {
            expectedReadCount = -1;
            expectedString = "";
        } else if (i < (numChunks - 1)) {
            expectedReadCount = chunkLength;
            expectedString = result.substring(i * chunkLength, i * chunkLength + expectedReadCount);
        } else {
            expectedReadCount = result.length() - i * chunkLength;
            expectedString = result.substring(i * chunkLength, i * chunkLength + expectedReadCount);
        }
        char[] array = new char[chunkLength];
        assertEquals("Unexpected number of characters read from streams for chunk " + i, expectedReadCount,
                reader.read(array));
        if (expectedReadCount > 0) {
            assertEquals("Unexpected concatenated set of characters read from streams for chunk " + i,
                    expectedString, new String(Arrays.copyOf(array, expectedReadCount)));
        }
    }
    reader.close();
}

From source file:org.jimcat.gui.perspective.boards.cards.Card.java

/**
 * update shown tag list/*  ww w  .ja v a  2 s  .  co m*/
 */
private void updateTagList() {
    List<Tag> tagList = new ArrayList<Tag>(image.getTags());
    StringBuffer result = new StringBuffer();
    Collections.sort(tagList, TAG_COMPARATOR);

    for (Tag t : tagList) {
        result.append(t.getName()).append(", ");
    }

    String list = " -none- ";
    if (tagList.size() > 0) {
        list = result.substring(0, result.length() - 2);
    }
    tags.setText(list);
    tags.setToolTipText(list);
}