List of usage examples for java.lang IllegalStateException IllegalStateException
public IllegalStateException(Throwable cause)
From source file:Main.java
public static Object get(String key) { HashMap map = (HashMap) s_var.get(); if (map == null) throw new IllegalStateException("Thread local not exists!"); else// ww w. j av a 2s . co m return map.get(key); }
From source file:Main.java
/** * Assert we are in the event dispatching thread. *//* www. j ava2 s .co m*/ public static void assertEventDispatcherThread() { if (!SwingUtilities.isEventDispatchThread()) throw new IllegalStateException("Not an AWT thread."); }
From source file:Main.java
public static String getApplicationKey(Context context) { try {/*from w w w. j ava2 s .c o m*/ BufferedReader assetsFile = new BufferedReader( new InputStreamReader(context.getAssets().open(YUMMLY_CREDS_FILE_NAME))); assetsFile.readLine(); return assetsFile.readLine(); } catch (IOException e) { e.printStackTrace(); } throw new IllegalStateException(YUMMLY_CREDS_FILE_NAME + " needs to have application ID on first line and application Key on second line"); }
From source file:Main.java
/** * directly jumps forward to start tag, ignoring any structure *//*w w w. jav a 2 s .co m*/ public static void jump(final XmlPullParser pp, final String tagName) throws XmlPullParserException, IOException { if (!jumpToStartTag(pp, null, tagName)) throw new IllegalStateException("cannot find <" + tagName + " />"); }
From source file:Main.java
/** * Returns the in memory size of the given {@link Bitmap} in bytes. */// w w w . ja v a 2s . c om @TargetApi(Build.VERSION_CODES.KITKAT) public static int getBitmapByteSize(Bitmap bitmap) { // The return value of getAllocationByteCount silently changes for recycled bitmaps from the // internal buffer size to row bytes * height. To avoid random inconsistencies in caches, we // instead assert here. if (bitmap.isRecycled()) { throw new IllegalStateException("Cannot obtain size for recycled Bitmap: " + bitmap + "[" + bitmap.getWidth() + "x" + bitmap.getHeight() + "] " + bitmap.getConfig()); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // Workaround for KitKat initial release NPE in Bitmap, fixed in MR1. See issue #148. try { return bitmap.getAllocationByteCount(); } catch (NullPointerException e) { // Do nothing. } } return bitmap.getHeight() * bitmap.getRowBytes(); }
From source file:Main.java
public static String getStringFromResources(final Context context, @RawRes final int rawResource) { final InputStream is = context.getResources().openRawResource(rawResource); try {/*from w ww . j a va 2s. co m*/ return readStringFromInputStreamAndCloseStream(is, 4048); } catch (final IOException e) { // TODO: bad. throw new IllegalStateException("ain't nobody got time to handle this properly"); } }
From source file:Main.java
/** * @return a transformer that indents entries by 4 characters (never null) *///from w w w.j av a 2 s .c o m public static Transformer createIndentingTransformer() { Transformer transformer; try { TRANSFORMER_FACTORY.setAttribute("indent-number", 4); transformer = TRANSFORMER_FACTORY.newTransformer(); } catch (final Exception e) { throw new IllegalStateException(e); } transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); return transformer; }
From source file:Main.java
public static XMLReader createXMLReader() { SAXParserFactory factory = createParserFactory(); try {//w w w . j a v a 2 s.c om SAXParser parser = factory.newSAXParser(); return parser.getXMLReader(); } catch (ParserConfigurationException ex) { throw new IllegalStateException(ex); } catch (SAXException ex) { throw new IllegalStateException(ex); } }
From source file:Main.java
/** * Return PITarget from Processing Instruction (PI) as defined in * XML 1.0 Section 2.6 Processing Instructions * <code>[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'</code> *//*from w ww . j a v a2s. co m*/ public static String getPITarget(XmlPullParser pp) throws IllegalStateException { int eventType; try { eventType = pp.getEventType(); } catch (XmlPullParserException ex) { // should never happen ... throw new IllegalStateException( "could not determine parser state: " + ex + pp.getPositionDescription()); } if (eventType != XmlPullParser.PROCESSING_INSTRUCTION) { throw new IllegalStateException("parser must be on processing instruction and not " + XmlPullParser.TYPES[eventType] + pp.getPositionDescription()); } final String PI = pp.getText(); for (int i = 0; i < PI.length(); i++) { if (isS(PI.charAt(i))) { // assert i > 0 return PI.substring(0, i); } } return PI; }
From source file:Main.java
/** * Digests the given message with the default digest algorithm ({@link CipherUtils#DEFAULT_DIGEST_ALGORITHM}) * * @param originalMessage the original message * @return the bytes of the digested message *///from ww w . j av a2s .c om public static byte[] digestMessage(byte[] originalMessage) { byte[] bytes; try { bytes = digestMessage(originalMessage, DEFAULT_DIGEST_ALGORITHM); } catch (NoSuchAlgorithmException ignored) { throw new IllegalStateException("Default digest algorithm not found"); } return bytes; }