Example usage for java.lang CharSequence toString

List of usage examples for java.lang CharSequence toString

Introduction

In this page you can find the example usage for java.lang CharSequence toString.

Prototype

public String toString();

Source Link

Document

Returns a string containing the characters in this sequence in the same order as this sequence.

Usage

From source file:Main.java

/**
 * Writes chars from a <code>CharSequence</code> to a <code>Writer</code>.
 * /*from   w  ww  .  ja v a 2  s.  co  m*/
 * @param data  the <code>CharSequence</code> to write, null ignored
 * @param output  the <code>Writer</code> to write to
 * @throws NullPointerException if output is null
 * @throws IOException if an I/O error occurs
 * @since Commons IO 2.0
 */
public static void write(CharSequence data, Writer output) throws IOException {
    if (data != null) {
        write(data.toString(), output);
    }
}

From source file:Main.java

/**
 * Writes chars from a <code>CharSequence</code> to bytes on an
 * <code>OutputStream</code> using the default character encoding of the
 * platform.//  w  w  w  .  j av a 2 s . c  o  m
 * <p>
 * This method uses {@link String#getBytes()}.
 * 
 * @param data  the <code>CharSequence</code> to write, null ignored
 * @param output  the <code>OutputStream</code> to write to
 * @throws NullPointerException if output is null
 * @throws IOException if an I/O error occurs
 * @since Commons IO 2.0
 */
public static void write(CharSequence data, OutputStream output) throws IOException {
    if (data != null) {
        write(data.toString(), output);
    }
}

From source file:Main.java

public static String escapeXml(CharSequence str) {
    if (str == null) {
        return null;
    }//from  w  w  w .jav  a 2  s  . c om
    StringBuilder res = null;
    int strLength = str.length();
    for (int i = 0; i < strLength; i++) {
        char c = str.charAt(i);
        String repl = encodeXMLChar(c);
        if (repl == null) {
            if (res != null) {
                res.append(c);
            }
        } else {
            if (res == null) {
                res = new StringBuilder(str.length() + 5);
                for (int k = 0; k < i; k++) {
                    res.append(str.charAt(k));
                }
            }
            res.append(repl);
        }
    }
    return res == null ? str.toString() : res.toString();
}

From source file:it.unimi.di.big.mg4j.document.SimpleCompressedDocumentCollection.java

private static EliasFanoMonotoneLongBigList loadOffsetsSuccinctly(final CharSequence filename,
        final long numberOfItems, final long upperBound) throws IOException {
    final InputBitStream ibs = new InputBitStream(filename.toString());
    final EliasFanoMonotoneLongBigList offsets = new EliasFanoMonotoneLongBigList(numberOfItems + 1, upperBound,
            new OffsetsLongIterator(ibs, numberOfItems + 1));
    ibs.close();//from  w ww . j a v  a 2s  .c  o  m
    return offsets;
}

From source file:Main.java

/**
 * Writes chars from a <code>CharSequence</code> to bytes on an
 * <code>OutputStream</code> using the specified character encoding.
 * <p>//from  w  w  w. jav  a2s. c  o  m
 * Character encoding names can be found at
 * <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
 * <p>
 * This method uses {@link String#getBytes(String)}.
 * 
 * @param data  the <code>CharSequence</code> to write, null ignored
 * @param output  the <code>OutputStream</code> to write to
 * @param encoding  the encoding to use, null means platform default
 * @throws NullPointerException if output is null
 * @throws IOException if an I/O error occurs
 * @since Commons IO 2.0
 */
public static void write(CharSequence data, OutputStream output, String encoding) throws IOException {
    if (data != null) {
        write(data.toString(), output, encoding);
    }
}

From source file:com.heliosapm.mws.server.net.json.JSONRequest.java

/**
 * Creates a new JSONRequest//from w  ww.  j  av  a2s . c  om
 * @param channel The channel the request came in on
 * @param jsonContent The json content to build the request from
 * @return a new JSONRequest
 */
public static JSONRequest newJSONRequest(Channel channel, CharSequence jsonContent) {
    if (jsonContent == null || jsonContent.toString().trim().isEmpty())
        throw new IllegalArgumentException("The passed json content was null or empty");
    try {
        JsonNode jsonNode = jsonMapper.readTree(jsonContent.toString().trim());
        return new JSONRequest(channel, jsonNode.get("t").asText(), jsonNode.get("rid").asLong(-1L), -1L,
                jsonNode.get("svc").asText(), jsonNode.get("op").asText(), jsonNode);
    } catch (Exception e) {
        throw new RuntimeException("Failed to parse JsonNode from passed string [" + jsonContent + "]", e);
    }
}

From source file:com.taobao.android.object.DexDiffInfo.java

private static String getParamsType(List<? extends CharSequence> parameterTypes) {
    StringBuilder params = new StringBuilder();
    for (CharSequence charSequence : parameterTypes) {
        boolean isArray = false;
        String s = null;/*from   w w  w.  j  ava2s.c o m*/
        if (charSequence.toString().startsWith("[")) {
            s = charSequence.subSequence(1, charSequence.length()).toString();
            isArray = true;
        } else {
            s = charSequence.toString();
        }
        if (!APatchTool.mappingMap.containsValue(s)) {
            params.append(isArray ? "[" + s + "|" : s + "|");
            continue;
        } else {
            for (Map.Entry<String, String> entry : APatchTool.mappingMap.entrySet()) {
                if (entry.getValue().equals(charSequence.toString())) {
                    params.append(isArray ? "[" + entry.getKey() + "|" : entry.getKey() + "|");
                }
            }

        }
    }
    if (params.length() > 1) {
        return "[" + params.substring(0, params.length() - 1).toString() + "]";
    } else {
        return "[" + params.toString() + "]";
    }
}

From source file:com.liferay.events.global.mobile.Utils.java

/**
 * Calculates the number of characters from the beginning of the strings that match exactly one-to-one,
 * up to a maximum of four (4) characters.
 *
 * @param first  The first string.//from w w  w. j  a va  2s .  c o  m
 * @param second The second string.
 * @return A number between 0 and 4.
 */
private static int commonPrefixLength(final CharSequence first, final CharSequence second) {
    final int result = StringUtils.getCommonPrefix(new String[] { first.toString(), second.toString() })
            .length();

    // Limit the result to 4.
    return result > 4 ? 4 : result;
}

From source file:jp.co.ctc_g.jse.core.validation.util.Validators.java

/**
 * Date?????//www  . j  a  v  a  2s  .c  o  m
 * @param suspect 
 * @param pattern ??
 * @param throwing true????????
 * @return 
 */
public static Date toDate(CharSequence suspect, String pattern, boolean throwing) {
    Date value = null;
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        sdf.setLenient(false);
        value = sdf.parse(suspect.toString());
    } catch (ParseException e) {
        L.debug("??({})????????????????",
                new Object[] { suspect });
        if (throwing) {
            throw new IllegalArgumentException(e);
        }
    }
    return value;
}

From source file:edu.cornell.med.icb.goby.modes.AbstractAlignmentToCompactMode.java

public static int getTargetIndex(final IndexedIdentifier targetIds, final CharSequence targetIdentifier,
        final boolean thirdPartyInput) {
    int targetIndex = -1;
    try {//w  w w .  j  av  a  2 s.  c o  m
        if (thirdPartyInput) {
            targetIndex = targetIds.registerIdentifier(new MutableString(targetIdentifier));
        } else {
            targetIndex = Integer.parseInt(targetIdentifier.toString());
        }
    } catch (NumberFormatException e) {
        if (targetIds != null) {
            final Integer object = targetIds.get(targetIdentifier);
            if (object == null) {
                LOG.warn("Input file contains a target id that is not defined in the target compact reads: "
                        + targetIdentifier);
                targetIndex = targetIds.registerIdentifier(new MutableString(targetIdentifier));
            } else {
                targetIndex = object;
            }
            if (targetIndex == -1) {
                System.out.println("Cannot convert reference identifier to index. " + targetIdentifier);
                System.exit(1);
            }
        }
    }
    return targetIndex;
}