List of usage examples for java.lang Byte intValue
public int intValue()
From source file:org.apache.hawq.pxf.service.io.GPDBWritable.java
/** * Helper printing function/*from w ww .j a v a 2s . c o m*/ */ private static String byteArrayInString(byte[] data) { StringBuilder result = new StringBuilder(); for (Byte b : data) { result.append(b.intValue()).append(" "); } return result.toString(); }
From source file:Uuid32Generator.java
public String generate() { StringBuilder strRetVal = new StringBuilder(); String strTemp;/*w w w.ja v a 2 s .c om*/ try { // IPAddress segment InetAddress addr = InetAddress.getLocalHost(); byte[] ipaddr = addr.getAddress(); for (byte anIpaddr : ipaddr) { Byte b = new Byte(anIpaddr); strTemp = Integer.toHexString(b.intValue() & 0x000000ff); strRetVal.append(ZEROS.substring(0, 2 - strTemp.length())); strRetVal.append(strTemp); } strRetVal.append(':'); // CurrentTimeMillis() segment strTemp = Long.toHexString(System.currentTimeMillis()); strRetVal.append(ZEROS.substring(0, 12 - strTemp.length())); strRetVal.append(strTemp).append(':'); // random segment SecureRandom prng = SecureRandom.getInstance("SHA1PRNG"); strTemp = Integer.toHexString(prng.nextInt()); while (strTemp.length() < 8) { strTemp = '0' + strTemp; } strRetVal.append(strTemp.substring(4)).append(':'); // IdentityHash() segment strTemp = Long.toHexString(System.identityHashCode(this)); strRetVal.append(ZEROS.substring(0, 8 - strTemp.length())); strRetVal.append(strTemp); } catch (UnknownHostException uhex) { throw new RuntimeException("Unknown host.", uhex); } catch (NoSuchAlgorithmException nsaex) { throw new RuntimeException("Algorithm 'SHA1PRNG' is unavailiable.", nsaex); } return strRetVal.toString().toUpperCase(); }
From source file:org.apache.hadoop.hive.ql.udf.UDFToInteger.java
public Integer evaluate(Byte i) { if (i == null) { return null; } else {/*from ww w .jav a2 s . c om*/ return Integer.valueOf(i.intValue()); } }
From source file:eionet.gdem.utils.Utils.java
/** * * @param srcBytes/*w ww. j av a 2 s .c o m*/ * @param algorithm * @return * @throws Exception */ public static String digest(byte[] srcBytes, String algorithm) throws Exception { byte[] dstBytes = new byte[16]; MessageDigest md; md = MessageDigest.getInstance(algorithm); md.update(srcBytes); dstBytes = md.digest(); md.reset(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < dstBytes.length; i++) { Byte byteWrapper = new Byte(dstBytes[i]); int k = byteWrapper.intValue(); String s = Integer.toHexString(k); if (s.length() == 1) { s = "0" + s; } buf.append(s.substring(s.length() - 2)); } return buf.toString(); }
From source file:eionet.gdem.utils.Utils.java
/** * * @param f/*w ww . java 2 s. co m*/ * @param algorithm * @return * @throws Exception */ public static String digest(File f, String algorithm) throws Exception { byte[] dstBytes = new byte[16]; MessageDigest md; md = MessageDigest.getInstance(algorithm); BufferedInputStream in = null; int theByte = 0; try { in = new BufferedInputStream(new FileInputStream(f)); while ((theByte = in.read()) != -1) { md.update((byte) theByte); } } finally { try { in.close(); } catch (Exception e) { } } dstBytes = md.digest(); md.reset(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < dstBytes.length; i++) { Byte byteWrapper = new Byte(dstBytes[i]); int k = byteWrapper.intValue(); String s = Integer.toHexString(k); if (s.length() == 1) { s = "0" + s; } buf.append(s.substring(s.length() - 2)); } return buf.toString(); }
From source file:de.syss.MifareClassicTool.Common.java
/** * Convert an array of bytes into a string of hex values. * @param bytes Bytes to convert.//from ww w .j a v a 2 s . co m * @return The bytes in hex string format. */ public static String byte2HexString(byte[] bytes) { String ret = ""; if (bytes != null) { for (Byte b : bytes) { ret += String.format("%02X", b.intValue() & 0xFF); } } return ret; }
From source file:eionet.util.Util.java
/** * A method for creating a unique Hexa-Decimal digest of a String message. * * @param src// www . java 2 s.co m * String to be digested. * @param algosrithm * Digesting algorithm (please see Java documentation for allowable values). * @return A unique String-typed Hexa-Decimal digest of the input message. */ public static String digestHexDec(String src, String algorithm) throws GeneralSecurityException { byte[] srcBytes = src.getBytes(); byte[] dstBytes = new byte[16]; MessageDigest md = MessageDigest.getInstance(algorithm); md.update(srcBytes); dstBytes = md.digest(); md.reset(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < dstBytes.length; i++) { Byte byteWrapper = new Byte(dstBytes[i]); int k = byteWrapper.intValue(); String s = Integer.toHexString(byteWrapper.intValue()); if (s.length() == 1) { s = "0" + s; } buf.append(s.substring(s.length() - 2)); } return buf.toString(); }
From source file:eionet.util.Util.java
/** * A method for creating a unique digest of a String message. * * @param src//w ww . j a v a 2 s . co m * String to be digested. * @param algorithm * Digesting algorithm (please see Java documentation for allowable values). * @return A unique String-typed digest of the input message. */ public static String digest(String src, String algorithm) throws GeneralSecurityException { byte[] srcBytes = src.getBytes(); byte[] dstBytes = new byte[16]; MessageDigest md = MessageDigest.getInstance(algorithm); md.update(srcBytes); dstBytes = md.digest(); md.reset(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < dstBytes.length; i++) { Byte byteWrapper = new Byte(dstBytes[i]); buf.append(String.valueOf(byteWrapper.intValue())); } return buf.toString(); }
From source file:org.hellojavaer.poi.excel.utils.ExcelUtils.java
@SuppressWarnings("unused") private static void writeCell(Cell cell, Object val, boolean userTemplate, ExcelWriteFieldMappingAttribute attribute, Object bean) { if (attribute != null && attribute.getLinkField() != null) { String addressFieldName = attribute.getLinkField(); String address = null;/*from ww w . java 2 s .c om*/ if (bean != null) { address = (String) getFieldValue(bean, addressFieldName, true); } Workbook wb = cell.getRow().getSheet().getWorkbook(); Hyperlink link = wb.getCreationHelper().createHyperlink(attribute.getLinkType()); link.setAddress(address); cell.setHyperlink(link); // Its style can't inherit from cell. CellStyle style = wb.createCellStyle(); Font hlinkFont = wb.createFont(); hlinkFont.setUnderline(Font.U_SINGLE); hlinkFont.setColor(IndexedColors.BLUE.getIndex()); style.setFont(hlinkFont); if (cell.getCellStyle() != null) { style.setFillBackgroundColor(cell.getCellStyle().getFillBackgroundColor()); } cell.setCellStyle(style); } if (val == null) { cell.setCellValue((String) null); return; } Class<?> clazz = val.getClass(); if (val instanceof Byte) {// Double Byte temp = (Byte) val; cell.setCellValue((double) temp.byteValue()); } else if (val instanceof Short) { Short temp = (Short) val; cell.setCellValue((double) temp.shortValue()); } else if (val instanceof Integer) { Integer temp = (Integer) val; cell.setCellValue((double) temp.intValue()); } else if (val instanceof Long) { Long temp = (Long) val; cell.setCellValue((double) temp.longValue()); } else if (val instanceof Float) { Float temp = (Float) val; cell.setCellValue((double) temp.floatValue()); } else if (val instanceof Double) { Double temp = (Double) val; cell.setCellValue((double) temp.doubleValue()); } else if (val instanceof Date) {// Date Date dateVal = (Date) val; long time = dateVal.getTime(); // read is based on 1899/12/31 but DateUtil.getExcelDate is base on // 1900/01/01 if (time >= TIME_1899_12_31_00_00_00_000 && time < TIME_1900_01_01_00_00_00_000) { Date incOneDay = new Date(time + 24 * 60 * 60 * 1000); double d = DateUtil.getExcelDate(incOneDay); cell.setCellValue(d - 1); } else { cell.setCellValue(dateVal); } if (!userTemplate) { Workbook wb = cell.getRow().getSheet().getWorkbook(); CellStyle cellStyle = cell.getCellStyle(); if (cellStyle == null) { cellStyle = wb.createCellStyle(); } DataFormat dataFormat = wb.getCreationHelper().createDataFormat(); // @see #BuiltinFormats // 0xe, "m/d/yy" // 0x14 "h:mm" // 0x16 "m/d/yy h:mm" // {@linke https://en.wikipedia.org/wiki/Year_10,000_problem} /** [1899/12/31 00:00:00:000~1900/01/01 00:00:000) */ if (time >= TIME_1899_12_31_00_00_00_000 && time < TIME_1900_01_02_00_00_00_000) { cellStyle.setDataFormat(dataFormat.getFormat("h:mm")); // cellStyle.setDataFormat(dataFormat.getFormat("m/d/yy h:mm")); } else { // if ( time % (24 * 60 * 60 * 1000) == 0) {//for time // zone,we can't use this way. Calendar calendar = Calendar.getInstance(); calendar.setTime(dateVal); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); int millisecond = calendar.get(Calendar.MILLISECOND); if (millisecond == 0 && second == 0 && minute == 0 && hour == 0) { cellStyle.setDataFormat(dataFormat.getFormat("m/d/yy")); } else { cellStyle.setDataFormat(dataFormat.getFormat("m/d/yy h:mm")); } } cell.setCellStyle(cellStyle); } } else if (val instanceof Boolean) {// Boolean cell.setCellValue(((Boolean) val).booleanValue()); } else {// String cell.setCellValue((String) val.toString()); } }
From source file:uk.ac.edukapp.service.WidgetProfileService.java
public Message toggleFeatured(String widgetId) { Message msg = new Message(); EntityManager em = this.getEntityManagerFactory().createEntityManager(); em.getTransaction().begin();/*from w w w . j a v a2s . c o m*/ Widgetprofile widgetProfile = em.find(Widgetprofile.class, widgetId); Byte featured = widgetProfile.getFeatured(); if (featured.intValue() == 0) { msg.setMessage("true"); widgetProfile.setFeatured((byte) 1); } else { msg.setMessage("false"); widgetProfile.setFeatured((byte) 0); } em.persist(widgetProfile); em.getTransaction().commit(); em.close(); return msg; }