Example usage for java.lang IllegalStateException IllegalStateException

List of usage examples for java.lang IllegalStateException IllegalStateException

Introduction

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

Prototype

public IllegalStateException(Throwable cause) 

Source Link

Document

Constructs a new exception with the specified cause and a detail message of (cause==null ?

Usage

From source file:Main.java

public static Node findFirstChild(final Node n, final String name) {
    for (int i = 0; i < n.getChildNodes().getLength(); i++) {
        if (n.getChildNodes().item(i).getNodeName().equals(name)) {
            return n.getChildNodes().item(i);
        }//w  ww  .  j a va  2  s.  com
    }
    throw new IllegalStateException("no " + name + " children found in: " + n.getNodeName());
}

From source file:Main.java

public static Element getChildByName(Element e, String name) {
    Element[] list = getChildrenByName(e, name);
    if (list.length == 0) {
        return null;
    }//from w  ww  .  ja  va  2 s  . c o  m
    if (list.length > 1) {
        throw new IllegalStateException("Too many (" + list.length + ") '" + name + "' elements found!");
    }
    return list[0];
}

From source file:Main.java

private static Object invokeGetter(Method getter, Object object) {
    try {/*w w  w  .  j  a  v  a 2s  . c o m*/
        getter.setAccessible(true);
        return getter.invoke(object, new Object[0]);
    } catch (IllegalAccessException e) {
        throw new IllegalStateException(e);
    } catch (InvocationTargetException e) {
        throw new IllegalStateException(e);
    }
}

From source file:Main.java

public static long readEncodedLength(InputStream input, int[] bytesReadOut) {
    try {/* w w  w .  jav  a  2 s  .  c om*/
        int lbyte = input.read();
        if (lbyte == -1)
            return -1;
        if (lbyte == 0)
            throw new IllegalStateException("First length byte is 0");
        // there will always be 24 extra leading zeros from the first 3 bytes
        int nbytes = 1 + Integer.numberOfLeadingZeros(lbyte) - 24;

        // start with the first byte with the leading 1 masked out
        long value = lbyte ^ Integer.highestOneBit(lbyte);
        // read successive bytes, shifting current value each time (big-endian, most significant bytes first)
        for (int i = 1; i < nbytes; i++) {
            lbyte = input.read();
            if (lbyte == -1)
                return -1;
            value = (value << 8) | lbyte;
        }
        if (bytesReadOut != null)
            bytesReadOut[0] = nbytes;
        return value;
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}

From source file:Main.java

public static InputStream getWsddStream(Class<?> clientClass) {
    InputStream wsdd = clientClass.getResourceAsStream("client-config.wsdd");
    if (wsdd == null) {
        throw new IllegalStateException(
                "Could not find client-config.wsdd relative to " + clientClass.getName());
    }// w w w .j  av  a  2s .c  o m
    return wsdd;
}

From source file:Main.java

public static void requireAttr(final XmlPullParser pp, final String attrName, final String requiredValue) {
    if (!requiredValue.equals(attr(pp, attrName)))
        throw new IllegalStateException("cannot find " + attrName + "=\"" + requiredValue + "\" />");
}

From source file:Main.java

private static void assureScreenDimen() {
    if (sDevicesScreenHeight == 0 || sDevicesScreenWidth == 0) {
        throw new IllegalStateException("you must init sDevicesScreenHeight and/or sDevicesScreenWidth.");
    }/*from  w w  w. ja  v  a  2  s.  c  om*/
}

From source file:Main.java

public static void setUseSaxonTransformFactory() {
    if (System.getProperty(XSLT_TRANSFORMER_FACTORY) == null) {
        System.setProperty(XSLT_TRANSFORMER_FACTORY, SAXON_TRANSFORMER_FACTORY);
    } else {/*from  ww  w . j a v  a 2  s.co m*/
        throw new IllegalStateException(XSLT_TRANSFORMER_FACTORY + " is already set");
    }
}

From source file:Main.java

public static void awaitForTermination(List<Thread> threads, long timeout, TimeUnit timeUnit) {
    try {//from ww w  .  j a  va  2s.  c  om
        long finishTime = System.currentTimeMillis() + timeUnit.toMillis(timeout);
        for (Thread t : threads) {
            long now = System.currentTimeMillis();
            if (now > finishTime) {
                throw new IllegalStateException("failed to stop all threads");
            } else {
                t.join(finishTime - now);
                if (t.isAlive()) {
                    throw new IllegalStateException("failed to stop all threads");
                }
            }
        }
    } catch (InterruptedException e) {
        throw new IllegalStateException(e);
    }
}

From source file:Main.java

public static String stringToHexString(String input) {
    try {//ww w  .j  av  a  2 s.c  o  m
        return stringToHexString(input, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException("UTF-8 encoding is not supported by JVM");
    }
}