/** * Checks the availability of the JAXP classes on the classpath. * @throws NoClassDefFoundError if the required JAXP classes are not availabile on the classpath. */ static void checkJAXPAvailability() { try { XmlConfigurator.class.getName(); } catch (NoClassDefFoundError error) { Error tmp=new NoClassDefFoundError(JAXP_MISSING_ERROR_MSG); tmp.initCause(error); throw tmp; } }
/** * Performs URL encoding with UTF-8 * * @param value the value to URL encode * @return the encoded value */ private String utf8UrlEncode(String value) { try { return URLEncoder.encode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { Error err = new AssertionError( "The Java platform guarantees UTF-8 support, but it seemingly is not present."); err.initCause(e); throw err; } } }
/** * Create an array of bytes with the given size. If this is not possible * because not enough memory is available, an OutOfMemoryError with the * requested size in the message is thrown. * <p> * This method should be used if the size of the array is user defined, or * stored in a file, so wrong size data can be distinguished from regular * out-of-memory. * </p> * * @param len the number of bytes requested * @return the byte array * @throws OutOfMemoryError if the allocation was too large */ public static byte[] newBytes(int len) { if (len == 0) { return EMPTY_BYTES; } try { return new byte[len]; } catch (OutOfMemoryError e) { Error e2 = new OutOfMemoryError("Requested memory: " + len); e2.initCause(e); throw e2; } }
/** * Creates a copy of array of bytes with the new size. If this is not possible * because not enough memory is available, an OutOfMemoryError with the * requested size in the message is thrown. * <p> * This method should be used if the size of the array is user defined, or * stored in a file, so wrong size data can be distinguished from regular * out-of-memory. * </p> * * @param bytes source array * @param len the number of bytes in the new array * @return the byte array * @throws OutOfMemoryError if the allocation was too large * @see Arrays#copyOf(byte[], int) */ public static byte[] copyBytes(byte[] bytes, int len) { if (len == 0) { return EMPTY_BYTES; } try { return Arrays.copyOf(bytes, len); } catch (OutOfMemoryError e) { Error e2 = new OutOfMemoryError("Requested memory: " + len); e2.initCause(e); throw e2; } }
/** * Create an array of bytes with the given size. If this is not possible * because not enough memory is available, an OutOfMemoryError with the * requested size in the message is thrown. * <p> * This method should be used if the size of the array is user defined, or * stored in a file, so wrong size data can be distinguished from regular * out-of-memory. * * @param len the number of bytes requested * @return the byte array * @throws OutOfMemoryError if the allocation was too large */ public static byte[] newBytes(int len) { if (len == 0) { return EMPTY_BYTES; } try { return new byte[len]; } catch (OutOfMemoryError e) { Error e2 = new OutOfMemoryError("Requested memory: " + len); e2.initCause(e); throw e2; } }
private static void encodeTrailingHeaders(ChannelBuffer buf, HttpChunkTrailer trailer) { try { for (Map.Entry<String, String> h: trailer.trailingHeaders()) { encodeHeader(buf, h.getKey(), h.getValue()); } } catch (UnsupportedEncodingException e) { throw (Error) new Error().initCause(e); } }
private static void encodeHeaders(ChannelBuffer buf, HttpMessage message) { try { for (Map.Entry<String, String> h: message.headers()) { encodeHeader(buf, h.getKey(), h.getValue()); } } catch (UnsupportedEncodingException e) { throw (Error) new Error().initCause(e); } }
e.initCause(ex); if (logger.isDebugEnabled()) { logger.debug("Failed to extract for " + libnameversion + ": " + e);
e.initCause(ex); throw e;
public static SimpleFeature createAddressFeature() { try { return createFeature(); // FeatureType addressType = createAddressType(); // Object[] attributes = createComplexAttributes(); // return addressType.create(attributes); } catch (Exception e) { Error ae = new AssertionError("Sample Feature for tests has been misscoded"); ae.initCause(e); throw ae; } }
public static SimpleFeature createFeature() { try { SimpleFeatureType testType = createTestType(); Object[] attributes = createAttributes(); return SimpleFeatureBuilder.build(testType, attributes, null); } catch (Exception e) { Error ae = new AssertionError("Sample Feature for tests has been misscoded"); ae.initCause(e); throw ae; } }
private static Method lookupMethod(Class type, String name, Class... args) { try { return type.getMethod(name, args); } catch (NoSuchMethodException e) { Error error = new NoSuchMethodError(); error.initCause(e); throw error; } }
public String getLocation() { try { return (location == null) ? new File(symbolicName + ".jar").toURL().toString() : location; } catch (MalformedURLException e) { Error err = new AssertionFailedError("We could not generate a valid url for the bundle"); err.initCause(e); throw err; } }
public String getLocation() { try { return (location == null) ? new File(symbolicName + ".jar").toURL().toString() : location; } catch (MalformedURLException e) { Error err = new AssertionFailedError("We could not generate a valid url for the bundle"); err.initCause(e); throw err; } }
public URL getResource(String name) { if (cl != null) return cl.getResource(name); try { File f = new File(name); if(f.exists() || "Entities.jar".equals(name)) return f.toURL(); else return null; } catch (MalformedURLException e) { Error err = new AssertionFailedError("The resource " + name + " could not be found."); err.initCause(e); throw err; } }
protected void assertValid(final String cronExpression) { try { validator.validate(cronExpression); } catch (CronSyntaxException cse) { final Error e = new AssertionError("Expected '" + cronExpression + "' to be valid, but it threw " + cse); e.initCause(cse); throw e; } }
public URL getResource(String name) { if (cl != null) return cl.getResource(name); try { File f = new File(name); if(f.exists() || "Entities.jar".equals(name)) return f.toURL(); else return null; } catch (MalformedURLException e) { Error err = new AssertionFailedError("The resource " + name + " could not be found."); err.initCause(e); throw err; } }
private static void encodeTrailingHeaders(ChannelBuffer buf, HttpChunkTrailer trailer) { try { for (Map.Entry<String, String> h: trailer.trailingHeaders()) { encodeHeader(buf, h.getKey(), h.getValue()); } } catch (UnsupportedEncodingException e) { throw (Error) new Error().initCause(e); } }
private static void encodeHeaders(ChannelBuffer buf, HttpMessage message) { try { for (Map.Entry<String, String> h: message.headers()) { encodeHeader(buf, h.getKey(), h.getValue()); } } catch (UnsupportedEncodingException e) { throw (Error) new Error().initCause(e); } }
@Override public synchronized Throwable initCause(Throwable cause) { if(!MockFramework.isEnabled()){ return super.initCause(cause); } return getDelegate().initCause(cause); }