Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2012 the project-owners Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package inti.util;
An utility for common string operations.
public class StringUtil {
A fast byte-to-string implementation which allocates only the new string object.

data The string data as single-byte values.
offset The offset in the data-array.
length The byte count to cast to character.
buffer The transfer buffer used to cast.
The newly-created string.
    public String bytesToString(byte[] dataint offsetint lengthchar[] buffer) {
        for (int i = offsetj = 0; i < lengthi++, j++) {
            buffer[j] = (chardata[i];
        return String.valueOf(buffer, 0, length);
A fast string-to-byte implementation which allocates no new objects at all.

source The string source as single-byte values.
dest The buffer to write the string data to.
    public void stringToBytes(String sourceByteBuffer dest) {
        for (int i = 0; i < source.length(); i++) {
New to GrepCode? Check out our FAQ X