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:fr.landel.utils.commons.exception.AbstractRuntimeException.java

/**
 * Constructor. To format the message, this method uses
 * {@link String#format} function./*from  w w  w  . j av a2  s . c om*/
 *
 * @param cause
 *            the cause
 * @param enableSuppression
 *            whether or not suppression is enabled or disabled
 * @param writableStackTrace
 *            whether or not the stack trace should be writable
 * @param locale
 *            message locale
 * @param message
 *            message
 * @param arguments
 *            message arguments
 */
protected AbstractRuntimeException(final Throwable cause, final boolean enableSuppression,
        final boolean writableStackTrace, final Locale locale, final CharSequence message,
        final Object... arguments) {
    super(ArrayUtils.isNotEmpty(arguments) ? String.format(locale, message.toString(), arguments)
            : message.toString(), cause, enableSuppression, writableStackTrace);
}

From source file:fr.landel.utils.commons.exception.AbstractException.java

/**
 * Constructor. (inverse parameter order to keep compatibility with standard
 * signature)/*from ww w  .j  av a 2 s . c  om*/
 *
 * @param message
 *            The message
 * @param cause
 *            the cause
 * @param enableSuppression
 *            whether or not suppression is enabled or disabled
 * @param writableStackTrace
 *            whether or not the stack trace should be writable
 */
protected AbstractException(final CharSequence message, final Throwable cause, final boolean enableSuppression,
        final boolean writableStackTrace) {
    super(message.toString(), cause, enableSuppression, writableStackTrace);
}

From source file:fr.landel.utils.commons.exception.AbstractRuntimeException.java

/**
 * Constructor. (inverse parameter order to keep compatibility with standard
 * signature)//  w  ww  .j  a  va2  s  . c o m
 *
 * @param message
 *            The message
 * @param cause
 *            the cause
 * @param enableSuppression
 *            whether or not suppression is enabled or disabled
 * @param writableStackTrace
 *            whether or not the stack trace should be writable
 */
protected AbstractRuntimeException(final CharSequence message, final Throwable cause,
        final boolean enableSuppression, final boolean writableStackTrace) {
    super(message.toString(), cause, enableSuppression, writableStackTrace);
}

From source file:cn.org.once.cstack.utils.CustomPasswordEncoder.java

@Override
public String encode(CharSequence sequence) {
    Cipher cipher;//from  w  w  w .j  a v a  2s . c om
    String encryptedString = null;
    try {
        cipher = Cipher.getInstance(ALGO);
        cipher.init(Cipher.ENCRYPT_MODE, generateKey());
        encryptedString = Base64.encodeBase64String(cipher.doFinal(sequence.toString().getBytes()));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return encryptedString;
}

From source file:eu.edisonproject.training.wsd.WikipediaOnline.java

private Set<Term> queryTerms(String jsonString, String originalTerm)
        throws ParseException, IOException, MalformedURLException, InterruptedException, ExecutionException {
    Set<Term> terms = new HashSet<>();
    Set<Term> termsToReturn = new HashSet<>();
    JSONObject jsonObj = (JSONObject) JSONValue.parseWithException(jsonString);
    JSONObject query = (JSONObject) jsonObj.get("query");
    JSONObject pages = (JSONObject) query.get("pages");
    Set<String> keys = pages.keySet();
    for (String key : keys) {
        JSONObject jsonpage = (JSONObject) pages.get(key);
        Term t = TermFactory.create(jsonpage, originalTerm);
        if (t != null) {
            terms.add(t);/* w w  w. j  a  va2s  .  c o m*/
        }
    }
    if (terms.size() > 0) {
        Map<CharSequence, List<CharSequence>> cats = getCategories(terms);
        for (Term t : terms) {
            boolean add = true;
            List<CharSequence> cat = cats.get(t.getUid());
            t.setCategories(cat);
            for (CharSequence g : t.getGlosses()) {
                if (g != null && g.toString().contains("may refer to:")) {
                    Set<Term> referToTerms = getReferToTerms(g.toString(), originalTerm);
                    if (referToTerms != null) {
                        for (Term rt : referToTerms) {
                            String url = "https://en.wikipedia.org/?curid=" + rt.getUid();
                            rt.setUrl(url);
                            termsToReturn.add(rt);
                        }
                    }
                    add = false;
                    break;
                }
            }
            if (add) {
                String url = "https://en.wikipedia.org/?curid=" + t.getUid();
                t.setUrl(url);
                termsToReturn.add(t);
            }
        }
    }
    return termsToReturn;
}

From source file:com.sunchenbin.store.feilong.core.lang.StringUtil.java

/**
 * [?]:?(<code>text</code> <code>lastString</code>).
 *
 * @param text/*from w  w w.  ja v  a2 s. com*/
 *            the text
 * @param lastString
 *            the last string
 * @return the string
 * @since 1.4.0
 */
public static String substringWithoutLast(final CharSequence text, final String lastString) {
    if (Validator.isNullOrEmpty(text)) {
        return StringUtils.EMPTY;
    }

    //?,??nullempty,?,,,????
    String returnValue = text.toString();
    if (Validator.isNullOrEmpty(lastString)) {
        return returnValue;
    }

    if (returnValue.endsWith(lastString)) {
        //?
        return substringWithoutLast(returnValue, lastString.length());
    }
    return returnValue;
}

From source file:com.huguesjohnson.segacdcollector.EbayUtils.java

private String getRequestURL(String keyword) {
    CharSequence requestURL = TextUtils.expandTemplate(requestTemplate, ebayURL, appID, keyword);
    return (requestURL.toString());
}

From source file:fr.inria.ucn.collectors.RunningAppsCollector.java

@SuppressLint("NewApi")
@Override/* w  ww.  j  av  a  2s  .com*/
public void run(Context c, long ts) {
    try {
        ActivityManager am = (ActivityManager) c.getSystemService(Context.ACTIVITY_SERVICE);
        PackageManager pm = c.getPackageManager();

        JSONObject data = new JSONObject();

        // running tasks
        JSONArray runTaskArray = new JSONArray();
        List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(50);
        boolean first = true;
        for (ActivityManager.RunningTaskInfo info : taskInfo) {
            JSONObject jinfo = new JSONObject();
            jinfo.put("task_id", info.id);
            jinfo.put("task_num_activities", info.numActivities);
            jinfo.put("task_num_running", info.numRunning);

            // is this the foreground process ?
            jinfo.put("task_foreground", first);
            if (first) {
                first = false;
            }

            if (info.topActivity != null) {
                jinfo.put("task_top_class_name", info.topActivity.getClassName());
                jinfo.put("task_top_package_name", info.topActivity.getPackageName());
                try {
                    // map package name to app label
                    CharSequence appLabel = pm.getApplicationLabel(pm.getApplicationInfo(
                            info.topActivity.getPackageName(), PackageManager.GET_META_DATA));
                    jinfo.put("task_app_label", appLabel.toString());
                } catch (NameNotFoundException e) {
                }
            }

            runTaskArray.put(jinfo);
        }
        data.put("runningTasks", runTaskArray);

        // processes
        JSONArray runProcArray = new JSONArray();
        for (ActivityManager.RunningAppProcessInfo pinfo : am.getRunningAppProcesses()) {
            JSONObject jinfo = new JSONObject();
            jinfo.put("proc_uid", pinfo.uid);
            jinfo.put("proc_name", pinfo.processName);
            jinfo.put("proc_packages", Helpers.getPackagesForUid(c, pinfo.uid));
            runProcArray.put(jinfo);
        }
        data.put("runningAppProcesses", runProcArray);

        // done
        Helpers.sendResultObj(c, "running_apps", ts, data);

    } catch (JSONException jex) {
        Log.w(Constants.LOGTAG, "failed to create json obj", jex);
    }
}

From source file:com.moviejukebox.tools.SearchEngineTools.java

private String requestContent(CharSequence cs) throws IOException {
    HttpGet httpGet = new HttpGet(cs.toString());
    httpGet.setHeader(HTTP.USER_AGENT,//w  w w.  ja v  a  2 s .c  om
            "Mozilla/6.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1");
    return httpClient.request(httpGet);
}

From source file:net.community.chest.gitcloud.facade.backend.git.BackendUploadPackFactory.java

@Override
public UploadPack create(final C request, Repository db)
        throws ServiceNotEnabledException, ServiceNotAuthorizedException {
    final File dir = db.getDirectory();
    final String logPrefix;
    if (request instanceof HttpServletRequest) {
        HttpServletRequest req = (HttpServletRequest) request;
        logPrefix = "create(" + req.getMethod() + ")[" + req.getRequestURI() + "][" + req.getQueryString()
                + "]";
    } else {/*from  w  ww .  j  a v a 2  s.co m*/
        logPrefix = "create(" + dir.getAbsolutePath() + ")";
    }
    if (logger.isDebugEnabled()) {
        logger.debug(logPrefix + ": " + dir.getAbsolutePath());
    }

    UploadPack up = new UploadPack(db) {
        @Override
        @SuppressWarnings("synthetic-access")
        public void upload(InputStream input, OutputStream output, OutputStream messages) throws IOException {
            InputStream effIn = input;
            OutputStream effOut = output, effMessages = messages;
            if (logger.isTraceEnabled()) {
                LineLevelAppender inputAppender = new LineLevelAppender() {
                    @Override
                    public void writeLineData(CharSequence lineData) throws IOException {
                        logger.trace(logPrefix + " upload(C): " + lineData);
                    }

                    @Override
                    public boolean isWriteEnabled() {
                        return true;
                    }
                };
                effIn = new TeeInputStream(effIn, new HexDumpOutputStream(inputAppender), true);

                LineLevelAppender outputAppender = new LineLevelAppender() {
                    @Override
                    public void writeLineData(CharSequence lineData) throws IOException {
                        logger.trace(logPrefix + " upload(S): " + lineData);
                    }

                    @Override
                    public boolean isWriteEnabled() {
                        return true;
                    }
                };
                effOut = new TeeOutputStream(effOut, new HexDumpOutputStream(outputAppender));

                if (effMessages != null) {
                    LineLevelAppender messagesAppender = new LineLevelAppender() {
                        @Override
                        public void writeLineData(CharSequence lineData) throws IOException {
                            logger.trace(logPrefix + " upload(M): " + lineData);
                        }

                        @Override
                        public boolean isWriteEnabled() {
                            return true;
                        }
                    };
                    // TODO review the decision to use an AsciiLineOutputStream here
                    effMessages = new TeeOutputStream(effMessages, new AsciiLineOutputStream(messagesAppender));
                }
            }

            super.upload(effIn, effOut, effMessages);
        }

        @Override
        @SuppressWarnings("synthetic-access")
        public void sendAdvertisedRefs(RefAdvertiser adv) throws IOException, ServiceMayNotContinueException {
            RefAdvertiser effAdv = adv;
            if (logger.isTraceEnabled() && (adv instanceof PacketLineOutRefAdvertiser)) {
                PacketLineOut pckOut = (PacketLineOut) ReflectionUtils.getField(pckOutField, adv);
                effAdv = new PacketLineOutRefAdvertiser(pckOut) {
                    private final PacketLineOut pckLog = new PacketLineOut( // TODO review the decision to use an AsciiLineOutputStream here
                            new AsciiLineOutputStream(new LineLevelAppender() {
                                @Override
                                public void writeLineData(CharSequence lineData) throws IOException {
                                    logger.trace(logPrefix + " S: " + lineData);
                                }

                                @Override
                                public boolean isWriteEnabled() {
                                    return true;
                                }
                            }));

                    @Override
                    protected void writeOne(CharSequence line) throws IOException {
                        String s = line.toString();
                        super.writeOne(s);
                        pckLog.writeString(s);
                    }

                    @Override
                    protected void end() throws IOException {
                        super.end();
                        pckLog.end();
                    }
                };
            }

            super.sendAdvertisedRefs(effAdv);
        }
    };
    up.setTimeout(uploadTimeoutValue);
    return up;
}