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:de.csw.ontology.XWikiTextEnhancer.java

/**
 * The enhanced text contains links to the Lucene search page of the xWiki
 * system. The search terms are related to the annotated phrase.
 *//*from   w ww .  j  a  v  a  2s  .c om*/
public String enhance(String text) {
    CSWGermanAnalyzer ga = new CSWGermanAnalyzer();
    TokenStream ts = null;
    StringBuilder result = new StringBuilder();

    initializeLinkIndex(text);

    try {
        Reader r = new BufferedReader(new StringReader(text));

        ts = ga.tokenStream("", r);

        CharTermAttribute charTermAttribute = ts.addAttribute(CharTermAttribute.class);
        OffsetAttribute offsetAttribute = ts.addAttribute(OffsetAttribute.class);
        TypeAttribute typeAttribute = ts.addAttribute(TypeAttribute.class);

        String term;
        int lastEndIndex = 0;

        while (ts.incrementToken()) {

            result.append(text.substring(lastEndIndex, offsetAttribute.startOffset()));
            term = String.copyValueOf(charTermAttribute.buffer(), 0, charTermAttribute.length());

            if (typeAttribute.type().equals(ConceptFilter.CONCEPT_TYPE) && isAnnotatable(offsetAttribute)) {
                log.debug("Annotating concept: " + term);
                annotateWithSearch(result,
                        text.substring(offsetAttribute.startOffset(), offsetAttribute.endOffset()), term);
            } else {
                result.append(text.substring(offsetAttribute.startOffset(), offsetAttribute.endOffset()));
            }

            lastEndIndex = offsetAttribute.endOffset();
        }
        result.append(text.subSequence(lastEndIndex, text.length()));
    } catch (IOException e) {
        Log.error("Error while processing the page content", e);
    }

    ga.close();
    return result.toString();
}

From source file:org.nuxeo.theme.presets.PhotoshopPaletteParser.java

public static Map<String, String> parse(byte[] bytes) {
    Map<String, String> entries = new LinkedHashMap<String, String>();
    ByteArrayInputStream is = new ByteArrayInputStream(bytes);
    DataInputStream dis = new DataInputStream(is);

    char[] words = new char[bytes.length];
    int size = 0;
    while (true) {
        try {//from   w w w . j  a  va2s .c  o  m
            words[size] = dis.readChar();
            size++;
        } catch (Exception e) {
            break;
        }
    }

    try {
        is.close();
        dis.close();
    } catch (IOException e) {
        log.error(e, e);
    }

    int offset = 1;
    int version = words[0] & 0xffff;
    int nc = words[1] & 0xffff;

    // get version 2 if it exists
    if (version == 1 && size > nc * 5 + 2) {
        offset += nc * 5 + 2;
        version = words[offset - 1] & 0xffff;
        nc = words[offset] & 0xffff;
    }

    if (version == 1) {
        log.debug("Found ACO v1 color file (Photoshop < 7.0)");
    } else if (version == 2) {
        log.debug("Found ACO v2 color file (Photoshop >= 7.0)");
    } else {
        log.error("Unknown ACO file version: " + version);
        return entries;
    }

    log.debug("Found " + nc + " colors.");

    int counter = 1;
    for (int j = 0; j < nc; j++) {
        String value = null;
        int colorSpace = words[offset + 1] & 0xff;
        int w = words[offset + 2] & 0xffff;
        int x = words[offset + 3] & 0xffff;
        int y = words[offset + 4] & 0xffff;
        int z = words[offset + 5] & 0xffff;

        if (colorSpace == RGB) {
            value = rgbToHex(w / 256, x / 256, y / 256);

        } else if (colorSpace == HSB) {
            float hue = w / 65535F; // [0.0-1.0]
            float saturation = x / 65535F; // [0.0-1.0]
            float brightness = y / 65535F; // [0.0-1.0]
            Color color = Color.getHSBColor(hue, saturation, brightness);
            value = rgbToHex(color.getRed(), color.getGreen(), color.getBlue());

        } else if (colorSpace == CMYK) {
            float cyan = 1F - w / 65535F; // [0.0-1.0]
            float magenta = 1F - x / 65535F; // [0.0-1.0]
            float yellow = 1F - y / 65535F; // [0.0-1.0]
            float black = 1F - z / 65535F; // [0.0-1.0]
            // TODO: do the conversion to RGB. An ICC profile is required.
            log.warn("Unsupported color space: CMYK");

        } else if (colorSpace == GRAYSCALE) {
            int gray = (int) (w * 256F / 10000F); // [0-256]
            value = rgbToHex(gray, gray, gray);

        } else if (colorSpace == LAB) {
            float l = w / 100F;
            float a = x / 100F;
            float b = y / 100F;
            // TODO: do the conversion to RGB. An ICC profile is required.
            log.warn("Unsupported color space: CIE Lab");

        } else if (colorSpace == WIDE_CMYK) {
            float cyan = w / 10000F; // [0.0-1.0]
            float magenta = x / 10000F; // [0.0-1.0]
            float yellow = y / 10000F; // [0.0-1.0]
            float black = z / 10000F; // [0.0-1.0]
            // TODO: do the conversion to RGB. An ICC profile is required.
            log.warn("Unsupported color space: Wide CMYK");

        } else {
            log.warn("Unknown color space: " + colorSpace);
        }

        String name = "";
        if (version == 1) {
            name = String.format("Color %s", counter);
        }

        else if (version == 2) {
            int len = (words[offset + 7] & 0xffff) - 1;
            name = String.copyValueOf(words, offset + 8, len);
            offset += len + 3;

            String n = name;
            int c = 2;
            while (entries.containsKey(n)) {
                n = String.format("%s %s", name, c);
                c++;
            }
            name = n;
        }

        if (value != null) {
            entries.put(name, value);
        }

        offset += 5;
        counter++;
    }

    return entries;
}

From source file:cd.what.DutchBot.AccessList.java

/**
 * Load the configuration/*from  w w w .ja v  a2  s  . c o m*/
 * 
 * @param configfile
 * @throws ConfigurationException
 * @throws FileNotFoundException
 */
public static void loadFromConfig(String configfile) throws ConfigurationException, FileNotFoundException {
    config.setAutoSave(true);
    config.setThrowExceptionOnMissing(true);
    config.setFileName(configfile);
    config.load();

    @SuppressWarnings("rawtypes")
    Iterator keys = config.getKeys("acl.user");
    while (keys.hasNext()) {
        String key = keys.next().toString();
        String host = key.substring("acl.user.".length()).toLowerCase();
        Privileges axx = Privileges.lookup((config.getInt(key)));
        accessList.put(host, axx);
    }
    keys = config.getKeys("acl.channel");
    while (keys.hasNext()) {
        String key = keys.next().toString();
        String channel = "#" + key.substring("acl.channel.".length()).toLowerCase();
        Privileges axx = Privileges.lookup(config.getInt(key));
        channelAccessList.put(channel, axx);
    }

    keys = config.getKeys("alias");
    while (keys.hasNext()) {
        String key = keys.next().toString();
        String host = String.copyValueOf(key.toCharArray(), 6, key.toString().length() - 6).toLowerCase();
        aliasList.put(host, config.getString(key));
    }

}

From source file:de.csw.lucene.ConceptFilter.java

/**
 * advances to the next token in the stream.
 * Takes into account that terms from the ontology might be constructed
 * out of several consecutive tokens.//from w w w . j a va2 s .c  o  m
 * @return false at EOS
 */
@Override
public boolean incrementToken() throws IOException {

    boolean hasMoreToken = innerNextToken();
    if (!hasMoreToken) {
        return false;
    }

    Queue<AttributeSource.State> lookAhead = new LinkedList<AttributeSource.State>();
    List<String> terms = new ArrayList<String>();
    terms.add(String.copyValueOf(charTermAttribute.buffer(), 0, charTermAttribute.length()));

    while (index.isPrefix(terms) && hasMoreToken) {
        lookAhead.add(captureState());
        hasMoreToken = innerNextToken();
        terms.add(String.copyValueOf(charTermAttribute.buffer(), 0, charTermAttribute.length()));
    }

    // if we have a match ...
    if (index.hasExactMatches(StringUtils.join(terms.toArray(), OntologyIndex.PREFIX_SEPARATOR))) {

        // ..then we consume all elements in the look ahead, if present
        if (!lookAhead.isEmpty()) {
            int maxEndOffset = offsetAttribute.endOffset();
            restoreState(lookAhead.poll());
            terms.remove(0); // already present in current token
            for (String term : terms) {
                charTermAttribute.append(OntologyIndex.PREFIX_SEPARATOR);
                charTermAttribute.append(term);
            }

            offsetAttribute.setOffset(offsetAttribute.startOffset(), maxEndOffset);
        }
        typeAttribute.setType(CONCEPT_TYPE);
        if (log.isTraceEnabled()) {
            log.trace("Concept token recognized: "
                    + String.copyValueOf(charTermAttribute.buffer(), 0, charTermAttribute.length()));
        }

    } else {

        // .. else we push back in the queue the tokens already read
        if (!lookAhead.isEmpty()) {
            lookAhead.add(captureState());
            restoreState(lookAhead.poll());
            for (AttributeSource.State laterToken : lookAhead) {
                queue.add(laterToken);
            }
        }
    }

    return hasMoreToken;
}

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

@Override
public String getConfigData(String component, String feature) throws Exception {
    if (component == null) {
        throw new Exception("Component is invalid");
    } else if (feature == null) {
        throw new Exception("Feature is not valid");
    } else {/*from www  .  j  av  a 2 s . c  o  m*/

        String componentUrl = "" + getProjectUrl() + "/" + component + "/" + feature + "/config.json";

        String configResource = "";

        if (projectExists(componentUrl)) {
            Sardine method = SardineFactory.begin(apiUserName, apiPassword);
            try {
                InputStream is = method.get(componentUrl);
                BufferedReader i = new BufferedReader(new InputStreamReader(is, "8859_1"));
                int numBytes;
                char[] buff = new char[512];

                while ((numBytes = i.read(buff)) != -1) {
                    configResource += String.copyValueOf(buff, 0, numBytes);
                }
            } catch (IOException ioe) {
                String error = "Could not get config data because: " + ioe.getMessage();
                throw new Exception(error, ioe);
            }
        } else {
            return "no_config";
        }

        return configResource;
    }
}

From source file:Ismap.java

public boolean addmap(String mapurl) {
    int linepos = 1;
    int streambyte;
    char localln[] = new char[80];
    try {/*from w  w w .ja va 2  s .  c om*/
        URL remotemap = new URL(mapurl);
        InputStream mapis = remotemap.openStream();
        do {
            streambyte = mapis.read();
            localln[linepos - 1] = (char) streambyte;
            if (localln[linepos - 1] == '\n') {
                this.mapdetail[numlines] = String.copyValueOf(localln, 0, linepos - 1);
                numlines++;
                linepos = 0;
            }
            linepos++;
        } while (streambyte != -1);
    } catch (java.net.MalformedURLException e) {
        System.out.println("Malformed URL! exception");
        return (false);
    } catch (java.io.IOException e) {
        System.out.println("Error reading from URL! exception");
        return (false);
    }
    return true;
}

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

protected void appendToChunkBoundaryBuffer(char[] chars, int start, int end) {
    if (chunkBoundaryBuffer != null) {
        chunkBoundaryBuffer = chunkBoundaryBuffer.concat(String.copyValueOf(chars, start, end));
    } else {//from  w  w w  . j  av a 2s . c o  m
        chunkBoundaryBuffer = String.copyValueOf(chars, start, end);
    }
}

From source file:com.seanmadden.net.fast.SerialInterface.java

public DataPacket getDataFromPort() {
    char[] arr = new char[255];
    try {/*from  w w w.j a v  a  2s  .com*/
        if (portIn.ready()) {
            int num = portIn.read(arr);
            buildBuf += String.copyValueOf(arr, 0, num);
            DataPacket pkt = new DataPacket(buildBuf);
            if (pkt.parseDataPacket() != null) {
                buildBuf = "";
                return pkt;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        buildBuf = "";
    }
    return null;
}

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

@Override
public String getDefaultConfigData(String component, String feature) throws Exception {
    if (component == null) {
        throw new Exception("Component is invalid");
    } else if (feature == null) {
        throw new Exception("Feature is not valid");
    } else {// w  ww  . j  a v  a  2 s  . co  m

        String componentUrl = "" + apiDefaultPath + "/" + component + "/" + feature + "/config.json";

        String configResource = "";

        if (projectExists(componentUrl)) {
            Sardine method = SardineFactory.begin(apiUserName, apiPassword);
            try {
                InputStream is = method.get(componentUrl);
                BufferedReader i = new BufferedReader(new InputStreamReader(is, "8859_1"));
                int numBytes;
                char[] buff = new char[512];

                while ((numBytes = i.read(buff)) != -1) {
                    configResource += String.copyValueOf(buff, 0, numBytes);
                }
            } catch (IOException ioe) {
                String error = "Could not get config data because: " + ioe.getMessage();
                throw new Exception(error, ioe);
            }
        } else {
            return "no_config";
        }

        return configResource;
    }

}

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

@Override
protected void jsonWriteRawValue(char[] chars, int i, int j) throws IOException {
    if (isZValue()) {
        zCounter++;/*from w ww .  j  av a2s .co  m*/
    } else {
        coordinateBuffer[counter - 1 - zCounter] = Double.parseDouble(String.copyValueOf(chars, i, j));
    }
}