Example usage for java.lang RuntimeException RuntimeException

List of usage examples for java.lang RuntimeException RuntimeException

Introduction

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

Prototype

public RuntimeException(String message, Throwable cause) 

Source Link

Document

Constructs a new runtime exception with the specified detail message and cause.

Usage

From source file:Main.java

public static void setConfigSpec(String viewTag, String configSpecFilePath) {
    try {//from   w  w w.  ja  va2  s  .c  om
        Process pr = Runtime.getRuntime().exec("cleartool setcs -tag " + viewTag + " " + configSpecFilePath);
        pr.waitFor();
        pr.destroy();
    } catch (Exception e) {
        throw new RuntimeException("cleartool setcs error!", e);
    }

}

From source file:Main.java

public static String decode(String s) {
    if (s == null) {
        return "";
    }//from   w  w  w. j  ava 2 s .  c o  m
    try {
        return URLDecoder.decode(s, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:Main.java

public static Document createDocFromFile(String str) {

    try {/*from w ww. j  av  a  2  s  . c o  m*/
        return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(str));
    } catch (Throwable e) {
        throw new RuntimeException("Create docBuilder error", e);

    }
}

From source file:Main.java

/**
 * close inputStream/* ww w.  j av a 2s .c  o  m*/
 * 
 * @param s
 */
private static void closeInputStream(InputStream s) {
    if (s == null) {
        return;
    }

    try {
        s.close();
    } catch (IOException e) {
        throw new RuntimeException("IOException occurred. ", e);
    }
}

From source file:Main.java

private static File getTestDataDir() {
    // Search each parent directory looking for "src/google/protobuf".
    File ancestor = new File(".");
    try {/* w w  w.j  ava 2  s  . c  o  m*/
        ancestor = ancestor.getCanonicalFile();
    } catch (IOException e) {
        throw new RuntimeException("Couldn't get canonical name of working directory.", e);
    }
    while (ancestor != null && ancestor.exists()) {
        if (new File(ancestor, "src/google/protobuf").exists()) {
            return new File(ancestor, "src/google/protobuf/testdata");
        }
        ancestor = ancestor.getParentFile();
    }

    throw new RuntimeException("Could not find golden files.  This test must be run from within the "
            + "protobuf source package so that it can read test data files from the " + "C++ source tree.");
}

From source file:Main.java

public static String readFromFile(File file) {
    try (Reader in = new InputStreamReader(new FileInputStream(file), "UTF-8")) {
        char[] arr = new char[(int) file.length()];
        int len = in.read(arr);
        return new String(arr, 0, len);
    } catch (IOException ex) {
        throw new RuntimeException("Unable to read file " + file.getName(), ex);
    }/* ww  w.  j  av a 2s.  co m*/
}

From source file:Main.java

public static String md5(String string) {
    byte[] hash = null;
    try {//ww  w. j a v  a  2  s .c o m
        hash = string.getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("UTF-8 is not supported", e);
    }
    return computeMD5(hash);
}

From source file:Main.java

public static String utf8Encode(String str) {
    if (!isEmpty(str) && str.getBytes().length != str.length()) {
        try {/*  w ww.  j a  v  a  2  s.  c o  m*/
            return URLEncoder.encode(str, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UnsupportedEncodingException occurred. ", e);
        }
    }
    return str;
}

From source file:Main.java

public static String md5(String string) {
    if (string == null || string.trim().length() < 1) {
        return null;
    }//from   ww w.jav  a 2  s.  c  om
    try {
        return getMD5(string.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:Main.java

public static String getMD5Str(String md5Str) {
    byte[] hash;//w  ww  .  j  a va2  s  . co  m
    try {
        hash = MessageDigest.getInstance("MD5").digest(md5Str.getBytes("UTF-8"));
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException("Huh, MD5 should be supported?", e);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException("Huh, UTF-8 should be supported?", e);
    }

    StringBuilder hex = new StringBuilder(hash.length * 2);
    for (byte b : hash) {
        if ((b & 0xFF) < 0x10)
            hex.append("0");
        hex.append(Integer.toHexString(b & 0xFF));
    }
    return hex.toString();
}