|
Play Framework/Scala example source code file (MonkeyPatcher.scala)
The MonkeyPatcher.scala Play Framework example source code
/*
*
* * Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
*
*/
package play.api.libs.ws.ssl
import java.lang.reflect.Field
/**
*
*/
trait MonkeyPatcher {
// Define unsafe to monkeypatch fields
private val unsafe: sun.misc.Unsafe = {
val field = Class.forName("sun.misc.Unsafe").getDeclaredField("theUnsafe")
field.setAccessible(true)
field.get(null).asInstanceOf[sun.misc.Unsafe]
}
/**
* Monkeypatches any given field.
*
* @param field the field to change
* @param newObject the new object to place in the field.
*/
def monkeyPatchField(field: Field, newObject: AnyRef) {
val base = unsafe.staticFieldBase(field)
val offset = unsafe.staticFieldOffset(field)
unsafe.putObject(base, offset, newObject)
}
}
Other Play Framework source code examplesHere is a short list of links related to this Play Framework MonkeyPatcher.scala source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.