List of usage examples for java.lang IllegalStateException IllegalStateException
public IllegalStateException(Throwable cause)
From source file:Main.java
/** * Return the context use by the library. * @return the context use by the library. *//*w ww . j a v a2 s. c o m*/ protected static Context getContext() { if (mContext == null) { throw new IllegalStateException("The context provided to this library is null. Please provide" + " a proper context according the lifecycle of the application (you should provide the application context)."); } return mContext; }
From source file:Main.java
/** * Returns the folder that contains a jar that contains the class * * @param aclass a class to find a jar/*from w w w . j a v a2 s. c o m*/ * @return */ public static String getJarContainingFolderPath(Class aclass) throws Exception { CodeSource codeSource = aclass.getProtectionDomain().getCodeSource(); File jarFile; if (codeSource.getLocation() != null) { jarFile = new File(codeSource.getLocation().toURI()); } else { String path = aclass.getResource(aclass.getSimpleName() + ".class").getPath(); int startIndex = path.indexOf(":") + 1; int endIndex = path.indexOf("!"); if (startIndex == -1 || endIndex == -1) { throw new IllegalStateException( "Class " + aclass.getSimpleName() + " is located not within a jar: " + path); } String jarFilePath = path.substring(startIndex, endIndex); jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8"); jarFile = new File(jarFilePath); } return jarFile.getParentFile().getAbsolutePath(); }
From source file:Main.java
/** * Return everything past PITarget and S from Processing Instruction (PI) as defined in XML 1.0 Section 2.6 * Processing Instructions <code>[16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'</code> * /* w w w.j a v a2 s.co m*/ * <p> * <b>NOTE:</b> if there is no PI data it returns empty string. */ public static String getPIData(final XmlPullParser pp) throws IllegalStateException { int eventType; try { eventType = pp.getEventType(); } catch (final XmlPullParserException x) { // should never happen ... throw new IllegalStateException("could not determine parser state: " + x + 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(); int pos = -1; for (int i = 0; i < PI.length(); i++) { if (isS(PI.charAt(i))) { pos = i; } else if (pos > 0) { return PI.substring(i); } } return ""; }
From source file:nh.examples.springintegration.order.client.ClientContext.java
static void createInstance(ApplicationContext applicationContext) { if (_instance != null) { throw new IllegalStateException("clientcontext already initialized"); }/*from w w w. ja v a 2s . co m*/ _instance = new ClientContext(applicationContext); }
From source file:Main.java
private static Constructor<?> getDefaultConstructor(@NonNull Class<?> cls) { final Constructor[] ctors = cls.getDeclaredConstructors(); Constructor ctor = null;/*from ww w . j a v a 2s.com*/ for (Constructor ct : ctors) { ctor = ct; if (ctor.getGenericParameterTypes().length == 0) break; } if (ctor == null) throw new IllegalStateException("No default constructor found for " + cls.getName()); ctor.setAccessible(true); return ctor; }
From source file:Main.java
public static String getRevisionIdSuffix(String revId) { validateRevisionId(revId);//w w w .j a v a2 s . c o m int dashPos = revId.indexOf("-"); if (dashPos >= 0) { return revId.substring(dashPos + 1); } else { throw new IllegalStateException("The revId id should be valid: " + revId); } }
From source file:Main.java
public static void init(Instrumentation instrumentation) { if (inst != null) throw new IllegalStateException("AProfSizeUtil is already initialized"); inst = instrumentation;//from w w w . ja v a2 s. c o m }
From source file:Main.java
private static void print(Writer writer, String s) { try {//from w w w. ja va 2s.co m writer.write(s); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:Main.java
/** * Converts a {@link Node node} to an XML string * * @param node the first element/*from w ww .j ava 2 s. c o m*/ * @return the XML String representation of the node, never null */ public static String nodeToString(Node node) { try { StringWriter writer = new StringWriter(); createIndentingTransformer().transform(new DOMSource(node), new StreamResult(writer)); return writer.toString(); } catch (TransformerException e) { throw new IllegalStateException(e); } }
From source file:Main.java
/** * Write the current IP address of the Android device to an NFC Tag. Must be connected to wifi network. * * @param tag NFC Tag to write message to * @param wifi WifiManager which can be used to retrieve IP address * @throws IOException//w ww.ja va 2 s . com * @throws FormatException * @throws IllegalStateException when Android device is not connected to Wifi network */ public static void writeIpAddress(Tag tag, WifiManager wifi) throws IOException, FormatException, IllegalStateException { String ipAddress = getIpAddr(wifi); if (ipAddress.equals("0.0.0.0")) { throw new IllegalStateException("Not connected to Wifi"); } NdefRecord[] records = { createRecord(ipAddress) }; NdefMessage message = new NdefMessage(records); Ndef ndef = Ndef.get(tag); ndef.connect(); ndef.writeNdefMessage(message); ndef.close(); }