List of usage examples for java.lang IllegalStateException IllegalStateException
public IllegalStateException(String message, Throwable cause)
From source file:Main.java
public static void sleepMillis(int milliseconds) { try {//from w ww. ja v a 2s . c o m Thread.sleep(milliseconds); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IllegalStateException("Interrupted sleeping", e); } }
From source file:Main.java
public static byte[] stringToBytes(String string) { try {/* w w w .ja v a2 s .c om*/ return string.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("UTF8 not supported", e); } }
From source file:Main.java
public static <T> T fromJson(@NonNull String content, @NonNull Class<T> clazz) throws IllegalStateException { try {/* ww w. j a va2 s . c om*/ return sGson.fromJson(content, clazz); } catch (JsonSyntaxException e) { throw new IllegalStateException(JSON_PARSE_ERROR + content, e); } }
From source file:Main.java
public static int getContentAsInt(Node n) { String content = getContent(n).trim(); try {// w w w . j a v a2 s . c om return Integer.parseInt(content); } catch (NumberFormatException e) { throw new IllegalStateException("Cannot get number from '" + content + "' (" + format(n, 0) + ")", e); } }
From source file:com.netflix.spinnaker.clouddriver.artifacts.CredentialReader.java
public static String credentialsFromFile(String filename) { try {/* ww w . j a v a2 s . co m*/ String credentials = FileUtils.readFileToString(new File(filename)); return credentials.replace("\n", ""); } catch (IOException e) { throw new IllegalStateException("Could not read credentials file: " + filename, e); } }
From source file:Main.java
/** * Invokes the Cipher to perform encryption or decryption (depending on the initialized mode). *///from w w w. ja va 2 s .co m public static byte[] doFinal(Cipher cipher, byte[] input) { try { return cipher.doFinal(input); } catch (IllegalBlockSizeException e) { throw new IllegalStateException("Unable to invoke Cipher due to illegal block size", e); } catch (BadPaddingException e) { throw new IllegalStateException("Unable to invoke Cipher due to bad padding", e); } }
From source file:com.jeysan.modules.utils.encode.EncodeUtils.java
public static String uncode4MethodGet(String input) { try {/*from w w w . jav a 2 s .c om*/ return new String(input.getBytes("ISO-8859-1"), DEFAULT_URL_ENCODING); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("uncode4MethodGet exception", e); } }
From source file:Main.java
/** * Constructs a new Cipher.// w w w . jav a 2 s . com */ public static Cipher newCipher(String algorithm, String provider) { try { return Cipher.getInstance(algorithm, provider); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException("Not a valid encryption algorithm", e); } catch (NoSuchPaddingException e) { throw new IllegalStateException("Should not happen", e); } catch (NoSuchProviderException e) { throw new IllegalStateException("Not a valid encryption provider", e); } }
From source file:com.bjwg.back.util.EncodeUtils.java
public static byte[] decodeHex(String input) { try {//from w ww .j ava2s . c o m return Hex.decodeHex(input.toCharArray()); } catch (DecoderException e) { throw new IllegalStateException("Hex Decoder exception", e); } }
From source file:Main.java
public static Schema loadSchema(final InputStream... fromStreams) { Source[] sources = new Source[fromStreams.length]; int i = 0;//from ww w. j a v a 2 s. com for (InputStream stream : fromStreams) { sources[i++] = new StreamSource(stream); } try { return SCHEMA_FACTORY.newSchema(sources); } catch (SAXException e) { throw new IllegalStateException("Failed to instantiate XML schema", e); } }