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:org.apache.lucene.analysis.jate.OpenNLPTokenizer.java

void splitWords(int i) {
    Span current = sentences[i];/* w w  w .  j a v  a  2 s .c o  m*/
    String sentence = String.copyValueOf(fullText, current.getStart(), current.getEnd() - current.getStart());
    words[i] = tokenizerOp.tokenizePos(sentence);
}

From source file:de.Keyle.MyPet.api.Util.java

public static String toString(InputStream is, Charset charset) {
    String content = "";

    try {/*from w w  w . j a va 2s  . com*/
        InputStreamReader in = new InputStreamReader(is, charset);
        int numBytes;
        final char[] buf = new char[512];
        while ((numBytes = in.read(buf)) != -1) {
            content += String.copyValueOf(buf, 0, numBytes);
        }
    } catch (Exception ignored) {
    }

    return content;
}

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

@Override
protected void jsonWriteRaw(char[] chars, int i, int j) throws IOException {
    if (isXValue()) {
        tupleBuffer.appendX(String.copyValueOf(chars, i, j));
    }//from w w  w .  ja va  2s . c om
    if (isYValue()) {
        tupleBuffer.appendY(String.copyValueOf(chars, i, j));
    }
}

From source file:org.commoncrawl.io.NIOHttpHeaders.java

/** Parse and merge a MIME header from an input stream. */
public void mergeHeader(InputStream is) throws java.io.IOException {
    if (is == null)
        return;/*from ww w. ja v  a 2s. c o  m*/
    char s[] = new char[10];
    int firstc = is.read();
    while (firstc != '\n' && firstc != '\r' && firstc >= 0) {
        int len = 0;
        int keyend = -1;
        int c;
        boolean inKey = firstc > ' ';
        s[len++] = (char) firstc;
        parseloop: {
            while ((c = is.read()) > 0) {
                switch (c) {
                case ':':
                    if (inKey && len > 0)
                        keyend = len;
                    inKey = false;
                    break;
                case '\t':
                    c = ' ';
                case ' ':
                    inKey = false;
                    break;
                case '\r':
                case '\n':
                    firstc = is.read();
                    if (c == '\r' && firstc == '\n') {
                        firstc = is.read();
                        if (firstc == '\r')
                            firstc = is.read();
                    }
                    if (firstc == '\n' || firstc == '\r' || firstc > ' ')
                        break parseloop;
                    /* continuation */
                    c = ' ';
                    break;
                }
                if (len >= s.length) {
                    char ns[] = new char[s.length * 2];
                    System.arraycopy(s, 0, ns, 0, len);
                    s = ns;
                }
                s[len++] = (char) c;
            }
            firstc = -1;
        }
        while (len > 0 && s[len - 1] <= ' ')
            len--;
        String k;
        if (keyend <= 0) {
            k = null;
            keyend = 0;
        } else {
            k = String.copyValueOf(s, 0, keyend);
            if (keyend < len && s[keyend] == ':')
                keyend++;
            while (keyend < len && s[keyend] <= ' ')
                keyend++;
        }
        String v;
        if (keyend >= len)
            v = new String();
        else
            v = String.copyValueOf(s, keyend, len - keyend);

        add(k, v.trim());
    }
}

From source file:org.commoncrawl.io.shared.NIOHttpHeaders.java

/** Parse and merge a MIME header from an input stream. */
public void mergeHeader(Reader reader) throws java.io.IOException {
    if (reader == null)
        return;//from  w w w.jav a 2 s. c  o m
    char s[] = new char[10];
    int firstc = reader.read();
    while (firstc != '\n' && firstc != '\r' && firstc >= 0) {
        int len = 0;
        int keyend = -1;
        int c;
        boolean inKey = firstc > ' ';
        s[len++] = (char) firstc;
        parseloop: {
            while ((c = reader.read()) > 0) {
                switch (c) {
                case ':':
                    if (inKey && len > 0)
                        keyend = len;
                    inKey = false;
                    break;
                case '\t':
                    c = ' ';
                case ' ':
                    inKey = false;
                    break;
                case '\r':
                case '\n':
                    firstc = reader.read();
                    if (c == '\r' && firstc == '\n') {
                        firstc = reader.read();
                        if (firstc == '\r')
                            firstc = reader.read();
                    }
                    if (firstc == '\n' || firstc == '\r' || firstc > ' ')
                        break parseloop;
                    /* continuation */
                    c = ' ';
                    break;
                }
                if (len >= s.length) {
                    char ns[] = new char[s.length * 2];
                    System.arraycopy(s, 0, ns, 0, len);
                    s = ns;
                }
                s[len++] = (char) c;
            }
            firstc = -1;
        }
        while (len > 0 && s[len - 1] <= ' ')
            len--;
        String k;
        if (keyend <= 0) {
            k = null;
            keyend = 0;
        } else {
            k = String.copyValueOf(s, 0, keyend);
            if (keyend < len && s[keyend] == ':')
                keyend++;
            while (keyend < len && s[keyend] <= ' ')
                keyend++;
        }
        String v;
        if (keyend >= len)
            v = new String();
        else
            v = String.copyValueOf(s, keyend, len - keyend);

        add(k, v.trim());
    }
}

From source file:uk.ac.soton.itinnovation.experimedia.arch.ecc.configRegistry.api.ECCConfigAPIImpl.java

@Override
public String getDocument(String filePath) throws Exception {

    if (filePath == null) {
        throw new Exception("The file path is invalid");
    } else {//  w w w  . j a  va2s .  c o  m

        try {
            String fileURL = "" + apiRepositoryUrl + filePath;

            if (projectExists(fileURL)) {
                Sardine method = SardineFactory.begin(apiUserName, apiPassword);
                InputStream is = method.get(fileURL);
                BufferedReader i = new BufferedReader(new InputStreamReader(is, "8859_1"));

                String resource = "";
                int numBytes;
                char[] buff = new char[512];

                while ((numBytes = i.read(buff)) != -1) {
                    resource += String.copyValueOf(buff, 0, numBytes);
                }
                return resource;
            } else {
                throw new Exception("The project configuration file does not exist");
            }

        } catch (IOException ioe) {
            String error = "Could not retrieve the document because : " + ioe.getMessage();
            throw new Exception(error, ioe);
        }

    }
}

From source file:org.kuali.kfs.sys.document.service.impl.PaymentSourceHelperServiceImpl.java

/**
 * This method will take a word and simply chop into smaller
 * text segments that satisfy the limit requirements.  All words
 * brute force chopped, with no regard to preserving whole words.
 *
 * For example:/*from   w  w w.ja  va 2s .c  o  m*/
 *
 *      "Java is a fun programming language!"
 *
 * Might be chopped into:
 *
 *      "Java is a fun prog"
 *      "ramming language!"
 *
 * @param word The word that needs chopping
 * @param limit Number of character that should represent a chopped word
 * @return String [] of chopped words
 */
protected String[] chopWord(String word, int limit) {
    StringBuilder builder = new StringBuilder();
    if (word != null && word.trim().length() > 0) {

        char[] chars = word.toCharArray();
        int index = 0;

        // First process all the words that fit into the limit.
        for (int i = 0; i < chars.length / limit; i++) {
            builder.append(String.copyValueOf(chars, index, limit));
            builder.append("\n");

            index += limit;
        }

        // Not all words will fit perfectly into the limit amount, so
        // calculate the modulus value to determine any remaining characters.
        int modValue = chars.length % limit;
        if (modValue > 0) {
            builder.append(String.copyValueOf(chars, index, modValue));
        }

    }

    // Split the chopped words into individual segments.
    return builder.toString().split("\\n");
}

From source file:pt.ubi.di.pdm.swipe.CollectionDemoActivity.java

public static String ReadBtn(Context ctx, String file) {
    //reading text from file
    InputStreamReader InputRead = null;
    String s = "";
    try {//from   w w w  .  j  a v  a 2s. c om
        FileInputStream fileIn = ctx.openFileInput(file);
        InputRead = new InputStreamReader(fileIn);

        char[] inputBuffer = new char[100];

        int charRead;

        while ((charRead = InputRead.read(inputBuffer)) > 0) {
            // char to string conversion
            String readstring = String.copyValueOf(inputBuffer, 0, charRead);
            s += readstring;
        }

        //Toast.makeText(ctx, s,Toast.LENGTH_SHORT).show();

    } catch (Exception e) {
        Toast.makeText(ctx, "Nao consegui carregar ficheiro", Toast.LENGTH_SHORT).show();
        //e.printStackTrace();
    } finally {
        if (InputRead != null) {
            try {
                InputRead.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return s;
    }
}

From source file:com.opensmile.maven.EmoRecService.java

private File cutAudio(File file, String startTime, String duration, double d) {
    File F = new File(file + "_p" + ((Double) d).toString() + ".wav");
    try {/*from   www .j  ava  2s. com*/
        if (F.exists())
            F.delete();
        String durationStr = "";
        if (startTime.startsWith(".")) {
            startTime = startTime + " ";
            startTime = "0" + String.copyValueOf(startTime.toCharArray(), 0, startTime.length() - 1);
        }
        if (startTime.compareTo("-1") == 0)
            startTime = "0";
        if (duration.compareTo("-1") != 0)
            durationStr = " -t " + duration;
        if (durationStr.startsWith(".")) {
            durationStr = durationStr + " ";
            durationStr = "0" + String.copyValueOf(durationStr.toCharArray(), 0, durationStr.length() - 1);
        }
        Process p = Runtime.getRuntime()
                .exec("avconv" + " -i " + file + " -acodec copy " + " -ac 1 -ss " + startTime + // start
                        durationStr + // duration
                        " " + F.toString());
        p.waitFor();
        p = Runtime.getRuntime().exec("qwavheaderdump -q -F " + F.toString());// Fixing header
        p.waitFor();
    } catch (IOException | InterruptedException e) {
        e.printStackTrace();
    }
    return F;
}

From source file:org.kuali.kfs.fp.batch.service.impl.DisbursementVoucherExtractServiceImpl.java

/**
 * This method will take a word and simply chop into smaller
 * text segments that satisfy the limit requirements.  All words
 * brute force chopped, with no regard to preserving whole words.
 *
 * For example:// w  w w.  ja  v  a2s.  c  om
 *
 *      "Java is a fun programming language!"
 *
 * Might be chopped into:
 *
 *      "Java is a fun prog"
 *      "ramming language!"
 *
 * @param word The word that needs chopping
 * @param limit Number of character that should represent a chopped word
 * @return String [] of chopped words
 */
private String[] chopWord(String word, int limit) {
    StringBuilder builder = new StringBuilder();
    if (word != null && word.trim().length() > 0) {

        char[] chars = word.toCharArray();
        int index = 0;

        // First process all the words that fit into the limit.
        for (int i = 0; i < chars.length / limit; i++) {
            builder.append(String.copyValueOf(chars, index, limit));
            builder.append("\n");

            index += limit;
        }

        // Not all words will fit perfectly into the limit amount, so
        // calculate the modulus value to determine any remaining characters.
        int modValue = chars.length % limit;
        if (modValue > 0) {
            builder.append(String.copyValueOf(chars, index, modValue));
        }

    }

    // Split the chopped words into individual segments.
    return builder.toString().split("\\n");
}