/** * Read the byte size of a {@link Class}. * * @param clazz * The class * @return The byte size of the given {@link Class} * @throws Exception */ static int findLengthOfClass(Class<?> clazz) throws Exception { String classResourceName = getResourceNameForClass(clazz); InputStream in = SecurityActions.getThreadContextClassLoader().getResourceAsStream(classResourceName); return findLengthOfStream(in); }
@Test public void shouldBeAbleToReadThisClass() throws Exception { Class<?> clazz = ClassAssetTestCase.class; Asset asset = new ClassAsset(clazz); InputStream io = asset.openStream(); Assert.assertNotNull(io); Assert.assertEquals("Loaded class should have the same size", ApiTestUtils.findLengthOfStream(io), ApiTestUtils.findLengthOfClass(clazz)); }
/** * https://jira.jboss.org/jira/browse/TMPARCH-19 <br/> * <br/> * A {@link Class} loaded by the Bootstrap ClassLoader will return a null {@link ClassLoader}, should use * {@link Thread} current context {@link ClassLoader} instead. * * @throws Exception */ @Test public void shouldBeAbleAddBootstrapClass() throws Exception { Class<?> bootstrapClass = Class.class; Asset asset = new ClassAsset(bootstrapClass); InputStream io = asset.openStream(); Assert.assertNotNull(io); Assert.assertEquals("Loaded class should have the same size", ApiTestUtils.findLengthOfStream(io), ApiTestUtils.findLengthOfClass(bootstrapClass)); }