List of usage examples for java.lang IllegalStateException IllegalStateException
public IllegalStateException(Throwable cause)
From source file:org.zodiark.protocol.ActorValue.java
@JsonCreator public static ActorValue deserialize(String v) { String value = v.toLowerCase(); switch (value) { case "subscriber": return SUBSCRIBER; case "publisher": return PUBLISHER; case "stream_server": return STREAM_SERVER; case "server": return SERVER; case "monitor": return MONITOR; default:// w ww . j a v a2s .c o m throw new IllegalStateException("Invalid value " + value); } }
From source file:com.thinkberg.webdav.vfs.VFSBackend.java
public static FileObject resolveFile(String path) throws FileSystemException { if (null == instance) { throw new IllegalStateException("VFS backend not initialized"); }/* w w w. ja v a2s . c om*/ return instance.fileSystemRoot.resolveFile(path); }
From source file:Main.java
public static Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) { List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes(); if (rawSupportedSizes == null) { Log.w(TAG, "Device returned no supported preview sizes; using default"); Camera.Size defaultSize = parameters.getPreviewSize(); if (defaultSize == null) { throw new IllegalStateException("Parameters contained no preview size!"); }//ww w .j a v a 2 s .c om return new Point(defaultSize.width, defaultSize.height); } if (Log.isLoggable(TAG, Log.INFO)) { StringBuilder previewSizesString = new StringBuilder(); for (Camera.Size size : rawSupportedSizes) { previewSizesString.append(size.width).append('x').append(size.height).append(' '); } Log.i(TAG, "Supported preview sizes: " + previewSizesString); } double screenAspectRatio = screenResolution.x / (double) screenResolution.y; // Find a suitable size, with max resolution int maxResolution = 0; Camera.Size maxResPreviewSize = null; for (Camera.Size size : rawSupportedSizes) { int realWidth = size.width; int realHeight = size.height; int resolution = realWidth * realHeight; if (resolution < MIN_PREVIEW_PIXELS) { continue; } boolean isCandidatePortrait = realWidth < realHeight; int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth; int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight; double aspectRatio = maybeFlippedWidth / (double) maybeFlippedHeight; double distortion = Math.abs(aspectRatio - screenAspectRatio); if (distortion > MAX_ASPECT_DISTORTION) { continue; } if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) { Point exactPoint = new Point(realWidth, realHeight); Log.i(TAG, "Found preview size exactly matching screen size: " + exactPoint); return exactPoint; } // Resolution is suitable; record the one with max resolution if (resolution > maxResolution) { maxResolution = resolution; maxResPreviewSize = size; } } // If no exact match, use largest preview size. This was not a great idea on older devices because // of the additional computation needed. We're likely to get here on newer Android 4+ devices, where // the CPU is much more powerful. if (maxResPreviewSize != null) { Point largestSize = new Point(maxResPreviewSize.width, maxResPreviewSize.height); Log.i(TAG, "Using largest suitable preview size: " + largestSize); return largestSize; } // If there is nothing at all suitable, return current preview size Camera.Size defaultPreview = parameters.getPreviewSize(); if (defaultPreview == null) { throw new IllegalStateException("Parameters contained no preview size!"); } Point defaultSize = new Point(defaultPreview.width, defaultPreview.height); Log.i(TAG, "No suitable preview sizes, using default: " + defaultSize); return defaultSize; }
From source file:com.ai.bss.webui.util.SecurityUtil.java
public static String obtainLoggedinUserIdentifier() { Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof UserAccount) { return ((UserAccount) principal).getUserId(); } else {// ww w .j a v a 2 s .c o m throw new IllegalStateException("Wrong security implementation, expecting a UserAccount as principal"); } }
From source file:RandomUtil.java
/** * Creates a new secure random number generator. The following secure random * algorithm names are tried://from w ww .j av a2s . co m * <ul> * <li>The value of system property "boticelli.securerandom", if set. </li> * <li> "SHA1PRNG" </li> * <li> "IBMSecureRandom" (available if running in the IBM JRE) </li> * </ul> */ private static SecureRandom createSecureRandom() { SecureRandom secureRnd = null; try { for (int i = 0; i < secureRndNames.length; i++) { try { if (secureRndNames[i] != null) { secureRnd = SecureRandom.getInstance(secureRndNames[i]); break; } } catch (NoSuchAlgorithmException nsae) { // log.debug("no secure random algorithm named \"" + secureRndNames[i] + "\"", // nsae); } } if (secureRnd == null) { throw new IllegalStateException( "no secure random algorithm found. (tried " + Arrays.asList(secureRndNames) + ")"); } secureRnd.setSeed(System.currentTimeMillis()); } catch (Exception e) { // log.fatal("error initializing secure random", e); } return secureRnd; }
From source file:Main.java
public static Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) { List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes(); if (rawSupportedSizes == null) { Log.w(TAG, "Device returned no supported preview sizes; using default"); Camera.Size defaultSize = parameters.getPreviewSize(); if (defaultSize == null) { throw new IllegalStateException("Parameters contained no preview size!"); }/*from www . j av a 2s .c o m*/ return new Point(defaultSize.width, defaultSize.height); } // Sort by size, descending List<Camera.Size> supportedPreviewSizes = new ArrayList<Camera.Size>(rawSupportedSizes); Collections.sort(supportedPreviewSizes, new Comparator<Camera.Size>() { @Override public int compare(Camera.Size a, Camera.Size b) { int aPixels = a.height * a.width; int bPixels = b.height * b.width; if (bPixels < aPixels) { return -1; } if (bPixels > aPixels) { return 1; } return 0; } }); if (Log.isLoggable(TAG, Log.INFO)) { StringBuilder previewSizesString = new StringBuilder(); for (Camera.Size supportedPreviewSize : supportedPreviewSizes) { previewSizesString.append(supportedPreviewSize.width).append('x') .append(supportedPreviewSize.height).append(' '); } Log.i(TAG, "Supported preview sizes: " + previewSizesString); } double screenAspectRatio = (double) screenResolution.x / (double) screenResolution.y; // Remove sizes that are unsuitable Iterator<Camera.Size> it = supportedPreviewSizes.iterator(); while (it.hasNext()) { Camera.Size supportedPreviewSize = it.next(); int realWidth = supportedPreviewSize.width; int realHeight = supportedPreviewSize.height; if (realWidth * realHeight < MIN_PREVIEW_PIXELS) { it.remove(); continue; } boolean isCandidatePortrait = realWidth < realHeight; int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth; int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight; double aspectRatio = (double) maybeFlippedWidth / (double) maybeFlippedHeight; double distortion = Math.abs(aspectRatio - screenAspectRatio); if (distortion > MAX_ASPECT_DISTORTION) { it.remove(); continue; } if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) { Point exactPoint = new Point(realWidth, realHeight); Log.i(TAG, "Found preview size exactly matching screen size: " + exactPoint); return exactPoint; } } // If no exact match, use largest preview size. This was not a great idea on older devices because // of the additional computation needed. We're likely to get here on newer Android 4+ devices, where // the CPU is much more powerful. if (!supportedPreviewSizes.isEmpty()) { Camera.Size largestPreview = supportedPreviewSizes.get(0); Point largestSize = new Point(largestPreview.width, largestPreview.height); Log.i(TAG, "Using largest suitable preview size: " + largestSize); return largestSize; } // If there is nothing at all suitable, return current preview size Camera.Size defaultPreview = parameters.getPreviewSize(); if (defaultPreview == null) { throw new IllegalStateException("Parameters contained no preview size!"); } Point defaultSize = new Point(defaultPreview.width, defaultPreview.height); Log.i(TAG, "No suitable preview sizes, using default: " + defaultSize); return defaultSize; }
From source file:Main.java
/** * Create a new DocumentBuilder which processes XML securely. * * @return a DocumentBuilder/*w w w . ja v a2s . c om*/ */ public static DocumentBuilder createDocumentBuilder() { try { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); return documentBuilderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new IllegalStateException(e); } }
From source file:org.eclipse.aether.transport.http.UriUtils.java
public static URI resolve(URI base, URI ref) { String path = ref.getRawPath(); if (path != null && path.length() > 0) { path = base.getRawPath();/* w ww . j ava 2 s . com*/ if (path == null || !path.endsWith("/")) { try { base = new URI(base.getScheme(), base.getAuthority(), base.getPath() + '/', null, null); } catch (URISyntaxException e) { throw new IllegalStateException(e); } } } return URIUtils.resolve(base, ref); }
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 {/* w ww .j av a 2 s . c o m*/ throw new IllegalStateException("Unsupported buf type: " + buf); } }
From source file:Comments.java
public static String removeComment(String input) { StringBuffer sb = new StringBuffer(input); char NQ = ' ', quote = NQ; int len = sb.length(); for (int j = 0, lineno = 1; j < len; j++) { if (sb.charAt(j) == '\n') ++lineno;/*from w w w .j av a 2 s . c o m*/ if (quote != NQ) { if (sb.charAt(j) == quote) { quote = NQ; } else if (sb.charAt(j) == '\\') { j++; //fix for "123\\\r\n123" if (sb.charAt(j) == '\r') j++; // if(sb.charAt(j) == '\n') j++; } else if (sb.charAt(j) == '\n') { throw new IllegalStateException("Unterminated string at line " + lineno); } } else if (sb.charAt(j) == '/' && j + 1 < len && (sb.charAt(j + 1) == '*' || sb.charAt(j + 1) == '/')) { int l = j; boolean eol = sb.charAt(++j) == '/'; while (++j < len) { if (sb.charAt(j) == '\n') ++lineno; if (eol) { if (sb.charAt(j) == '\n') { sb.delete(l, sb.charAt(j - 1) == '\r' ? j - 1 : j); len = sb.length(); j = l; break; } } else if (sb.charAt(j) == '*' && j + 1 < len && sb.charAt(j + 1) == '/') { sb.delete(l, j + 2); len = sb.length(); j = l; break; } } } else if (sb.charAt(j) == '\'' || sb.charAt(j) == '"') { quote = sb.charAt(j); } else if (sb.charAt(j) == '/') { // regex boolean regex = false; for (int k = j;;) { if (--k < 0) { regex = true; break; } char ck = sb.charAt(k); if (!Character.isWhitespace(ck)) { regex = ck == '(' || ck == ',' || ck == '=' || ck == ':' || ck == '?' || ck == '{' || ck == '[' || ck == ';' || ck == '!' || ck == '&' || ck == '|' || ck == '^' || (ck == 'n' && k > 4 && "return".equals(sb.substring(k - 5, k + 1))) || (ck == 'e' && k > 2 && "case".equals(sb.substring(k - 3, k + 1))); break; } } if (regex) { while (++j < len && sb.charAt(j) != '/') { if (sb.charAt(j) == '\\') j++; else if (sb.charAt(j) == '\n') { throw new IllegalStateException("Unterminated regex at line " + lineno); } } } } } return sb.toString(); }