
com.googlecode.jinahya.rfc3986.PercentBinaryEncoderProxy Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2011 Jin Kwon.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.googlecode.jinahya.rfc3986;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* Proxy for
* org.apache.commons.codec.BinaryEncoder
.
*
*
* // create
* final BinaryEncoder encoder = (BinaryEncoder)
* PercentBinaryEncoderProxy.newInstance();
*
* // encode
* encoder.encode(byte[]);
*
*
*
* @author Jin Kwon
* @see BinaryEncoder (Apache Commons Codec)
*/
public class PercentBinaryEncoderProxy implements InvocationHandler {
/**
* BinaryEncoder Class.
*/
private static final Class BINARY_ENCODER_CLAZZ;
static {
try {
BINARY_ENCODER_CLAZZ = Class.forName(
"org.apache.commons.codec.BinaryEncoder");
} catch (ClassNotFoundException cnfe) {
throw new InstantiationError(cnfe.getMessage());
}
}
/**
* EncoderException Constructor.
*/
private static final Constructor ENCODER_EXCEPTION_CONSTRUCTOR;
static {
try {
ENCODER_EXCEPTION_CONSTRUCTOR = Class.forName(
"org.apache.commons.codec.EncoderException").getConstructor(
new Class[]{Throwable.class});
} catch (ClassNotFoundException cnfe) {
throw new InstantiationError(cnfe.getMessage());
} catch (NoSuchMethodException nsme) {
throw new InstantiationError(nsme.getMessage());
}
}
/**
* Creates a new instance.
*
* @return a new proxy instance.
*/
public static Object newInstance() {
return Proxy.newProxyInstance(
BINARY_ENCODER_CLAZZ.getClassLoader(),
new Class[]{BINARY_ENCODER_CLAZZ},
new PercentBinaryEncoderProxy());
}
/**
* Creates a new instance.
*/
protected PercentBinaryEncoderProxy() {
super();
}
//@Override
public Object invoke(final Object proxy, final Method method,
final Object[] args)
throws Throwable {
if (args[0] == null) {
throw new NullPointerException("null source");
}
return PercentEncoder.encode((byte[]) args[0]);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy