List of usage examples for java.lang IllegalArgumentException IllegalArgumentException
public IllegalArgumentException(Throwable cause)
From source file:Main.java
/** * Appends str to <code>out</code> while performing HTML attribute escaping. * //from w ww.jav a 2 s . c o m * @param out * @param str * @throws IOException */ public static void escapeHTMLAttribute(Writer out, String str) throws IOException { if (out == null) { throw new IllegalArgumentException("The Writer must not be null"); } if (str == null) { return; } int sz; sz = str.length(); for (int i = 0; i < sz; i++) { char ch = str.charAt(i); switch (ch) { case '&': out.write("&"); break; case '"': out.write("""); break; case '\t': out.write("	"); break; case '\n': out.write(" "); break; case '\r': out.write(" "); break; case '<': out.write("<"); break; case '>': out.write(">"); break; default: out.write(ch); break; } } }
From source file:Main.java
/** * Remove the characters caused by Saxon. This is necessary if you parse an * attribute because XPath then returns the name of the attribute. * // ww w.ja va 2s .com * @param input * - the return value of Saxon. * @return the cleaned String. */ public static String removeAttributeChars(final String input) { if (input == null) { throw new IllegalArgumentException( "The value for the parameter input in removeAttributeChars mustn't be empty."); } // Ex. value: [] String ret = input.replaceFirst("(\\w)+=(\")", ""); int lastPos = input.lastIndexOf("\""); if (input.length() != 0 && lastPos == input.length() - 1) { ret = ret.substring(0, ret.length() - 1); } return ret; }
From source file:Main.java
public static void setDefaultViewer(Context context, String mimeType, String activityPackage, String activityName) {/*w w w . j a v a 2s . c o m*/ if (TextUtils.isEmpty(mimeType)) { throw new IllegalArgumentException("Default viewer type can't be empty"); } PreferenceManager.getDefaultSharedPreferences(context).edit() .putString(DEFAULT_VIEWER_PREFIX + mimeType, activityPackage + "\t" + activityName).apply(); }
From source file:Main.java
public static Date parseDate(String dateString) { Matcher m = DATE_PATTERN.matcher(dateString.trim()); if (!m.matches()) { throw new IllegalArgumentException("\"" + dateString + "\" must be in YYYY-MM-DD format."); }/*from w w w . ja va 2 s . c o m*/ Calendar c = Calendar.getInstance(); c.set(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)) - 1, Integer.parseInt(m.group(3))); return c.getTime(); }
From source file:Main.java
public static byte[] decodeYUV420SP2RGB(byte[] yuv420sp, int width, int height) { final int frameSize = width * height; byte[] rgbBuf = new byte[frameSize * 3]; // if (rgbBuf == null) throw new NullPointerException("buffer 'rgbBuf' is null"); if (rgbBuf.length < frameSize * 3) throw new IllegalArgumentException( "buffer 'rgbBuf' size " + rgbBuf.length + " < minimum " + frameSize * 3); if (yuv420sp == null) throw new NullPointerException("buffer 'yuv420sp' is null"); if (yuv420sp.length < frameSize * 3 / 2) throw new IllegalArgumentException( "buffer 'yuv420sp' size " + yuv420sp.length + " < minimum " + frameSize * 3 / 2); int i = 0, y = 0; int uvp = 0, u = 0, v = 0; int y1192 = 0, r = 0, g = 0, b = 0; for (int j = 0, yp = 0; j < height; j++) { uvp = frameSize + (j >> 1) * width; u = 0;/*from ww w .j a va2 s .c o m*/ v = 0; for (i = 0; i < width; i++, yp++) { y = (0xff & ((int) yuv420sp[yp])) - 16; if (y < 0) y = 0; if ((i & 1) == 0) { v = (0xff & yuv420sp[uvp++]) - 128; u = (0xff & yuv420sp[uvp++]) - 128; } y1192 = 1192 * y; r = (y1192 + 1634 * v); g = (y1192 - 833 * v - 400 * u); b = (y1192 + 2066 * u); if (r < 0) r = 0; else if (r > 262143) r = 262143; if (g < 0) g = 0; else if (g > 262143) g = 262143; if (b < 0) b = 0; else if (b > 262143) b = 262143; rgbBuf[yp * 3] = (byte) (r >> 10); rgbBuf[yp * 3 + 1] = (byte) (g >> 10); rgbBuf[yp * 3 + 2] = (byte) (b >> 10); } } // for return rgbBuf; }
From source file:Main.java
/** * Converts an {@code Icon} to an {@code Image}. * //w w w . ja va 2 s . c om * @param icon * {@code Icon} that needs to be converted * @return the converted {@code Image} */ public static Image iconToImage(Icon icon) { if (icon instanceof ImageIcon) return ((ImageIcon) icon).getImage(); throw new IllegalArgumentException("Unable to get Image from Icon type! [" + icon + "]"); }
From source file:Main.java
public static Frame getOwnerFrame(Component component) { if (component instanceof Frame) { return (Frame) component; }//from w w w. jav a 2s .c om Container parent = component.getParent(); while (!(parent instanceof Frame)) { parent = parent.getParent(); if (parent == null) { throw new IllegalArgumentException("Component has no root Frame."); } } return (Frame) parent; }
From source file:Main.java
public static void skipFully(InputStream input, long toSkip) throws IOException { if (toSkip < 0L) { throw new IllegalArgumentException("Bytes to skip must not be negative: " + toSkip); } else {/*from w w w .ja v a 2 s .c o m*/ long skipped = skip(input, toSkip); if (skipped != toSkip) { throw new EOFException("Bytes to skip: " + toSkip + " actual: " + skipped); } } }
From source file:Main.java
public static String convertToStringRepresentation(final long value) { final long[] dividers = new long[] { T, G, M, K, 1 }; final String[] units = new String[] { "TB", "GB", "MB", "KB", "B" }; if (value < 1) throw new IllegalArgumentException("Invalid file size: " + value); String result = null;//w w w. j a va 2s . com for (int i = 0; i < dividers.length; i++) { final long divider = dividers[i]; if (value >= divider) { result = format(value, divider, units[i]); break; } } return result; }
From source file:Main.java
public static <T> T getSingleIfExist(Iterable<T> iterable) { if (iterable == null) return null; final Iterator<? extends T> iter = iterable.iterator(); if (!iter.hasNext()) return null; final T result = iter.next(); if (iter.hasNext()) { throw new IllegalArgumentException("More than (expected) one element in " + iterable); }/*from w ww. j a v a 2 s. c o m*/ return result; }