Java 8 ClassFileTransformer - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ClassFileTransformer class.

This code example shows how to use the following methods:transform
	} 
 
	public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
			ProtectionDomain protectionDomain, byte[] classfileBuffer) throws Exception {
 
		return this.transformer.transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
	} 
 
	public void unregisterClassLoader(ClassLoader loader) {
	} 
 
 
	@Override 
	public String toString() {
		StringBuilder builder = new StringBuilder(getClass().getName());
		builder.append(" for transformer: ");
		builder.append(this.transformer);
		return builder.toString();
	} 
 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:transform
	public void initialize(Hashtable<?, ?> params) {
	} 
 
	public byte[] preProcess(String className, byte[] classBytes) {
		try { 
			byte[] result = this.transformer.transform(this.loader, className, null, null, classBytes);
			return (result != null ? result : classBytes);
		} 
		catch (IllegalClassFormatException ex) {
			throw new IllegalStateException("Cannot transform due to illegal class format", ex);
		} 
	} 
 
	@Override 
	public String toString() {
		return getClass().getName() + " for transformer: " + this.transformer;
	} 
 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:transform
This code example shows how to use the following methods:transform
 
	protected byte[] transform(String className, byte[] classfileBuffer, CodeSource codeSource, ClassLoader classLoader)
			throws Exception {
 
		// NB: WebSphere passes className as "." without class while the transformer expects a VM, "/" format 
		byte[] result = transformer.transform(classLoader, className.replace('.', '/'), null, null, classfileBuffer);
		return (result != null ? result : classfileBuffer);
	} 
 
	@Override 
	public String toString() {
		StringBuilder builder = new StringBuilder(getClass().getName());
		builder.append(" for transformer: ");
		builder.append(this.transformer);
		return builder.toString();
	} 
 
 
	private static class Dummy { 
	} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:transform
		String path = name.replace('.', '/').concat(".class");
		Resource res = new URLClassPath(getURLs()).getResource(path, false);
		if (res != null) {
			try { 
				byte[] b = res.getBytes();
				byte[] transformed = transformer.transform(this, name, null,
						null, b);
				if (transformed == null)
					transformed = b;
				return defineClass(name, transformed, 0, transformed.length);
			} catch (Exception e) {
				return super.findClass(name);
			} 
		} 
		return super.findClass(name);
	} 
 
	/** 
	 * Determines if a class can be transformed based on the name. In most cases 
	 * as class is non transformable because it is part of the JRE and loaded by 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:transform
This code example shows how to use the following methods:transform
    public byte[] transform(ClassLoader loader, String className,
                            Class<?> redefinedClass,
                            ProtectionDomain protectionDomain,
                            byte[] bytecode)
        throws IllegalClassFormatException {
      byte[] data = transformer.transform(loader, className, redefinedClass,
                                          protectionDomain, bytecode);
      if (data != null) {
        DebugUtils.dump(className, data, Kind.CLASS);
      } 
      return data;
    } 
  } 
 
  private static void configure() { 
    String configClass = System.getProperty("com.google.java.contract.configurator");
    if (configClass != null) {
      try { 
        Class<?> clazz = Class.forName(configClass);
        Object instance = clazz.newInstance();
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:transform
This code example shows how to use the following methods:transform
			try { 
				// Our class should get instrumented: 
				final byte[] data = TargetLoader
						.getClassDataAsBytes(ModifiedSystemClassRuntimeTest.class); 
				verifyInstrumentedClass(TARGET_CLASS_NAME,
						transformer.transform(null, TARGET_CLASS_NAME, null,
								null, data));
 
				// Other classes will not be instrumented: 
				assertNull(transformer.transform(getClass().getClassLoader(),
						"some/other/Class", null, null, new byte[0])); 
			} catch (Exception e) {
				throw new RuntimeException(e);
			} 
		} 
 
		public boolean removeTransformer(ClassFileTransformer transformer) {
			assertTrue(added);
			assertFalse(removed);
			removed = true;
4
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 ClassFileTransformer Methods: