List of usage examples for java.lang Long TYPE
Class TYPE
To view the source code for java.lang Long TYPE.
Click Source Link
From source file:com.fjn.helper.common.io.file.common.FileUpAndDownloadUtil.java
/** * ???????//from w w w. j a v a 2 s . co m * @param klass ???klass?Class * @param filepath ? * @param sizeThreshold ?? * @param isFileNameBaseTime ???? * @return bean */ public static <T> Object upload(HttpServletRequest request, Class<T> klass, String filepath, int sizeThreshold, boolean isFileNameBaseTime) throws Exception { FileItemFactory fileItemFactory = null; if (sizeThreshold > 0) { File repository = new File(filepath); fileItemFactory = new DiskFileItemFactory(sizeThreshold, repository); } else { fileItemFactory = new DiskFileItemFactory(); } ServletFileUpload upload = new ServletFileUpload(fileItemFactory); ServletRequestContext requestContext = new ServletRequestContext(request); T bean = null; if (klass != null) { bean = klass.newInstance(); } // if (ServletFileUpload.isMultipartContent(requestContext)) { File parentDir = new File(filepath); List<FileItem> fileItemList = upload.parseRequest(requestContext); for (int i = 0; i < fileItemList.size(); i++) { FileItem item = fileItemList.get(i); // ?? if (item.isFormField()) { String paramName = item.getFieldName(); String paramValue = item.getString("UTF-8"); log.info("?" + paramName + "=" + paramValue); request.setAttribute(paramName, paramValue); // ?bean if (klass != null) { Field field = null; try { field = klass.getDeclaredField(paramName); if (field != null) { field.setAccessible(true); Class type = field.getType(); if (type == Integer.TYPE) { field.setInt(bean, Integer.valueOf(paramValue)); } else if (type == Double.TYPE) { field.setDouble(bean, Double.valueOf(paramValue)); } else if (type == Float.TYPE) { field.setFloat(bean, Float.valueOf(paramValue)); } else if (type == Boolean.TYPE) { field.setBoolean(bean, Boolean.valueOf(paramValue)); } else if (type == Character.TYPE) { field.setChar(bean, paramValue.charAt(0)); } else if (type == Long.TYPE) { field.setLong(bean, Long.valueOf(paramValue)); } else if (type == Short.TYPE) { field.setShort(bean, Short.valueOf(paramValue)); } else { field.set(bean, paramValue); } } } catch (NoSuchFieldException e) { log.info("" + klass.getName() + "?" + paramName); } } } // else { // <input type='file' name='xxx'> xxx String paramName = item.getFieldName(); log.info("?" + item.getSize()); if (sizeThreshold > 0) { if (item.getSize() > sizeThreshold) continue; } String clientFileName = item.getName(); int index = -1; // ?IE? if ((index = clientFileName.lastIndexOf("\\")) != -1) { clientFileName = clientFileName.substring(index + 1); } if (clientFileName == null || "".equals(clientFileName)) continue; String filename = null; log.info("" + paramName + "\t??" + clientFileName); if (isFileNameBaseTime) { filename = buildFileName(clientFileName); } else filename = clientFileName; request.setAttribute(paramName, filename); // ?bean if (klass != null) { Field field = null; try { field = klass.getDeclaredField(paramName); if (field != null) { field.setAccessible(true); field.set(bean, filename); } } catch (NoSuchFieldException e) { log.info("" + klass.getName() + "? " + paramName); continue; } } if (!parentDir.exists()) { parentDir.mkdirs(); } File newfile = new File(parentDir, filename); item.write(newfile); String serverPath = newfile.getPath(); log.info("?" + serverPath); } } } return bean; }
From source file:org.wrml.runtime.syntax.DefaultSyntaxLoader.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public final <T> T parseSyntacticText(final String text, final java.lang.reflect.Type targetType) { if (text == null) { return null; }//from w w w .ja va 2 s .com if (targetType == null || targetType.equals(String.class)) { return (T) text; } if (targetType.equals(Integer.TYPE) || targetType.equals(Integer.class)) { return (T) new Integer(text); } if (targetType.equals(Boolean.TYPE) || targetType.equals(Boolean.class)) { return (T) (text.equals("true") ? Boolean.TRUE : Boolean.FALSE); } if (targetType.equals(Long.TYPE) || targetType.equals(Long.class)) { return (T) new Long(text); } if (targetType.equals(Double.TYPE) || targetType.equals(Double.class)) { return (T) new Double(text); } if (TypeUtils.isAssignable(targetType, Enum.class)) { return (T) Enum.valueOf((Class<Enum>) targetType, text); } if (targetType instanceof Class<?>) { final SyntaxHandler<?> syntaxHandler = getSyntaxHandler((Class<?>) targetType); if (syntaxHandler != null) { return (T) syntaxHandler.parseSyntacticText(text); } } throw new SyntaxRegistryException( "Failed to transform text: \"" + text + "\" value to target type: " + targetType, null, this); }
From source file:net.sf.json.JSONDynaBean.java
/** * DOCUMENT ME!/*from w ww . j ava2 s . co m*/ * * @param name DOCUMENT ME! * * @return DOCUMENT ME! */ public Object get(String name) { Object value = dynaValues.get(name); if (value != null) { return value; } Class type = getDynaProperty(name).getType(); if (type == null) { throw new NullPointerException("Unspecified property type for " + name); } if (!type.isPrimitive()) { return value; } if (type == Boolean.TYPE) { return Boolean.FALSE; } else if (type == Byte.TYPE) { return new Byte((byte) 0); } else if (type == Character.TYPE) { return new Character((char) 0); } else if (type == Short.TYPE) { return new Short((short) 0); } else if (type == Integer.TYPE) { return new Integer(0); } else if (type == Long.TYPE) { return new Long(0); } else if (type == Float.TYPE) { return new Float(0.0); } else if (type == Double.TYPE) { return new Double(0); } return null; }
From source file:Main.java
/** * renderArray returns an array similar to a List. If the array type is an * object they are rendered with "render(object)" for each. If the array * type is a primitive each element is added directly to the string buffer * collecting the result.// w w w. j a v a 2s.co m * * @param o * @param objectClass * @return */ private static StringBuffer renderArray(Object o, Class<?> objectClass) { Class<?> componentType = objectClass.getComponentType(); StringBuffer sb = new StringBuffer(ARRAY_PREFIX); if (componentType.isPrimitive() == false) { Object[] oa = (Object[]) o; for (int i = 0; i < oa.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(render(oa[i])); } } else { if (Boolean.TYPE.equals(componentType)) { boolean[] ba = (boolean[]) o; for (int i = 0; i < ba.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ba[i]); } } else if (Integer.TYPE.equals(componentType)) { int[] ia = (int[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Long.TYPE.equals(componentType)) { long[] ia = (long[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Double.TYPE.equals(componentType)) { double[] ia = (double[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Float.TYPE.equals(componentType)) { float[] ia = (float[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Character.TYPE.equals(componentType)) { char[] ia = (char[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Short.TYPE.equals(componentType)) { short[] ia = (short[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } else if (Byte.TYPE.equals(componentType)) { byte[] ia = (byte[]) o; for (int i = 0; i < ia.length; i++) { if (i > 0) { sb.append(ELEMENT_SEPARATOR); } sb.append(ia[i]); } } } sb.append(ARRAY_SUFFIX); return sb; }
From source file:org.briljantframework.data.vector.Convert.java
@SuppressWarnings("unchecked") private static <T> T convertLogical(Class<T> cls, Logical log) { if (cls.equals(Double.class) || cls.equals(Double.TYPE)) { return (T) (Double) (log == Logical.TRUE ? 1.0 : 0.0); } else if (cls.equals(Float.class) || cls.equals(Float.TYPE)) { return (T) (Float) (log == Logical.TRUE ? 1.0f : 0.0f); } else if (cls.equals(Long.class) || cls.equals(Long.TYPE)) { return (T) (Long) (log == Logical.TRUE ? 1l : 0l); } else if (cls.equals(Integer.class) || cls.equals(Integer.TYPE)) { return (T) (Integer) (log == Logical.TRUE ? 1 : 0); } else if (cls.equals(Short.class) || cls.equals(Short.TYPE)) { return (T) (Short) (log == Logical.TRUE ? (short) 1 : (short) 0); } else if (cls.equals(Byte.class) || cls.equals(Byte.TYPE)) { return (T) (Byte) (log == Logical.TRUE ? (byte) 1 : (byte) 0); } else if (Complex.class.equals(cls)) { return cls.cast(log == Logical.TRUE ? Complex.ONE : Complex.ZERO); } else if (Boolean.class.equals(cls)) { return cls.cast(log == Logical.TRUE); } else {/*from w ww . j a v a 2s. co m*/ return Na.of(cls); } }
From source file:org.hyperic.hq.plugin.jboss.MBeanUtil.java
private static void initConverters() { addConverter(Object.class, new Converter() { public Object convert(String param) { return param; }//from ww w .j av a 2 s .c o m }); addConverter(Short.class, new Converter() { public Object convert(String param) { return Short.valueOf(param); } }); addConverter(Integer.class, new Converter() { public Object convert(String param) { return Integer.valueOf(param); } }); addConverter(Long.class, new Converter() { public Object convert(String param) { return Long.valueOf(param); } }); addConverter(Double.class, new Converter() { public Object convert(String param) { return Double.valueOf(param); } }); addConverter(Boolean.class, new Converter() { public Object convert(String param) { return Boolean.valueOf(param); } }); addConverter(File.class, new Converter() { public Object convert(String param) { return new File(param); } }); addConverter(URL.class, new Converter() { public Object convert(String param) { try { return new URL(param); } catch (MalformedURLException e) { throw invalid(param, e); } } }); addConverter(ObjectName.class, new Converter() { public Object convert(String param) { try { return new ObjectName(param); } catch (MalformedObjectNameException e) { throw invalid(param, e); } } }); addConverter(List.class, new ListConverter() { public Object convert(String[] params) { return Arrays.asList(params); } }); addConverter(String[].class, new ListConverter() { public Object convert(String[] params) { return params; } }); Class[][] aliases = { { String.class, Object.class }, { Short.TYPE, Short.class }, { Integer.TYPE, Integer.class }, { Long.TYPE, Long.class }, { Double.TYPE, Double.class }, { Boolean.TYPE, Boolean.class }, }; for (int i = 0; i < aliases.length; i++) { addConverter(aliases[i][0], aliases[i][1]); } }
From source file:com.twitter.elephantbird.pig.piggybank.Invoker.java
private static Class<?> unPrimitivize(Class<?> klass) { if (klass.equals(Integer.TYPE)) { return Integer.class; }/*from www .j a va2s . com*/ if (klass.equals(Long.TYPE)) { return Long.class; } else if (klass.equals(Float.TYPE)) { return Float.class; } else if (klass.equals(Double.TYPE)) { return Double.class; } else if (klass.equals(DOUBLE_ARRAY_CLASS)) { return DOUBLE_ARRAY_CLASS; } else { return klass; } }
From source file:org.jcommon.com.util.JsonUtils.java
public static String toJson(Object o, boolean encode) { StringBuilder sb = new StringBuilder(); Class<?> type = null;// www . j a v a 2 s . co m sb.append("{"); try { java.lang.reflect.Field[] fs = o.getClass().getDeclaredFields(); String name, value; for (java.lang.reflect.Field f : fs) { value = null; name = f.getName(); type = f.getType(); java.lang.reflect.Method m = getMethod(o.getClass(), "get" + name); if (m == null) m = getMethod(o.getClass(), "is" + name); if (m != null) { if (String.class == type) { value = (String) m.invoke(o); } else if (java.lang.Integer.class == type || Integer.TYPE == type) { value = String.valueOf((Integer) m.invoke(o)); } else if (java.lang.Boolean.class == type || Boolean.TYPE == type) { value = String.valueOf((Boolean) m.invoke(o)); } else if (java.lang.Long.class == type || Long.TYPE == type) { value = String.valueOf((Long) m.invoke(o)); } else if (java.lang.Float.class == type || Float.TYPE == type) { value = String.valueOf((Float) m.invoke(o)); } else if (java.lang.Long.class == type || Long.TYPE == type) { logger.info("not map Class:" + type); } } if (value != null) { if (encode) sb.append("\"" + CoderUtils.encode(name) + "\"" + ":\"" + CoderUtils.encode(value) + "\""); else sb.append("\"" + name + "\"" + ":\"" + value + "\""); sb.append(","); } } } catch (Throwable t) { logger.error("", t); } if (sb.lastIndexOf(",") == sb.length() - 1) sb.deleteCharAt(sb.length() - 1); sb.append("}"); return sb.toString(); }
From source file:com.google.api.server.spi.response.ServletResponseResultWriter.java
private static SimpleModule getWriteLongAsStringModule() { JsonSerializer<Long> longSerializer = new JsonSerializer<Long>() { @Override//from w w w . ja va2 s. c om public void serialize(Long value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeString(value.toString()); } }; SimpleModule writeLongAsStringModule = new SimpleModule("writeLongAsStringModule", new Version(1, 0, 0, null, null, null)); writeLongAsStringModule.addSerializer(Long.TYPE, longSerializer); // long (primitive) writeLongAsStringModule.addSerializer(Long.class, longSerializer); // Long (class) return writeLongAsStringModule; }
From source file:MethodHashing.java
static String getTypeString(Class cl) { if (cl == Byte.TYPE) { return "B"; } else if (cl == Character.TYPE) { return "C"; } else if (cl == Double.TYPE) { return "D"; } else if (cl == Float.TYPE) { return "F"; } else if (cl == Integer.TYPE) { return "I"; } else if (cl == Long.TYPE) { return "J"; } else if (cl == Short.TYPE) { return "S"; } else if (cl == Boolean.TYPE) { return "Z"; } else if (cl == Void.TYPE) { return "V"; } else if (cl.isArray()) { return "[" + getTypeString(cl.getComponentType()); } else {//w w w .j a v a 2 s.c om return "L" + cl.getName().replace('.', '/') + ";"; } }