List of usage examples for java.lang IllegalStateException IllegalStateException
public IllegalStateException(Throwable cause)
From source file:com.aipo.aws.ses.SES.java
public static AmazonSimpleEmailServiceAsync getAsyncClient() { AWSContext awsContext = AWSContext.get(); if (awsContext == null) { throw new IllegalStateException("AWSContext is not initialized."); }/*from w w w. j a v a 2 s . co m*/ AmazonSimpleEmailServiceAsync client = new AmazonSimpleEmailServiceAsyncClient( awsContext.getAwsCredentials()); String endpoint = awsContext.getSesEndpoint(); if (endpoint != null && endpoint != "") { client.setEndpoint(endpoint); } return client; }
From source file:Main.java
public static int getElementSizeExponent(Buffer buf) { if (buf instanceof ByteBuffer) { return 0; } else if (buf instanceof ShortBuffer || buf instanceof CharBuffer) { return 1; } else if (buf instanceof FloatBuffer || buf instanceof IntBuffer) { return 2; } else if (buf instanceof LongBuffer || buf instanceof DoubleBuffer) { return 3; } else {/* ww w . j a v a 2 s .c o m*/ throw new IllegalStateException("Unsupported buffer type: " + buf); } }
From source file:com.asakusafw.runtime.compatibility.CoreCompatibility.java
/** * Verifies the running core framework version. */// w w w . j ava 2s . c o m public static void verifyFrameworkVersion() { FrameworkVersion running = FrameworkVersion.get(); if (TARGET.isCompatibleTo(running) == false) { throw new IllegalStateException(MessageFormat.format( "Inconsistent environment version: expected-version={0}, installed-version={1}", TARGET, running)); } }
From source file:com.linkedin.databus2.schemas.utils.Utils.java
public static byte[] utf8(String s) { try {/*from ww w . j a v a 2 s .co m*/ return s.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("This can't happen"); } }
From source file:Main.java
public static void setField(Object object, String fieldName, Object fieldValue) { Class<?> objectClass = object.getClass(); if (objectClass != null) { try {/* w w w . ja v a2 s . com*/ Field field = objectClass.getDeclaredField(fieldName); field.setAccessible(true); Type type = field.getGenericType(); //This is bad, but dear God I can't figure out how to convert a runtime Type to its actual type through reflection. I know how in C#.... if (type.toString().toLowerCase().contains("short")) { fieldValue = Short.parseShort((String) fieldValue); } else if (type.toString().toLowerCase().contains("integer")) { fieldValue = Integer.parseInt((String) fieldValue); } else if (type.toString().toLowerCase().contains("long")) { fieldValue = Long.parseLong((String) fieldValue); } else if (type.toString().toLowerCase().contains("boolean")) { fieldValue = "1".equals(fieldValue); //Java, you're the worst language. And SQLite isn't helping. } field.set(object, fieldValue); } catch (NoSuchFieldException e) { return; } catch (Exception e) { throw new IllegalStateException(e); } } }
From source file:Main.java
public static int hashCode(Object target) { if (target == null) return 0; final int prime = 31; int result = 1; Class<?> current = target.getClass(); do {//from ww w.ja v a 2 s . co m for (Field f : current.getDeclaredFields()) { if (Modifier.isStatic(f.getModifiers()) || Modifier.isTransient(f.getModifiers()) || f.isSynthetic()) { continue; } Object self; try { f.setAccessible(true); self = f.get(target); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } if (self == null) { result = prime * result + 0; } else if (self.getClass().isArray()) { if (self.getClass().equals(boolean[].class)) { result = prime * result + Arrays.hashCode((boolean[]) self); } else if (self.getClass().equals(char[].class)) { result = prime * result + Arrays.hashCode((char[]) self); } else if (self.getClass().equals(byte[].class)) { result = prime * result + Arrays.hashCode((byte[]) self); } else if (self.getClass().equals(short[].class)) { result = prime * result + Arrays.hashCode((short[]) self); } else if (self.getClass().equals(int[].class)) { result = prime * result + Arrays.hashCode((int[]) self); } else if (self.getClass().equals(long[].class)) { result = prime * result + Arrays.hashCode((long[]) self); } else if (self.getClass().equals(float[].class)) { result = prime * result + Arrays.hashCode((float[]) self); } else if (self.getClass().equals(double[].class)) { result = prime * result + Arrays.hashCode((double[]) self); } else { result = prime * result + Arrays.hashCode((Object[]) self); } } else { result = prime * result + self.hashCode(); } System.out.println(f.getName() + ": " + result); } current = current.getSuperclass(); } while (!Object.class.equals(current)); return result; }
From source file:Main.java
private static byte[] utf8(String keyString) { try {//from w w w . java2 s . c o m return keyString.getBytes("utf-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); // utf-8 is supported! } }
From source file:Main.java
/** * Add a zip entry into the provided <code>ZipOutputStream</code>. The zip * entry is the part of <code>filePathToZip</code> truncated with the * <code>baseFolderPath</code>. * <p>// w w w. j a va 2 s. co m * So a file or folder <code>c:\my\base\folder\my\file\to\zip.txt</code> * will be added in archive using <code>my/file/to/zip.txt</code> entry. */ public static void addZipEntry(ZipOutputStream zos, File fileToZip, File baseFolder) { if (!baseFolder.isDirectory()) { throw new IllegalArgumentException(baseFolder.getPath() + " is not a directory."); } if (fileToZip.isDirectory()) { final File[] files = fileToZip.listFiles(); for (final File file : files) { addZipEntry(zos, file, baseFolder); } } else { final String filePathToZip; final int start; try { filePathToZip = fileToZip.getCanonicalPath(); start = baseFolder.getCanonicalPath().length() + 1; } catch (final IOException e1) { throw new IllegalStateException(e1); } final int end = filePathToZip.length(); String entryName = filePathToZip.substring(start, end); entryName = entryName.replace(File.separatorChar, '/'); final FileInputStream inputStream; try { inputStream = new FileInputStream(filePathToZip); } catch (final FileNotFoundException e) { throw new IllegalStateException(e); } addEntryInputStream(zos, entryName, inputStream); } }
From source file:es.us.isa.ideas.app.social.CustomUserIdSource.java
public String getUserId() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { throw new IllegalStateException("Unable to get a ConnectionRepository: no user signed in"); }// ww w . j a va2s .com return authentication.getName(); }
From source file:pl.touk.wonderfulsecurity.core.ServerSecurity.java
/** * Return currently logged in user/*from ww w . ja va 2s . c o m*/ */ public static WsecUser getLoggedInUser() { Object obj = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (obj instanceof UserDetails) { WsecUserDetails wsecUserDetails = (WsecUserDetails) obj; return wsecUserDetails.getWsecUser(); } throw new IllegalStateException("No one logged in!!!"); }