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:io.coala.config.YamlUtil.java

/**
 * @param yamlContent the YAML-formatted tree
 * @param baseKeys the base keys for all imported property keys
 * @return a flat {@link Properties} mapping
 * @throws IOException/*from   w w  w . ja v a  2 s. c  o m*/
 */
public static Properties flattenYaml(final CharSequence yamlContent, final CharSequence... baseKeys)
        throws IOException {
    return ConfigUtil.flatten(getYamlMapper().readTree(yamlContent.toString()), baseKeys);
}

From source file:Main.java

public static void write(CharSequence data, Writer output) throws IOException {
    if (data != null)
        output.write(data.toString());
}

From source file:com.simiacryptus.mindseye.applications.HadoopUtil.java

/**
 * Get data byte [ ]./*  w ww  .  j  ava  2 s.  c  o  m*/
 *
 * @param file the file
 * @return the byte [ ]
 */
public static byte[] getData(final CharSequence file) {
    FileSystem fileSystem = getFileSystem(file);
    Path path = new Path(file.toString());
    try {
        if (!fileSystem.exists(path))
            throw new IllegalArgumentException("Not Found: " + path);
        try (FSDataInputStream open = fileSystem.open(path)) {
            return IOUtils.toByteArray(open);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static void write(CharSequence data, OutputStream output) throws IOException {
    if (data != null)
        output.write(data.toString().getBytes());
}

From source file:Main.java

public static String getAppName(Context context, Intent appIntent) {

    if (appIntent.hasExtra(Intent.EXTRA_SHORTCUT_NAME)) {
        return appIntent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    }//from w  w w  .j av a  2  s.c o  m

    if (appIntent.hasExtra(Intent.EXTRA_SHORTCUT_INTENT)) {
        appIntent = appIntent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    }
    ComponentName componentName = appIntent.getComponent();

    PackageManager pm = context.getPackageManager();

    ApplicationInfo appInfo = null;
    ActivityInfo activityInfo = null;
    try {
        appInfo = pm.getApplicationInfo(componentName.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        appInfo = null;
    }
    try {
        activityInfo = pm.getActivityInfo(componentName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    if (appInfo == null) {
        return null;
    } else {
        CharSequence appName = pm.getApplicationLabel(appInfo);
        CharSequence activityName = null;

        if (activityInfo != null) {
            activityName = activityInfo.loadLabel(pm);
        }

        if (activityName != null) {
            return activityName.toString();
        }

        if (appName != null) {
            appName.toString();
        }

        return null;
    }
}

From source file:Main.java

public static InputStream toInputStream(CharSequence input, String encoding)
        throws UnsupportedEncodingException {
    byte[] bytes = input.toString().getBytes(encoding);
    return new ByteArrayInputStream(bytes);
}

From source file:Main.java

/**
 * Shows a Dialog with a title, a message, a EditText and two Buttons for OK
 * and Cancel. The user can't click OK when the EditText is empty.
 *
 * @param context/*from www  .j a  v  a 2 s .  c o  m*/
 *            The Context of the calling Activity
 * @param title
 *            Title of the Dialog
 * @param message
 *            Message of the Dialog
 * @param inputEditText
 *            The EditText used for this Dialog. You can modify it for
 *            example by setting the input type before passing it to this
 *            method. You can also read the text from the calling method.
 * @param onOkClickListener
 *            The Listener for clicking on the OK button.
 */
public static void showDialog(Context context, String title, String message, EditText inputEditText,
        DialogInterface.OnClickListener onOkClickListener) {

    AlertDialog.Builder alert = new AlertDialog.Builder(context);
    alert.setTitle(title);
    alert.setMessage(message);
    alert.setView(inputEditText);

    /*
     * OK button
     */
    alert.setPositiveButton(context.getString(android.R.string.ok), onOkClickListener);
    /*
     * Cancel button
     */
    alert.setNegativeButton(context.getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            /*
             * Canceled.
             */
        }
    });

    final AlertDialog dialog = alert.show();
    if (dialog != null) {
        /*
         * Disable ok button.
         */
        dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
        /*
         * Dis- and enable , dependent on the text entered
         */
        inputEditText.addTextChangedListener(new TextWatcher() {
            /**
             * Enable OK button if text entered, disable otherwise.
             */
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                dialog.getButton(DialogInterface.BUTTON_POSITIVE)
                        .setEnabled(!s.toString().equals("") && isValideUrl(s.toString()));
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            public void afterTextChanged(Editable s) {
            }
        });
    }
}

From source file:Main.java

public static void write(CharSequence data, OutputStream output, String encoding) throws IOException {
    if (data != null)
        output.write(data.toString().getBytes(encoding));
}

From source file:com.simiacryptus.mindseye.applications.HadoopUtil.java

/**
 * Gets files.//from ww w.j  av  a  2 s.c o  m
 *
 * @param file the file
 * @return the files
 */
public static List<CharSequence> getFiles(CharSequence file) {
    try {
        FileSystem fileSystem = getFileSystem(file);
        Path path = new Path(file.toString());
        if (!fileSystem.exists(path))
            throw new IllegalStateException(path + " does not exist");
        List<CharSequence> collect = toStream(fileSystem.listFiles(path, false)).map(FileStatus::getPath)
                .map(Path::toString).collect(Collectors.toList());
        collect.stream().forEach(child -> {
            try {
                if (!fileSystem.exists(new Path(child.toString())))
                    throw new IllegalStateException(child + " does not exist");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
        return collect;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:hrytsenko.csv.IO.java

static Charset getCharset(Map<String, ?> args) {
    CharSequence charsetName = (CharSequence) args.get("charset");

    return charsetName != null ? Charset.forName(charsetName.toString()) : UTF_8;
}