Package java.lang.instrument

Examples of java.lang.instrument.ClassDefinition


            } else {
                log.trace(_loc.get("redefine-types", classes.keySet()));
                // in a Java 5 context, we can use class redefinition instead
                ClassDefinition[] defs = new ClassDefinition[array.length];
                for (int i = 0; i < defs.length; i++)
                    defs[i] = new ClassDefinition(array[i],
                        classes.get(array[i]));
                inst.redefineClasses(defs);
            }
        } catch (NoSuchMethodException e) {
            throw new InternalException(e);
View Full Code Here


            try {
                final Class<?> originalProxyClass = loader.loadClass(ct.getName());
                try {
                    ByteArrayOutputStream bs = new ByteArrayOutputStream();
                    ct.write(new DataOutputStream(bs));
                    Agent.redefine(new ClassDefinition[]{new ClassDefinition(originalProxyClass, bs.toByteArray())}, new AddedClass[0]);
                    return originalProxyClass;
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            } catch (ClassNotFoundException e) {
View Full Code Here

               
                // get the new class bytes
                InputStream in = zipFile.getInputStream(entry);
                byte[] clazzBytes = IOUtils.getBytes(in);
               
                classDefinitionList.add(new ClassDefinition(clazz, clazzBytes));
            }
        } catch (Exception e) {
            LOG.info("Hot swap cannot be performed for {} bundle: {}", bundleName, e.getMessage());
            LOG.debug("Hot swap cannot be performed for " + bundleName + " bundle", e);
            return false;
View Full Code Here

   
    private static String classDefinitionToString(Collection<ClassDefinition> definitions) {
        StringBuilder builder = new StringBuilder();
        Iterator<ClassDefinition> iterator = definitions.iterator();
        while(iterator.hasNext()) {
            ClassDefinition definition = iterator.next();
            builder.append(definition.getDefinitionClass().getName());
            if (iterator.hasNext()) {
                builder.append(", ");
            }
        }
       return builder.toString();
View Full Code Here

        if (_Method == null) return;

        ClassDefinition[] changes = new ClassDefinition[classSpecs.size()];
        for (int i=0; i<classSpecs.size(); i++) {
            ClassSpec spec = classSpecs.get(i);
            changes[i] = new ClassDefinition(spec._cls, spec._bytecode);
        }
        Boolean[] succeeded = new Boolean[classSpecs.size()];
        try {
            _Method.invoke(_Instance, changes, succeeded);
        } catch (IllegalAccessException e) {
View Full Code Here

            } else {
                log.trace(_loc.get("redefine-types", classes.keySet()));
                // in a Java 5 context, we can use class redefinition instead
                ClassDefinition[] defs = new ClassDefinition[array.length];
                for (int i = 0; i < defs.length; i++)
                    defs[i] = new ClassDefinition(array[i],
                        classes.get(array[i]));
                inst.redefineClasses(defs);
            }
        } catch (NoSuchMethodException e) {
            throw new InternalException(e);
View Full Code Here

               
                // get the new class bytes
                InputStream in = zipFile.getInputStream(entry);
                byte[] clazzBytes = IOUtils.getBytes(in);
               
                classDefinitionList.add(new ClassDefinition(clazz, clazzBytes));
            }
        } catch (Exception e) {
            LOG.info("Hot swap cannot be performed for {} bundle: {}", bundleName, e.getMessage());
            LOG.debug("Hot swap cannot be performed for " + bundleName + " bundle", e);
            return false;
View Full Code Here

   
    private static String classDefinitionToString(Collection<ClassDefinition> definitions) {
        StringBuilder builder = new StringBuilder();
        Iterator<ClassDefinition> iterator = definitions.iterator();
        while(iterator.hasNext()) {
            ClassDefinition definition = iterator.next();
            builder.append(definition.getDefinitionClass().getName());
            if (iterator.hasNext()) {
                builder.append(", ");
            }
        }
       return builder.toString();
View Full Code Here

        }
        assertTrue(caught);

        // Test that a null element amonst others throws NullPointerException
        caught = false;
        ClassDefinition cd = new ClassDefinition(DummyClass.class, new byte[] {1, 2, 3});
        try {
            fInst.redefineClasses(new ClassDefinition[]{ cd, null });
        } catch (NullPointerException npe) {
            caught = true;
        }
        assertTrue(caught);

        // Test that a null class throws NullPointerException
        caught = false;
        try {
            new ClassDefinition(null, new byte[] {1, 2, 3});
        } catch (NullPointerException npe) {
            caught = true;
        }
        assertTrue(caught);

        // Test that a null byte array throws NullPointerException
        caught = false;
        try {
            new ClassDefinition(DummyClass.class, null);
        } catch (NullPointerException npe) {
            caught = true;
        }
        assertTrue(caught);
    }
View Full Code Here

            } else {
                log.trace(_loc.get("redefine-types", classes.keySet()));
                // in a Java 5 context, we can use class redefinition instead
                ClassDefinition[] defs = new ClassDefinition[array.length];
                for (int i = 0; i < defs.length; i++)
                    defs[i] = new ClassDefinition(array[i],
                        classes.get(array[i]));
                inst.redefineClasses(defs);
            }
        } catch (Exception e) {
            throw new InternalException(e);
View Full Code Here

TOP

Related Classes of java.lang.instrument.ClassDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.