Example usage for java.lang String copyValueOf

List of usage examples for java.lang String copyValueOf

Introduction

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

Prototype

public static String copyValueOf(char data[], int offset, int count) 

Source Link

Document

Equivalent to #valueOf(char[],int,int) .

Usage

From source file:Main.java

public static void main(String[] arg) {
    char[] textArray = { 'T', 'o', ' ', 'b', 'e', ' ', 'o', 'r', ' ', 'n', 'o', 't', ' ', 't', 'o', ' ', 'b',
            'e' };

    String text = String.copyValueOf(textArray, 9, 3);

    System.out.println(text);/*from   w ww .j a v a 2 s.  c  o m*/
}

From source file:Main.java

public static void main(String[] args) {
    char[] data = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };

    String text = String.valueOf(data);
    System.out.println(text);//from  w  ww .  j av  a  2 s .  c  om

    text = String.copyValueOf(data, 3, 5);
    System.out.println(text);
}

From source file:Main.java

public static void main(String[] arg) {
    char[] textArray = { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm', ' ', 'j', 'a', 'v', 'a', '2', 's',
            '.', 'c', 'o', 'm' };

    String text = String.copyValueOf(textArray, 9, 3);

    System.out.println(text);// w  w  w  .  j  av a2 s.  c o m
}

From source file:Main.java

/**
 * Remove none digital character from the decimal string that maybe contains
 * none digit character.// ww  w  .java 2s.c  o  m
 *
 * @param decimal
 *            the decimal string.
 * @return the new digital string only contains digital character.
 */
public static String getPlain(String decimal) {
    if (TextUtils.isEmpty(decimal)) {
        decimal = "0";
    }
    char[] ch = new char[decimal.length()];
    int index = 0;
    for (int i = 0; i < decimal.length(); i++) {
        if (Character.isDigit(decimal.charAt(i))) {
            ch[index++] = decimal.charAt(i);
        }
    }
    return String.copyValueOf(ch, 0, index);
}

From source file:Main.java

public static String ByteToString(byte[] byteArray) {
    if (byteArray == null) {
        return null;
    }//from w ww. j  a v a2s  .c  o m
    try {
        String result = new String(byteArray, "ASCII");
        result = String.copyValueOf(result.toCharArray(), 0, byteArray.length);
        return result;
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}

From source file:de.ii.ldproxy.gml2json.FastXYSwapCoordinatesWriter.java

private void appendToXBuffer(char[] chars, int start, int len) {
    if (xBuffer != null && !xBuffer.isEmpty()) {
        xBuffer = xBuffer.concat(String.copyValueOf(chars, start, len));
    } else {//from  w  w w. j a  va  2s . c om
        xBuffer = String.copyValueOf(chars, start, len);
    }
}

From source file:LineInputStream.java

/**
 * Read a line containing only ASCII characters from the input 
 * stream. A line is terminated by a CR or NL or CR-NL sequence.
 * A common error is a CR-CR-NL sequence, which will also terminate
 * a line./*from ww w .ja  v a2s.com*/
 * The line terminator is not returned as part of the returned 
 * String. Returns null if no data is available. <p>
 *
 * This class is similar to the deprecated 
 * <code>DataInputStream.readLine()</code>
 */
public String readLine() throws IOException {
    InputStream in = this.in;
    char[] buf = lineBuffer;

    if (buf == null)
        buf = lineBuffer = new char[128];

    int c1;
    int room = buf.length;
    int offset = 0;

    while ((c1 = in.read()) != -1) {
        if (c1 == '\n') // Got NL, outa here.
            break;
        else if (c1 == '\r') {
            // Got CR, is the next char NL ?
            int c2 = in.read();
            if (c2 == '\r') // discard extraneous CR
                c2 = in.read();
            if (c2 != '\n') {
                // If not NL, push it back
                if (!(in instanceof PushbackInputStream))
                    in = this.in = new PushbackInputStream(in);
                ((PushbackInputStream) in).unread(c2);
            }
            break; // outa here.
        }

        // Not CR, NL or CR-NL ...
        // .. Insert the byte into our byte buffer
        if (--room < 0) { // No room, need to grow.
            buf = new char[offset + 128];
            room = buf.length - offset - 1;
            System.arraycopy(lineBuffer, 0, buf, 0, offset);
            lineBuffer = buf;
        }
        buf[offset++] = (char) c1;
    }

    if ((c1 == -1) && (offset == 0))
        return null;

    return String.copyValueOf(buf, 0, offset);
}

From source file:de.ii.ldproxy.gml2json.TransformingCoordinatesWriter.java

@Override
protected void jsonWriteRawValue(char[] chars, int i, int j) throws IOException {
    //json.writeRawValue(chars, i, j);
    jsonWriteRawValue(String.copyValueOf(chars, i, j));
}

From source file:Streams.java

public static String getAsString(InputStream is) {
    int c = 0;/*  w  ww. ja  v  a  2 s  . co  m*/
    char lineBuffer[] = new char[128], buf[] = lineBuffer;
    int room = buf.length, offset = 0;
    try {
        loop: while (true) {
            // read chars into a buffer which grows as needed
            switch (c = is.read()) {
            case -1:
                break loop;

            default:
                if (--room < 0) {
                    buf = new char[offset + 128];
                    room = buf.length - offset - 1;
                    System.arraycopy(lineBuffer, 0, buf, 0, offset);
                    lineBuffer = buf;
                }
                buf[offset++] = (char) c;
                break;
            }
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    if ((c == -1) && (offset == 0)) {
        return null;
    }
    return String.copyValueOf(buf, 0, offset);
}

From source file:de.ii.ldproxy.gml2json.TransformingCoordinatesWriter.java

@Override
protected void jsonWriteRaw(char[] chars, int i, int j) throws IOException {
    //json.writeRaw(chars, i, j);
    if (isXValue()) {
        coordinateBuffer.appendX(String.copyValueOf(chars, i, j));
    }//from ww w  .  ja  va  2  s  .co  m
    if (isYValue()) {
        coordinateBuffer.appendY(String.copyValueOf(chars, i, j));
    }
}