Example usage for java.lang Byte TYPE

List of usage examples for java.lang Byte TYPE

Introduction

In this page you can find the example usage for java.lang Byte TYPE.

Prototype

Class TYPE

To view the source code for java.lang Byte TYPE.

Click Source Link

Document

The Class instance representing the primitive type byte .

Usage

From source file:flex.messaging.services.http.proxy.RequestFilter.java

/**
 * Send the request.//www . j a  v a2  s .  c  om
 *
 * @param context the context
 */
protected void sendRequest(ProxyContext context) {
    Target target = context.getTarget();
    String method = context.getMethod();
    HttpMethod httpMethod = context.getHttpMethod();
    final String BEGIN = "-- Begin ";
    final String END = "-- End ";
    final String REQUEST = " request --";

    if (httpMethod instanceof EntityEnclosingMethod) {
        Object data = processBody(context);
        Class dataClass = data.getClass();
        if (data instanceof String) {
            String requestString = (String) data;
            if (Log.isInfo()) {
                Logger logger = Log.getLogger(HTTPProxyService.LOG_CATEGORY);
                logger.debug(BEGIN + method + REQUEST);
                logger.debug(StringUtils.prettifyString(requestString));
                logger.debug(END + method + REQUEST);
            }

            try {
                StringRequestEntity requestEntity = new StringRequestEntity(requestString, null, "UTF-8");
                ((EntityEnclosingMethod) httpMethod).setRequestEntity(requestEntity);
            } catch (UnsupportedEncodingException ex) {
                ProxyException pe = new ProxyException(CAUGHT_ERROR);
                pe.setDetails(CAUGHT_ERROR, "1", new Object[] { ex });
                throw pe;
            }
        } else if (dataClass.isArray() && Byte.TYPE.equals(dataClass.getComponentType())) {
            byte[] dataBytes = (byte[]) data;
            ByteArrayRequestEntity requestEntity = new ByteArrayRequestEntity(dataBytes,
                    context.getContentType());
            ((EntityEnclosingMethod) httpMethod).setRequestEntity(requestEntity);
        } else if (data instanceof InputStream) {
            InputStreamRequestEntity requestEntity = new InputStreamRequestEntity((InputStream) data,
                    context.getContentType());
            ((EntityEnclosingMethod) httpMethod).setRequestEntity(requestEntity);
        }
        //TODO: Support multipart post
        //else
        //{
        //FIXME: Throw exception if unhandled data type
        //}
    } else if (httpMethod instanceof GetMethod) {
        Object req = processBody(context);

        if (req instanceof String) {
            String requestString = (String) req;
            if (Log.isInfo()) {
                Logger logger = Log.getLogger(HTTPProxyService.LOG_CATEGORY);
                logger.debug(BEGIN + method + REQUEST);
                logger.debug(StringUtils.prettifyString(requestString));
                logger.debug(END + method + REQUEST);
            }

            if (!"".equals(requestString)) {
                String query = context.getHttpMethod().getQueryString();
                if (query != null) {
                    query += "&" + requestString;
                } else {
                    query = requestString;
                }
                context.getHttpMethod().setQueryString(query);
            }
        }
    }

    context.getHttpClient().setHostConfiguration(target.getHostConfig());

    try {
        context.getHttpClient().executeMethod(context.getHttpMethod());
    } catch (UnknownHostException uhex) {
        ProxyException pe = new ProxyException();
        pe.setMessage(UNKNOWN_HOST, new Object[] { uhex.getMessage() });
        pe.setCode(ProxyException.CODE_SERVER_PROXY_REQUEST_FAILED);
        throw pe;
    } catch (Exception ex) {
        // FIXME: JRB - could be more specific by looking for timeout and sending 504 in that case.
        // rfc2616 10.5.5 504 - could get more specific if we parse the HttpException
        ProxyException pe = new ProxyException(CAUGHT_ERROR);
        pe.setDetails(CAUGHT_ERROR, "1", new Object[] { ex.getMessage() });
        pe.setCode(ProxyException.CODE_SERVER_PROXY_REQUEST_FAILED);
        throw pe;
    }
}

From source file:com.sun.faces.el.impl.Coercions.java

/**
 * Coerces a double to the given primitive number class
 *///w w w .  java2  s.c o  m
static Number coerceToPrimitiveNumber(double pValue, Class pClass) throws ElException {
    if (pClass == Byte.class || pClass == Byte.TYPE) {
        return PrimitiveObjects.getByte((byte) pValue);
    } else if (pClass == Short.class || pClass == Short.TYPE) {
        return PrimitiveObjects.getShort((short) pValue);
    } else if (pClass == Integer.class || pClass == Integer.TYPE) {
        return PrimitiveObjects.getInteger((int) pValue);
    } else if (pClass == Long.class || pClass == Long.TYPE) {
        return PrimitiveObjects.getLong((long) pValue);
    } else if (pClass == Float.class || pClass == Float.TYPE) {
        return PrimitiveObjects.getFloat((float) pValue);
    } else if (pClass == Double.class || pClass == Double.TYPE) {
        return PrimitiveObjects.getDouble(pValue);
    } else {
        return PrimitiveObjects.getInteger(0);
    }
}

From source file:org.nuxeo.ecm.automation.core.impl.OperationServiceImpl.java

public static Class<?> getTypeForPrimitive(Class<?> primitiveType) {
    if (primitiveType == Boolean.TYPE) {
        return Boolean.class;
    } else if (primitiveType == Integer.TYPE) {
        return Integer.class;
    } else if (primitiveType == Long.TYPE) {
        return Long.class;
    } else if (primitiveType == Float.TYPE) {
        return Float.class;
    } else if (primitiveType == Double.TYPE) {
        return Double.class;
    } else if (primitiveType == Character.TYPE) {
        return Character.class;
    } else if (primitiveType == Byte.TYPE) {
        return Byte.class;
    } else if (primitiveType == Short.TYPE) {
        return Short.class;
    }// ww  w  .j  av  a2s.c  o m
    return primitiveType;
}

From source file:org.seedstack.seed.core.internal.application.ConfigurationMembersInjectorTest.java

public org.apache.commons.configuration.Configuration mockConfiguration(Field field, boolean isInconfig) {
    if (field == null) {
        return null;
    }//  w w  w  .  j  av a  2s  .c o  m
    org.apache.commons.configuration.Configuration configuration = mock(
            org.apache.commons.configuration.Configuration.class);
    when(configuration.containsKey(field.getName())).thenReturn(isInconfig);
    if (isInconfig) {
        Class<?> type = field.getType();
        String configParamName = field.getAnnotation(Configuration.class).value();
        if (type.isArray()) {
            type = type.getComponentType();

            if (type == Integer.TYPE || type == Integer.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Integer.MAX_VALUE) });
            } else if (type == Boolean.TYPE || type == Boolean.class) {
                when(configuration.getStringArray(configParamName)).thenReturn(new String[] { "true" });
            } else if (type == Short.TYPE || type == Short.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Short.MAX_VALUE) });
            } else if (type == Byte.TYPE || type == Byte.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Byte.MAX_VALUE) });
            } else if (type == Long.TYPE || type == Long.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Long.MAX_VALUE) });
            } else if (type == Float.TYPE || type == Float.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Float.MAX_VALUE) });
            } else if (type == Double.TYPE || type == Double.class) {
                when(configuration.getStringArray(configParamName))
                        .thenReturn(new String[] { String.valueOf(Double.MAX_VALUE) });
            } else if (type == Character.TYPE || type == Character.class) {
                when(configuration.getStringArray(configParamName)).thenReturn(new String[] { "t" });
            } else if (type == String.class) {
                when(configuration.getStringArray(configParamName)).thenReturn(new String[] { "test" });
            } else
                throw new IllegalArgumentException("Type " + type + " cannot be mocked");
        } else {
            if (type == Integer.TYPE || type == Integer.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Integer.MAX_VALUE));
            } else if (type == Boolean.TYPE || type == Boolean.class) {
                when(configuration.getString(configParamName)).thenReturn("true");
            } else if (type == Short.TYPE || type == Short.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Short.MAX_VALUE));
            } else if (type == Byte.TYPE || type == Byte.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Byte.MAX_VALUE));
            } else if (type == Long.TYPE || type == Long.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Long.MAX_VALUE));
            } else if (type == Float.TYPE || type == Float.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Float.MAX_VALUE));
            } else if (type == Double.TYPE || type == Double.class) {
                when(configuration.getString(configParamName)).thenReturn(String.valueOf(Double.MAX_VALUE));
            } else if (type == Character.TYPE || type == Character.class) {
                when(configuration.getString(configParamName)).thenReturn("t");
            } else if (type == String.class) {
                when(configuration.getString(configParamName)).thenReturn("test");
            } else
                throw new IllegalArgumentException("Type " + type + " cannot be mocked");
        }
    }
    return configuration;
}

From source file:com.sun.faces.el.impl.Coercions.java

/**
 * Coerces a Number to the given primitive number class
 *///from   w ww . j  av  a  2s  .  c  o  m
static Number coerceToPrimitiveNumber(Number pValue, Class pClass) throws ElException {
    if (pClass == Byte.class || pClass == Byte.TYPE) {
        return PrimitiveObjects.getByte(pValue.byteValue());
    } else if (pClass == Short.class || pClass == Short.TYPE) {
        return PrimitiveObjects.getShort(pValue.shortValue());
    } else if (pClass == Integer.class || pClass == Integer.TYPE) {
        return PrimitiveObjects.getInteger(pValue.intValue());
    } else if (pClass == Long.class || pClass == Long.TYPE) {
        return PrimitiveObjects.getLong(pValue.longValue());
    } else if (pClass == Float.class || pClass == Float.TYPE) {
        return PrimitiveObjects.getFloat(pValue.floatValue());
    } else if (pClass == Double.class || pClass == Double.TYPE) {
        return PrimitiveObjects.getDouble(pValue.doubleValue());
    } else if (pClass == BigInteger.class) {
        if (pValue instanceof BigDecimal)
            return ((BigDecimal) pValue).toBigInteger();
        else
            return BigInteger.valueOf(pValue.longValue());
    } else if (pClass == BigDecimal.class) {
        if (pValue instanceof BigInteger)
            return new BigDecimal((BigInteger) pValue);
        else
            return new BigDecimal(pValue.doubleValue());
    } else {
        return PrimitiveObjects.getInteger(0);
    }
}

From source file:nl.knaw.dans.common.ldap.repo.LdapMapper.java

private Object getPrimitive(Class<?> type, String s) throws NamingException {
    Object value = s;//from   w  ww  . jav  a  2s  .  c o m
    if (Integer.TYPE.equals(type)) {
        value = Integer.parseInt(s);
    } else if (Boolean.TYPE.equals(type)) {
        value = new Boolean("TRUE".equals(s));
    } else if (Long.TYPE.equals(type)) {
        value = Long.parseLong(s);
    } else if (Float.TYPE.equals(type)) {
        value = Float.parseFloat(s);
    } else if (Double.TYPE.equals(type)) {
        value = Double.parseDouble(s);
    } else if (Byte.TYPE.equals(type)) {
        value = Byte.parseByte(s);
    } else if (Short.TYPE.equals(type)) {
        value = Short.parseShort(s);
    }
    return value;
}

From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java

/**
 * Gets the bean size intern.// w w  w.  ja v  a2 s  .c  o m
 *
 * @param bean the bean
 * @param clazz the clazz
 * @param m the m
 * @param classNameMatcher the class name matcher
 * @param fieldNameMatcher the field name matcher
 * @return the bean size intern
 */
public static int getBeanSizeIntern(Object bean, Class<?> clazz, IdentityHashMap<Object, Object> m,
        Matcher<String> classNameMatcher, Matcher<String> fieldNameMatcher) {
    if (classNameMatcher.match(clazz.getName()) == false) {
        return 0;
    }
    if (clazz.isArray() == true) {
        if (clazz == boolean[].class) {
            return (((boolean[]) bean).length * 4);
        } else if (clazz == char[].class) {
            return (((char[]) bean).length * 2);
        } else if (clazz == byte[].class) {
            return (((byte[]) bean).length * 1);
        } else if (clazz == short[].class) {
            return (((short[]) bean).length * 2);
        } else if (clazz == int[].class) {
            return (((int[]) bean).length * 4);
        } else if (clazz == long[].class) {
            return (((long[]) bean).length * 4);
        } else if (clazz == float[].class) {
            return (((float[]) bean).length * 4);
        } else if (clazz == double[].class) {
            return (((double[]) bean).length * 8);
        } else {
            int length = Array.getLength(bean);
            int ret = (length * 4);
            for (int i = 0; i < length; ++i) {
                ret += getBeanSize(Array.get(bean, i), m, classNameMatcher, fieldNameMatcher);
            }
            return ret;
        }
    }
    int ret = 0;
    try {
        for (Field f : clazz.getDeclaredFields()) {
            int mod = f.getModifiers();
            if (Modifier.isStatic(mod) == true) {
                continue;
            }
            if (fieldNameMatcher.match(clazz.getName() + "." + f.getName()) == false) {
                continue;
            }
            if (f.getType() == Boolean.TYPE) {
                ret += 4;
            } else if (f.getType() == Character.TYPE) {
                ret += 2;
            } else if (f.getType() == Byte.TYPE) {
                ret += 1;
            } else if (f.getType() == Short.TYPE) {
                ret += 2;
            } else if (f.getType() == Integer.TYPE) {
                ret += 4;
            } else if (f.getType() == Long.TYPE) {
                ret += 8;
            } else if (f.getType() == Float.TYPE) {
                ret += 4;
            } else if (f.getType() == Double.TYPE) {
                ret += 8;
            } else {

                ret += 4;
                Object o = null;
                try {
                    o = readField(bean, f);
                    if (o == null) {
                        continue;
                    }
                } catch (NoClassDefFoundError ex) {
                    // nothing
                    continue;
                }
                int nestedsize = getBeanSize(o, o.getClass(), m, classNameMatcher, fieldNameMatcher);
                ret += nestedsize;
            }
        }
    } catch (NoClassDefFoundError ex) {
        // ignore here.
    }
    if (clazz == Object.class || clazz.getSuperclass() == null) {
        return ret;
    }
    ret += getBeanSizeIntern(bean, clazz.getSuperclass(), m, classNameMatcher, fieldNameMatcher);
    return ret;
}

From source file:com.sun.faces.el.impl.Coercions.java

/**
 * Coerces a String to the given primitive number class
 *///from  www.j  a va2s  .  c  om
static Number coerceToPrimitiveNumber(String pValue, Class pClass) throws ElException {
    if (pClass == Byte.class || pClass == Byte.TYPE) {
        return Byte.valueOf(pValue);
    } else if (pClass == Short.class || pClass == Short.TYPE) {
        return Short.valueOf(pValue);
    } else if (pClass == Integer.class || pClass == Integer.TYPE) {
        return Integer.valueOf(pValue);
    } else if (pClass == Long.class || pClass == Long.TYPE) {
        return Long.valueOf(pValue);
    } else if (pClass == Float.class || pClass == Float.TYPE) {
        return Float.valueOf(pValue);
    } else if (pClass == Double.class || pClass == Double.TYPE) {
        return Double.valueOf(pValue);
    } else if (pClass == BigInteger.class) {
        return new BigInteger(pValue);
    } else if (pClass == BigDecimal.class) {
        return new BigDecimal(pValue);
    } else {
        return PrimitiveObjects.getInteger(0);
    }
}

From source file:bammerbom.ultimatecore.bukkit.resources.utils.BossbarUtil.java

public Object getTeleportPacket(Location loc) {
    Class<?> PacketPlayOutEntityTeleport = Util.getCraftClass("PacketPlayOutEntityTeleport");

    Object packet = null;/*  w  w w .  ja v  a 2  s  . c  o m*/
    try {
        packet = PacketPlayOutEntityTeleport
                .getConstructor(new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE, Byte.TYPE,
                        Byte.TYPE, Boolean.TYPE })
                .newInstance(new Object[] { Integer.valueOf(this.id), Integer.valueOf(loc.getBlockX() * 32),
                        Integer.valueOf(loc.getBlockY() * 32), Integer.valueOf(loc.getBlockZ() * 32),
                        Byte.valueOf((byte) ((int) loc.getYaw() * 256 / 360)),
                        Byte.valueOf((byte) ((int) loc.getPitch() * 256 / 360)), Boolean.valueOf(false) });
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }

    return packet;
}

From source file:org.apache.hadoop.hbase.io.HbaseObjectWritable.java

/**
 * Read a {@link Writable}, {@link String}, primitive type, or an array of
 * the preceding.// w  w  w . jav  a  2 s.  com
 * @param in
 * @param objectWritable
 * @param conf
 * @return the object
 * @throws IOException
 */
@SuppressWarnings("unchecked")
public static Object readObject(DataInput in, HbaseObjectWritable objectWritable, Configuration conf)
        throws IOException {
    Class<?> declaredClass = CODE_TO_CLASS.get(WritableUtils.readVInt(in));
    Object instance;
    if (declaredClass.isPrimitive()) { // primitive types
        if (declaredClass == Boolean.TYPE) { // boolean
            instance = Boolean.valueOf(in.readBoolean());
        } else if (declaredClass == Character.TYPE) { // char
            instance = Character.valueOf(in.readChar());
        } else if (declaredClass == Byte.TYPE) { // byte
            instance = Byte.valueOf(in.readByte());
        } else if (declaredClass == Short.TYPE) { // short
            instance = Short.valueOf(in.readShort());
        } else if (declaredClass == Integer.TYPE) { // int
            instance = Integer.valueOf(in.readInt());
        } else if (declaredClass == Long.TYPE) { // long
            instance = Long.valueOf(in.readLong());
        } else if (declaredClass == Float.TYPE) { // float
            instance = Float.valueOf(in.readFloat());
        } else if (declaredClass == Double.TYPE) { // double
            instance = Double.valueOf(in.readDouble());
        } else if (declaredClass == Void.TYPE) { // void
            instance = null;
        } else {
            throw new IllegalArgumentException("Not a primitive: " + declaredClass);
        }
    } else if (declaredClass.isArray()) { // array
        if (declaredClass.equals(byte[].class)) {
            instance = Bytes.readByteArray(in);
        } else if (declaredClass.equals(Result[].class)) {
            instance = Result.readArray(in);
        } else {
            int length = in.readInt();
            instance = Array.newInstance(declaredClass.getComponentType(), length);
            for (int i = 0; i < length; i++) {
                Array.set(instance, i, readObject(in, conf));
            }
        }
    } else if (declaredClass.equals(Array.class)) { //an array not declared in CLASS_TO_CODE
        Class<?> componentType = readClass(conf, in);
        int length = in.readInt();
        instance = Array.newInstance(componentType, length);
        for (int i = 0; i < length; i++) {
            Array.set(instance, i, readObject(in, conf));
        }
    } else if (List.class.isAssignableFrom(declaredClass)) { // List
        int length = in.readInt();
        instance = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            ((ArrayList) instance).add(readObject(in, conf));
        }
    } else if (declaredClass == String.class) { // String
        instance = Text.readString(in);
    } else if (declaredClass.isEnum()) { // enum
        instance = Enum.valueOf((Class<? extends Enum>) declaredClass, Text.readString(in));
    } else if (declaredClass == Message.class) {
        String className = Text.readString(in);
        try {
            declaredClass = getClassByName(conf, className);
            instance = tryInstantiateProtobuf(declaredClass, in);
        } catch (ClassNotFoundException e) {
            LOG.error("Can't find class " + className, e);
            throw new IOException("Can't find class " + className, e);
        }
    } else { // Writable or Serializable
        Class instanceClass = null;
        int b = (byte) WritableUtils.readVInt(in);
        if (b == NOT_ENCODED) {
            String className = Text.readString(in);
            try {
                instanceClass = getClassByName(conf, className);
            } catch (ClassNotFoundException e) {
                LOG.error("Can't find class " + className, e);
                throw new IOException("Can't find class " + className, e);
            }
        } else {
            instanceClass = CODE_TO_CLASS.get(b);
        }
        if (Writable.class.isAssignableFrom(instanceClass)) {
            Writable writable = WritableFactories.newInstance(instanceClass, conf);
            try {
                writable.readFields(in);
            } catch (Exception e) {
                LOG.error("Error in readFields", e);
                throw new IOException("Error in readFields", e);
            }
            instance = writable;
            if (instanceClass == NullInstance.class) { // null
                declaredClass = ((NullInstance) instance).declaredClass;
                instance = null;
            }
        } else {
            int length = in.readInt();
            byte[] objectBytes = new byte[length];
            in.readFully(objectBytes);
            ByteArrayInputStream bis = null;
            ObjectInputStream ois = null;
            try {
                bis = new ByteArrayInputStream(objectBytes);
                ois = new ObjectInputStream(bis);
                instance = ois.readObject();
            } catch (ClassNotFoundException e) {
                LOG.error("Class not found when attempting to deserialize object", e);
                throw new IOException("Class not found when attempting to " + "deserialize object", e);
            } finally {
                if (bis != null)
                    bis.close();
                if (ois != null)
                    ois.close();
            }
        }
    }
    if (objectWritable != null) { // store values
        objectWritable.declaredClass = declaredClass;
        objectWritable.instance = instance;
    }
    return instance;
}