I am trying to manipulate a static method. For this, Byte Buddy or any other framework can be used.
There is one library that is called Pi4J that is used for controlling
The code for Pi4J is open source on github under LGPL license. You can simply clone the repository, modify to your needs and use own version. If you feel your changes can help others as well think about contributing tp pi4j.