List of usage examples for java.lang Byte valueOf
public static Byte valueOf(String s) throws NumberFormatException
From source file:org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.partitioners.WeightedRangePartitioner.java
private PigNullableWritable getPigNullableWritable(Tuple t) { try {/*from w ww. j ava 2 s. co m*/ // user comparators work with tuples - so if user comparator // is being used OR if there are more than 1 sort cols, use // NullableTuple if ("true".equals(job.get("pig.usercomparator")) || t.size() > 1) { return new NullableTuple(t); } else { Object o = t.get(0); String kts = job.get("pig.reduce.key.type"); if (kts == null) { throw new RuntimeException("Didn't get reduce key type " + "from config file."); } return HDataType.getWritableComparableTypes(o, Byte.valueOf(kts)); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.apache.rocketmq.jms.msg.RocketMQMessage.java
@Override public byte getByteProperty(String name) throws JMSException { if (propertyExists(name)) { Object value = getObjectProperty(name); return Byte.valueOf(value.toString()); }/* w ww . j a va 2 s. co m*/ return 0; }
From source file:in.bbat.license.LicenseManager.java
public static String getMacId() { try {// ww w . jav a2s . c o m InetAddress localInetAddress = InetAddress.getLocalHost(); NetworkInterface localNetworkInterface = NetworkInterface.getByInetAddress(localInetAddress); byte[] arrayOfByte = localNetworkInterface.getHardwareAddress(); StringBuilder localStringBuilder = new StringBuilder(); for (int i = 0; i < arrayOfByte.length; i++) localStringBuilder.append(String.format("%02X%s", new Object[] { Byte.valueOf(arrayOfByte[i]), i < arrayOfByte.length - 1 ? "-" : "" })); return localStringBuilder.toString(); } catch (Exception localException) { } return ""; }
From source file:org.apache.hadoop.hive.ql.optimizer.calcite.translator.ExprNodeConverter.java
/** * TODO: 1. Handle NULL/*from w w w . j a va2s.c o m*/ */ @Override public ExprNodeDesc visitLiteral(RexLiteral literal) { RelDataType lType = literal.getType(); switch (literal.getType().getSqlTypeName()) { case BOOLEAN: return new ExprNodeConstantDesc(TypeInfoFactory.booleanTypeInfo, Boolean.valueOf(RexLiteral.booleanValue(literal))); case TINYINT: return new ExprNodeConstantDesc(TypeInfoFactory.byteTypeInfo, Byte.valueOf(((Number) literal.getValue3()).byteValue())); case SMALLINT: return new ExprNodeConstantDesc(TypeInfoFactory.shortTypeInfo, Short.valueOf(((Number) literal.getValue3()).shortValue())); case INTEGER: return new ExprNodeConstantDesc(TypeInfoFactory.intTypeInfo, Integer.valueOf(((Number) literal.getValue3()).intValue())); case BIGINT: return new ExprNodeConstantDesc(TypeInfoFactory.longTypeInfo, Long.valueOf(((Number) literal.getValue3()).longValue())); case FLOAT: case REAL: return new ExprNodeConstantDesc(TypeInfoFactory.floatTypeInfo, Float.valueOf(((Number) literal.getValue3()).floatValue())); case DOUBLE: return new ExprNodeConstantDesc(TypeInfoFactory.doubleTypeInfo, Double.valueOf(((Number) literal.getValue3()).doubleValue())); case DATE: return new ExprNodeConstantDesc(TypeInfoFactory.dateTypeInfo, new Date(((Calendar) literal.getValue()).getTimeInMillis())); case TIME: case TIMESTAMP: { Object value = literal.getValue3(); if (value instanceof Long) { value = new Timestamp((Long) value); } return new ExprNodeConstantDesc(TypeInfoFactory.timestampTypeInfo, value); } case BINARY: return new ExprNodeConstantDesc(TypeInfoFactory.binaryTypeInfo, literal.getValue3()); case DECIMAL: return new ExprNodeConstantDesc( TypeInfoFactory.getDecimalTypeInfo(lType.getPrecision(), lType.getScale()), literal.getValue3()); case VARCHAR: { int varcharLength = lType.getPrecision(); // If we cannot use Varchar due to type length restrictions, we use String if (varcharLength < 1 || varcharLength > HiveVarchar.MAX_VARCHAR_LENGTH) { return new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, literal.getValue3()); } return new ExprNodeConstantDesc(TypeInfoFactory.getVarcharTypeInfo(varcharLength), new HiveVarchar((String) literal.getValue3(), varcharLength)); } case CHAR: { int charLength = lType.getPrecision(); // If we cannot use Char due to type length restrictions, we use String if (charLength < 1 || charLength > HiveChar.MAX_CHAR_LENGTH) { return new ExprNodeConstantDesc(TypeInfoFactory.stringTypeInfo, literal.getValue3()); } return new ExprNodeConstantDesc(TypeInfoFactory.getCharTypeInfo(charLength), new HiveChar((String) literal.getValue3(), charLength)); } case INTERVAL_YEAR_MONTH: { BigDecimal monthsBd = (BigDecimal) literal.getValue(); return new ExprNodeConstantDesc(TypeInfoFactory.intervalYearMonthTypeInfo, new HiveIntervalYearMonth(monthsBd.intValue())); } case INTERVAL_DAY_TIME: { BigDecimal millisBd = (BigDecimal) literal.getValue(); // Calcite literal is in millis, we need to convert to seconds BigDecimal secsBd = millisBd.divide(BigDecimal.valueOf(1000)); return new ExprNodeConstantDesc(TypeInfoFactory.intervalDayTimeTypeInfo, new HiveIntervalDayTime(secsBd)); } case OTHER: default: return new ExprNodeConstantDesc(TypeInfoFactory.voidTypeInfo, literal.getValue3()); } }
From source file:org.openspaces.rest.utils.ControllerUtils.java
public static Object convertPropertyToPrimitiveType(String object, Class type, String propKey) { if (type.equals(Long.class) || type.equals(Long.TYPE)) return Long.valueOf(object); if (type.equals(Boolean.class) || type.equals(Boolean.TYPE)) return Boolean.valueOf(object); if (type.equals(Integer.class) || type.equals(Integer.TYPE)) return Integer.valueOf(object); if (type.equals(Byte.class) || type.equals(Byte.TYPE)) return Byte.valueOf(object); if (type.equals(Short.class) || type.equals(Short.TYPE)) return Short.valueOf(object); if (type.equals(Float.class) || type.equals(Float.TYPE)) return Float.valueOf(object); if (type.equals(Double.class) || type.equals(Double.TYPE)) return Double.valueOf(object); if (type.isEnum()) return Enum.valueOf(type, object); if (type.equals(String.class) || type.equals(Object.class)) return String.valueOf(object); if (type.equals(java.util.Date.class)) { try {/*w w w . j a v a2 s.c om*/ return simpleDateFormat.parse(object); } catch (ParseException e) { throw new RestException( "Unable to parse date [" + object + "]. Make sure it matches the format: " + date_format); } } //unknown type throw new UnsupportedTypeException("Non primitive type when converting property [" + propKey + "]:" + type); }
From source file:com.alibaba.dubbo.governance.web.common.module.screen.Restful.java
private static Object convertPrimitive(Class<?> cls, String value) { if (cls == boolean.class || cls == Boolean.class) { return value == null || value.length() == 0 ? false : Boolean.valueOf(value); } else if (cls == byte.class || cls == Byte.class) { return value == null || value.length() == 0 ? 0 : Byte.valueOf(value); } else if (cls == char.class || cls == Character.class) { return value == null || value.length() == 0 ? '\0' : value.charAt(0); } else if (cls == short.class || cls == Short.class) { return value == null || value.length() == 0 ? 0 : Short.valueOf(value); } else if (cls == int.class || cls == Integer.class) { return value == null || value.length() == 0 ? 0 : Integer.valueOf(value); } else if (cls == long.class || cls == Long.class) { return value == null || value.length() == 0 ? 0 : Long.valueOf(value); } else if (cls == float.class || cls == Float.class) { return value == null || value.length() == 0 ? 0 : Float.valueOf(value); } else if (cls == double.class || cls == Double.class) { return value == null || value.length() == 0 ? 0 : Double.valueOf(value); }/*from www .jav a 2s . c o m*/ return value; }
From source file:org.unitime.timetable.server.script.ScriptExecution.java
@Override protected void execute() throws Exception { org.hibernate.Session hibSession = ScriptDAO.getInstance().getSession(); Transaction tx = hibSession.beginTransaction(); try {/*from w w w . j a va2 s . c om*/ setStatus("Starting up...", 3); Script script = ScriptDAO.getInstance().get(iRequest.getScriptId(), hibSession); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName(script.getEngine()); engine.put("hibSession", hibSession); engine.put("session", SessionDAO.getInstance().get(getSessionId())); engine.put("log", this); incProgress(); engine.getContext().setWriter(new Writer() { @Override public void write(char[] cbuf, int off, int len) throws IOException { String line = String.valueOf(cbuf, off, len); if (line.endsWith("\n")) line = line.substring(0, line.length() - 1); if (!line.isEmpty()) info(line); } @Override public void flush() throws IOException { } @Override public void close() throws IOException { } }); engine.getContext().setErrorWriter(new Writer() { @Override public void write(char[] cbuf, int off, int len) throws IOException { String line = String.valueOf(cbuf, off, len); if (line.endsWith("\n")) line = line.substring(0, line.length() - 1); if (!line.isEmpty()) warn(line); } @Override public void flush() throws IOException { } @Override public void close() throws IOException { } }); incProgress(); debug("Engine: " + engine.getFactory().getEngineName() + " (ver. " + engine.getFactory().getEngineVersion() + ")"); debug("Language: " + engine.getFactory().getLanguageName() + " (ver. " + engine.getFactory().getLanguageVersion() + ")"); for (ScriptParameter parameter : script.getParameters()) { String value = iRequest.getParameters().get(parameter.getName()); if ("file".equals(parameter.getType()) && iFile != null) { debug(parameter.getName() + ": " + iFile.getName() + " (" + iFile.getSize() + " bytes)"); engine.put(parameter.getName(), iFile); continue; } if (value == null) value = parameter.getDefaultValue(); if (value == null) { engine.put(parameter.getName(), null); continue; } debug(parameter.getName() + ": " + value); if (parameter.getType().equalsIgnoreCase("boolean")) { engine.put(parameter.getName(), "true".equalsIgnoreCase(value)); } else if (parameter.getType().equalsIgnoreCase("long")) { engine.put(parameter.getName(), Long.valueOf(value)); } else if (parameter.getType().equalsIgnoreCase("int") || parameter.getType().equalsIgnoreCase("integer")) { engine.put(parameter.getName(), Integer.valueOf(value)); } else if (parameter.getType().equalsIgnoreCase("double")) { engine.put(parameter.getName(), Double.valueOf(value)); } else if (parameter.getType().equalsIgnoreCase("float")) { engine.put(parameter.getName(), Float.valueOf(value)); } else if (parameter.getType().equalsIgnoreCase("short")) { engine.put(parameter.getName(), Short.valueOf(value)); } else if (parameter.getType().equalsIgnoreCase("byte")) { engine.put(parameter.getName(), Byte.valueOf(value)); } else if (parameter.getType().equalsIgnoreCase("department")) { engine.put(parameter.getName(), DepartmentDAO.getInstance().get(Long.valueOf(value), hibSession)); } else if (parameter.getType().equalsIgnoreCase("departments")) { List<Department> departments = new ArrayList<Department>(); for (String id : value.split(",")) if (!id.isEmpty()) departments.add(DepartmentDAO.getInstance().get(Long.valueOf(id), hibSession)); engine.put(parameter.getName(), departments); } else if (parameter.getType().equalsIgnoreCase("subject")) { engine.put(parameter.getName(), SubjectAreaDAO.getInstance().get(Long.valueOf(value), hibSession)); } else if (parameter.getType().equalsIgnoreCase("subjects")) { List<SubjectArea> subjects = new ArrayList<SubjectArea>(); for (String id : value.split(",")) if (!id.isEmpty()) subjects.add(SubjectAreaDAO.getInstance().get(Long.valueOf(id), hibSession)); engine.put(parameter.getName(), subjects); } else if (parameter.getType().equalsIgnoreCase("building")) { engine.put(parameter.getName(), BuildingDAO.getInstance().get(Long.valueOf(value), hibSession)); } else if (parameter.getType().equalsIgnoreCase("buildings")) { List<Building> buildings = new ArrayList<Building>(); for (String id : value.split(",")) if (!id.isEmpty()) buildings.add(BuildingDAO.getInstance().get(Long.valueOf(id), hibSession)); engine.put(parameter.getName(), buildings); } else if (parameter.getType().equalsIgnoreCase("room")) { engine.put(parameter.getName(), RoomDAO.getInstance().get(Long.valueOf(value), hibSession)); } else if (parameter.getType().equalsIgnoreCase("rooms")) { List<Room> rooms = new ArrayList<Room>(); for (String id : value.split(",")) if (!id.isEmpty()) rooms.add(RoomDAO.getInstance().get(Long.valueOf(id), hibSession)); engine.put(parameter.getName(), rooms); } else if (parameter.getType().equalsIgnoreCase("location")) { engine.put(parameter.getName(), LocationDAO.getInstance().get(Long.valueOf(value), hibSession)); } else if (parameter.getType().equalsIgnoreCase("locations")) { List<Location> locations = new ArrayList<Location>(); for (String id : value.split(",")) if (!id.isEmpty()) locations.add(LocationDAO.getInstance().get(Long.valueOf(id), hibSession)); engine.put(parameter.getName(), locations); } else { engine.put(parameter.getName(), value); } } incProgress(); if (engine instanceof Compilable) { setStatus("Compiling script...", 1); CompiledScript compiled = ((Compilable) engine).compile(script.getScript()); incProgress(); setStatus("Running script...", 100); compiled.eval(); } else { setStatus("Running script...", 100); engine.eval(script.getScript()); } hibSession.flush(); tx.commit(); setStatus("All done.", 1); incProgress(); } catch (Exception e) { tx.rollback(); error("Execution failed: " + e.getMessage(), e); } finally { hibSession.close(); } }
From source file:org.apache.hadoop.hive.serde2.RegexSerDe.java
@Override public Object deserialize(Writable blob) throws SerDeException { Text rowText = (Text) blob; Matcher m = inputPattern.matcher(rowText.toString()); if (m.groupCount() != numColumns) { throw new SerDeException("Number of matching groups doesn't match the number of columns"); }/*from ww w . ja v a 2 s .com*/ // If do not match, ignore the line, return a row with all nulls. if (!m.matches()) { unmatchedRowsCount++; if (!alreadyLoggedNoMatch) { // Report the row if its the first time LOG.warn("" + unmatchedRowsCount + " unmatched rows are found: " + rowText); alreadyLoggedNoMatch = true; } return null; } // Otherwise, return the row. for (int c = 0; c < numColumns; c++) { try { String t = m.group(c + 1); TypeInfo typeInfo = columnTypes.get(c); // Convert the column to the correct type when needed and set in row obj PrimitiveTypeInfo pti = (PrimitiveTypeInfo) typeInfo; switch (pti.getPrimitiveCategory()) { case STRING: row.set(c, t); break; case BYTE: Byte b; b = Byte.valueOf(t); row.set(c, b); break; case SHORT: Short s; s = Short.valueOf(t); row.set(c, s); break; case INT: Integer i; i = Integer.valueOf(t); row.set(c, i); break; case LONG: Long l; l = Long.valueOf(t); row.set(c, l); break; case FLOAT: Float f; f = Float.valueOf(t); row.set(c, f); break; case DOUBLE: Double d; d = Double.valueOf(t); row.set(c, d); break; case BOOLEAN: Boolean bool; bool = Boolean.valueOf(t); row.set(c, bool); break; case TIMESTAMP: Timestamp ts; ts = Timestamp.valueOf(t); row.set(c, ts); break; case DATE: Date date; date = Date.valueOf(t); row.set(c, date); break; case DECIMAL: HiveDecimal bd = HiveDecimal.create(t); row.set(c, bd); break; case CHAR: HiveChar hc = new HiveChar(t, ((CharTypeInfo) typeInfo).getLength()); row.set(c, hc); break; case VARCHAR: HiveVarchar hv = new HiveVarchar(t, ((VarcharTypeInfo) typeInfo).getLength()); row.set(c, hv); break; default: throw new SerDeException("Unsupported type " + typeInfo); } } catch (RuntimeException e) { partialMatchedRowsCount++; if (!alreadyLoggedPartialMatch) { // Report the row if its the first row LOG.warn("" + partialMatchedRowsCount + " partially unmatched rows are found, " + " cannot find group " + c + ": " + rowText); alreadyLoggedPartialMatch = true; } row.set(c, null); } } return row; }
From source file:org.vosao.rest.RestManager.java
private Object convertValue(Class<?> cl, String pathValue) { if (cl.isPrimitive()) throw new IllegalArgumentException("Primitive types are not supported"); if (cl.equals(String.class)) return pathValue; // for boolean {y,n}, {Y,N} or {true,false} or {TRUE, FALSE} if (cl.equals(Boolean.class)) { if (pathValue.toLowerCase().equals("y") || pathValue.toLowerCase().equals("true")) return true; if (pathValue.toLowerCase().equals("n") || pathValue.toLowerCase().equals("false")) return false; return false; }/*www . j a v a 2 s . c o m*/ if (cl.equals(Character.class)) return pathValue.charAt(0); if (cl.equals(Byte.class)) return Byte.valueOf(pathValue); if (cl.equals(Short.class)) return Short.valueOf(pathValue); if (cl.equals(Integer.class)) return Integer.valueOf(pathValue); if (cl.equals(Long.class)) return Long.valueOf(pathValue); if (cl.equals(Float.class)) return Float.valueOf(pathValue); if (cl.equals(Double.class)) return Double.valueOf(pathValue); throw new IllegalArgumentException("Unsupported paramter type " + cl.getName()); }
From source file:org.sourcepit.tpmp.change.ChecksumTargetPlatformConfigurationChangeDiscoverer.java
private static String byteArray2Hex(byte[] hash) { Formatter formatter = null;//from ww w .j a v a 2 s.c om try { formatter = new Formatter(); for (byte b : hash) { formatter.format("%02x", Byte.valueOf(b)); } return formatter.toString(); } finally { IOUtils.closeQuietly(formatter); } }