Example usage for java.lang String getChars

List of usage examples for java.lang String getChars

Introduction

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

Prototype

public void getChars(int srcBegin, int srcEnd, char dst[], int dstBegin) 

Source Link

Document

Copies characters from this string into the destination character array.

Usage

From source file:at.tuwien.minimee.migration.parser.HPROF_Parser.java

private void interpretline(String line) {
    char[] chars = new char[line.length()];
    line.getChars(0, line.length() - 1, chars, 0);

    String live_mem = "";
    String alloc_mem = "";

    int countWord = 0;
    int wordEntered = 0;

    for (char c : chars) {
        if (c == ' ') {
            wordEntered = 0;// w w w  . j ava 2  s  .  c  o m
            continue;
        }
        if (wordEntered == 0)
            countWord++;
        wordEntered = 1;
        if (countWord == 4)
            live_mem += c;
        else if (countWord == 6)
            alloc_mem += c;
    }

    total_virtual = total_virtual + Long.parseLong(live_mem);
    total_allocated = total_allocated + Long.parseLong(alloc_mem);
}

From source file:CharArrayWriter.java

public void write(String str, int off, int len) {

    ensureSize(count + len);//from   w ww .  j a v a2  s  .  co  m
    str.getChars(off, off + len, buffer, count);

    count += len;
}

From source file:TernarySearchTree.java

public Object get(String key) {
    int len = key.length();
    key.getChars(0, len, buff_, 0);
    int first = buff_[0];
    int second = buff_[1];
    if (len == 1 && (first < TRIE_CHAR_SIZE)) {
        return trie1Objects_[first];
    } else if (len == 2 && (first < TRIE_CHAR_SIZE) && (second < TRIE_CHAR_SIZE)) {
        return trie2Objects_[first][second];
    } else if ((first < TRIE_CHAR_SIZE) && (second < TRIE_CHAR_SIZE)) {
        int nodep = trie2_[first][second];
        if (nodep == 0) {
            return null;
        }//  w w  w  . j  a  v a  2s  .c o m
        return search(buff_, 2, len - 1, nodep);
    } else {
        //Use node[0] as a flag to determine if enetered here
        if (nodes_[0] == 0) {
            return null;
        }
        return search(buff_, 0, len - 1, INITIAL_NODE);
    }
}

From source file:com.huateng.ebank.framework.util.tags.HTTagUtils.java

/**
 * Filter the specified string for characters that are senstive to
 * HTML interpreters, returning the string with these characters replaced
 * by the corresponding character entities.
 *
 * @param value The string to be filtered and returned
 *///from w  w w .j a v  a2 s .  c o m
public String filter(String value) {

    if (value == null) {
        return (null);
    }

    char content[] = new char[value.length()];
    value.getChars(0, value.length(), content, 0);
    StringBuffer result = new StringBuffer(content.length + 50);

    for (int i = 0; i < content.length; i++) {
        switch (content[i]) {
        case '<':
            result.append("&lt;");
            break;
        case '>':
            result.append("&gt;");
            break;
        case '&':
            result.append("&amp;");
            break;
        case '"':
            result.append("&quot;");
            break;
        case '\'':
            result.append("&#39;");
            break;
        case ' ':
            result.append("&nbsp;");
            break;
        default:
            result.append(content[i]);
        }
    }

    return result.toString();
}

From source file:TernarySearchTree.java

public Object put(String key, Object value) {
    int len = key.length();
    key.getChars(0, len, buff_, 0);
    int first = buff_[0];
    int second = buff_[1];
    if (len == 1 && (first < TRIE_CHAR_SIZE)) {
        Object old = trie1Objects_[first];
        trie1Objects_[first] = value;
        return old;
    } else if (len == 2 && (first < TRIE_CHAR_SIZE) && (second < TRIE_CHAR_SIZE)) {
        Object old = trie2Objects_[first][second];
        trie2Objects_[first][second] = value;
        return old;
    } else if ((first < TRIE_CHAR_SIZE) && (second < TRIE_CHAR_SIZE)) {
        int nodep = trie2_[first][second];
        if (nodep == 0) {
            nodep = trie2_[first][second] = nextNode_;
            nodes_[nextNode_] = buff_[2];
            nextNode_ += NODE_SIZE;/*from w  ww.j  a  v  a 2 s  .  c  o m*/
        }
        return insert(buff_, 2, len - 1, value, nodep);
    } else {
        //Use node[0] as a flag to determine if enetered here
        if (nodes_[0] == 0) {
            nodes_[0] = 1;
            nodes_[INITIAL_NODE] = first;
        }
        return insert(buff_, 0, len - 1, value, INITIAL_NODE);
    }
}

From source file:CharBuf.java

/**
 * Replace a character range in the array with the characters from a
 * <code>String</code>./*ww  w . j a  v  a 2s  .  c  om*/
 */
public void replace(int from, int to, String text) {
    adjust(from, to, text.length());
    text.getChars(0, text.length(), buf, from);
}

From source file:CharBuf.java

/**
 * Insert the characters from a <code>String</code> into the array.
 */// w w  w.jav  a 2  s. c om
public void insert(int offset, String text) {
    adjust(offset, offset, text.length());
    text.getChars(0, text.length(), buf, offset);
}

From source file:QuickWriter.java

public void write(String str) {
    int len = str.length();
    if (pointer + len >= buffer.length) {
        flush();//from w w  w . j a  v a 2s . c  o m
        if (len > buffer.length) {
            raw(str.toCharArray());
            return;
        }
    }
    str.getChars(0, len, buffer, pointer);
    pointer += len;
}

From source file:com.ebuddy.cassandra.structure.StructureConverter.java

/**
 * @throws DataFormatException if the object could not be encoded as JSON
 *///from w w w.  j a v a  2  s .c o m
public String toString(Object obj) {
    if (obj == null) {
        return null;
    }

    if (obj instanceof String) {
        return (String) obj;
    }

    // write as special header bytes followed by JSON
    // intercept the Null token which stands in for a real null
    if (obj == NULL) {
        obj = null;
    }

    String jsonString = encodeJson(obj);
    char[] chars = new char[jsonString.length() + 1];
    chars[0] = HEADER_CHAR;
    jsonString.getChars(0, jsonString.length(), chars, 1);
    return new String(chars);
}

From source file:FastBufferedWriter.java

/**
 * Writes a portion of a String.//  w  w  w  .  ja  v a2s . c o  m
 *
 * <p> If the value of the <tt>len</tt> parameter is negative then no
 * characters are written.  This is contrary to the specification of this
 * method in the {@linkplain java.io.Writer#write(java.lang.String,int,int)
 * superclass}, which requires that an {@link IndexOutOfBoundsException} be
 * thrown.
 *
 * @param  s     String to be written
 * @param  off   Offset from which to start reading characters
 * @param  len   Number of characters to be written
 *
 * @exception  IOException  If an I/O error occurs
 */
public void write(String s, int off, int len) throws IOException {
    int b = off, t = off + len;
    while (b < t) {
        int d = min(nChars - nextChar, t - b);
        s.getChars(b, b + d, cb, nextChar);
        b += d;
        nextChar += d;
        if (nextChar >= nChars)
            flushBuffer();
    }
}