List of usage examples for java.lang Byte byteValue
@HotSpotIntrinsicCandidate public byte byteValue()
From source file:com.meetup.memcached.NativeHandler.java
protected static byte[] encode(Byte value) { byte[] b = new byte[1]; b[0] = value.byteValue(); return b;/*from w ww . j av a 2 s.c om*/ }
From source file:Main.java
/** * <p>Converts an array of object Bytes to primitives handling {@code null}.</p> * * <p>This method returns {@code null} for a {@code null} input array.</p> * * @param array a {@code Byte} array, may be {@code null} * @param valueForNull the value to insert if {@code null} found * @return a {@code byte} array, {@code null} if null array input *///from w ww. j a v a2 s .co m public static byte[] toPrimitive(Byte[] array, byte valueForNull) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_BYTE_ARRAY; } final byte[] result = new byte[array.length]; for (int i = 0; i < array.length; i++) { Byte b = array[i]; result[i] = (b == null ? valueForNull : b.byteValue()); } return result; }
From source file:Main.java
/** * <p>Converts an array of object Bytes to primitives handling {@code null}.</p> * * <p>This method returns {@code null} for a {@code null} input array.</p> * * @param array a {@code Byte} array, may be {@code null} * @param valueForNull the value to insert if {@code null} found * @return a {@code byte} array, {@code null} if null array input *///from w w w . ja va2 s . co m public static byte[] toPrimitive(final Byte[] array, final byte valueForNull) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_BYTE_ARRAY; } final byte[] result = new byte[array.length]; for (int i = 0; i < array.length; i++) { final Byte b = array[i]; result[i] = (b == null ? valueForNull : b.byteValue()); } return result; }
From source file:fr.landel.utils.commons.ObjectUtils.java
/** * Get the primitive value of an {@link Byte}. If {@code value} is not * {@code null}, returns the primitive value of {@code value} otherwise returns * {@code defaultValue}/*from ww w.j a v a 2 s . c o m*/ * * <pre> * Byte one = new Byte((byte) 1); * byte value1 = ObjectUtils.toPrimitive(one, (byte) 0); // => value1 = 1 * byte value2 = ObjectUtils.toPrimitive((Byte) null, (byte) 0); // => value2 = 0 * </pre> * * @param value * the {@link Byte} value * @param defaultValue * the default value * @return a primitive byte */ public static byte toPrimitive(final Byte value, final byte defaultValue) { if (value == null) { return defaultValue; } else { return value.byteValue(); } }
From source file:org.latticesoft.util.common.NumeralUtil.java
public static byte[] convertHexStringToByteArray(String s) { byte[] retVal = null; if (s == null || s.length() == 0) { return null; }/* w w w. j av a 2 s .c o m*/ if (s.length() % 2 != 0) { return null; } s = s.toUpperCase(); int index = 0; //int len = s.length(); List l = new ArrayList(); StringBuffer sb = new StringBuffer(); while (index < s.length()) { sb.setLength(0); sb.append(s.charAt(index++)); sb.append(s.charAt(index++)); byte b = convertHexStringToByte(sb.toString()); l.add(new Byte(b)); } retVal = new byte[l.size()]; for (int i = 0; i < l.size(); i++) { Byte bb = (Byte) l.get(i); retVal[i] = bb.byteValue(); } return retVal; }
From source file:com.ntsync.shared.RequestGenerator.java
private static byte[] createHeader(SyncAnchor syncAnchor, String pkgVersion, String clientId, String pwdSaltHexStr, Map<Long, String> newIdMap, boolean syncOnlyGroup, Restrictions restr, boolean explizitPhotoSave) throws HeaderCreateException { ByteArrayOutputStream out = new ByteArrayOutputStream(); try {//w w w.j ava 2 s . c o m JsonGenerator g = getJsonFactory().createGenerator(out); g.writeStartObject(); g.writeObjectFieldStart(CLIENT_FIELD_NAME); g.writeObjectFieldStart(PARAM_SYNC_ANCHOR); for (Byte contType : syncAnchor.containers()) { long anchor = syncAnchor.getAnchor(contType); if (anchor > 0) { String type = String.valueOf((char) contType.byteValue()); g.writeNumberField(type, anchor); } } g.writeEndObject(); if (syncOnlyGroup) { LOG.info("Sync only ContactGroups"); g.writeBooleanField(PARAM_SYNCONLYGROUP, true); } g.writeStringField(FIELD_SOFTWARE, "Android|" + pkgVersion); // Set ClientId if (clientId != null) { g.writeStringField(PARAM_CLIENTID, clientId); } if (restr != null) { g.writeBooleanField(PARAM_IS_PHOTO_SYNC_ENABLED, restr.isPhotoSyncSupported()); } if (explizitPhotoSave) { g.writeBooleanField(PARAM_FORCE_PHOTO_SAVE, true); } // Set PwdSalt if (pwdSaltHexStr != null) { g.writeStringField(FIELD_PWDSALT, pwdSaltHexStr); } if (newIdMap != null && !newIdMap.isEmpty()) { g.writeObjectFieldStart(TAG_CONTACTIDS); for (Map.Entry<Long, String> idRow : newIdMap.entrySet()) { String serverId = idRow.getValue(); if (serverId != null && serverId.length() > 0) { g.writeStringField(String.valueOf(idRow.getKey()), serverId); } } g.writeEndObject(); } g.writeEndObject(); g.writeEndObject(); g.close(); } catch (IOException ex) { throw new HeaderCreateException(ex); } return out.toByteArray(); }
From source file:org.apache.hadoop.hive.ql.udf.UDFOPBitNot.java
public Byte evaluate(Byte a) { if (a == null) return null; Byte r = Byte.valueOf((byte) ~a.byteValue()); return r;/*from w w w . j av a 2 s .co m*/ }
From source file:org.apache.hadoop.hive.ql.udf.UDFOPNegative.java
public Byte evaluate(Byte a) { if (a == null) return null; Byte r = Byte.valueOf((byte) -a.byteValue()); return r;/*from w w w . jav a2 s . co m*/ }
From source file:org.red5.io.mock.Input.java
/** {@inheritDoc} */ public byte readDataType() { Byte b = (Byte) getNext(); return b.byteValue(); }
From source file:org.apache.cocoon.util.JDBCTypeConversions.java
/** * Set the Statement column so that the results are mapped correctly. * * @param statement the prepared statement * @param position the position of the column * @param value the value of the column/*from www .j av a 2 s. c o m*/ */ public static void setColumn(PreparedStatement statement, int position, Object value, Integer typeObject) throws Exception { if (value instanceof String) { value = ((String) value).trim(); } if (typeObject == null) { throw new SQLException("Can't set column because the type is unrecognized"); } if (value == null) { /** If the value is null, set the column value null and return **/ statement.setNull(position, typeObject.intValue()); return; } if ("".equals(value)) { switch (typeObject.intValue()) { case Types.CHAR: case Types.CLOB: case Types.VARCHAR: /** If the value is an empty string and the column is a string type, we can continue **/ break; default: /** If the value is an empty string and the column is something else, we treat it as a null value **/ statement.setNull(position, typeObject.intValue()); return; } } File file = null; int length = -1; InputStream asciiStream = null; //System.out.println("========================================================================"); //System.out.println("JDBCTypeConversions: setting type "+typeObject.intValue()); switch (typeObject.intValue()) { case Types.CLOB: //System.out.println("CLOB"); Clob clob = null; if (value instanceof Clob) { clob = (Clob) value; } else if (value instanceof File) { File asciiFile = (File) value; asciiStream = new BufferedInputStream(new FileInputStream(asciiFile)); length = (int) asciiFile.length(); clob = new ClobHelper(asciiStream, length); } else if (value instanceof Part) { Part anyFile = (Part) value; asciiStream = new BufferedInputStream(anyFile.getInputStream()); length = anyFile.getSize(); clob = new ClobHelper(asciiStream, length); } else if (value instanceof JDBCxlobHelper) { asciiStream = ((JDBCxlobHelper) value).inputStream; length = ((JDBCxlobHelper) value).length; clob = new ClobHelper(asciiStream, length); } else if (value instanceof Source) { asciiStream = ((Source) value).getInputStream(); length = (int) ((Source) value).getContentLength(); clob = new ClobHelper(asciiStream, length); } else { String asciiText = value.toString(); asciiStream = new ByteArrayInputStream(asciiText.getBytes()); length = asciiText.length(); clob = new ClobHelper(asciiStream, length); } statement.setClob(position, clob); break; case Types.CHAR: // simple large object, e.g. Informix's TEXT //System.out.println("CHAR"); if (value instanceof File) { File asciiFile = (File) value; asciiStream = new BufferedInputStream(new FileInputStream(asciiFile)); length = (int) asciiFile.length(); } else if (value instanceof JDBCxlobHelper) { asciiStream = ((JDBCxlobHelper) value).inputStream; length = ((JDBCxlobHelper) value).length; } else if (value instanceof Source) { asciiStream = ((Source) value).getInputStream(); length = (int) ((Source) value).getContentLength(); } else if (value instanceof Part) { Part anyFile = (Part) value; asciiStream = new BufferedInputStream(anyFile.getInputStream()); length = anyFile.getSize(); clob = new ClobHelper(asciiStream, length); } else { String asciiText = value.toString(); asciiStream = new BufferedInputStream(new ByteArrayInputStream(asciiText.getBytes())); length = asciiText.length(); } statement.setAsciiStream(position, asciiStream, length); break; case Types.BIGINT: //System.out.println("BIGINT"); BigDecimal bd = null; if (value instanceof BigDecimal) { bd = (BigDecimal) value; } else if (value instanceof Number) { bd = BigDecimal.valueOf(((Number) value).longValue()); } else { bd = new BigDecimal(value.toString()); } statement.setBigDecimal(position, bd); break; case Types.TINYINT: //System.out.println("TINYINT"); Byte b = null; if (value instanceof Byte) { b = (Byte) value; } else if (value instanceof Number) { b = new Byte(((Number) value).byteValue()); } else { b = new Byte(value.toString()); } statement.setByte(position, b.byteValue()); break; case Types.DATE: //System.out.println("DATE"); Date d = null; if (value instanceof Date) { d = (Date) value; } else if (value instanceof java.util.Date) { d = new Date(((java.util.Date) value).getTime()); } else if (value instanceof Calendar) { d = new Date(((Calendar) value).getTime().getTime()); } else { d = Date.valueOf(value.toString()); } statement.setDate(position, d); break; case Types.DOUBLE: //System.out.println("DOUBLE"); double db; if (value instanceof Number) { db = (((Number) value).doubleValue()); } else { db = Double.parseDouble(value.toString()); } statement.setDouble(position, db); break; case Types.FLOAT: //System.out.println("FLOAT"); float f; if (value instanceof Number) { f = (((Number) value).floatValue()); } else { f = Float.parseFloat(value.toString()); } statement.setFloat(position, f); break; case Types.NUMERIC: //System.out.println("NUMERIC"); long l; if (value instanceof Number) { l = (((Number) value).longValue()); } else { l = Long.parseLong(value.toString()); } statement.setLong(position, l); break; case Types.SMALLINT: //System.out.println("SMALLINT"); Short s = null; if (value instanceof Short) { s = (Short) value; } else if (value instanceof Number) { s = new Short(((Number) value).shortValue()); } else { s = new Short(value.toString()); } statement.setShort(position, s.shortValue()); break; case Types.TIME: //System.out.println("TIME"); Time t = null; if (value instanceof Time) { t = (Time) value; } else if (value instanceof java.util.Date) { t = new Time(((java.util.Date) value).getTime()); } else { t = Time.valueOf(value.toString()); } statement.setTime(position, t); break; case Types.TIMESTAMP: //System.out.println("TIMESTAMP"); Timestamp ts = null; if (value instanceof Time) { ts = (Timestamp) value; } else if (value instanceof java.util.Date) { ts = new Timestamp(((java.util.Date) value).getTime()); } else { ts = Timestamp.valueOf(value.toString()); } statement.setTimestamp(position, ts); break; case Types.ARRAY: //System.out.println("ARRAY"); statement.setArray(position, (Array) value); // no way to convert string to array break; case Types.STRUCT: //System.out.println("STRUCT"); case Types.OTHER: //System.out.println("OTHER"); statement.setObject(position, value); break; case Types.LONGVARBINARY: //System.out.println("LONGVARBINARY"); statement.setTimestamp(position, new Timestamp((new java.util.Date()).getTime())); break; case Types.VARCHAR: //System.out.println("VARCHAR"); statement.setString(position, value.toString()); break; case Types.BLOB: //System.out.println("BLOB"); if (value instanceof JDBCxlobHelper) { statement.setBinaryStream(position, ((JDBCxlobHelper) value).inputStream, ((JDBCxlobHelper) value).length); } else if (value instanceof Source) { statement.setBinaryStream(position, ((Source) value).getInputStream(), (int) ((Source) value).getContentLength()); } else { Blob blob = null; if (value instanceof Blob) { blob = (Blob) value; } else if (value instanceof File) { file = (File) value; blob = new BlobHelper(new FileInputStream(file), (int) file.length()); } else if (value instanceof String) { file = new File((String) value); blob = new BlobHelper(new FileInputStream(file), (int) file.length()); } else if (value instanceof Part) { Part anyFile = (Part) value; blob = new BlobHelper(new BufferedInputStream(anyFile.getInputStream()), anyFile.getSize()); } else { throw new SQLException("Invalid type for blob: " + value.getClass().getName()); } //InputStream input = new BufferedInputStream(new FileInputStream(file)); statement.setBlob(position, blob); } break; case Types.VARBINARY: //System.out.println("VARBINARY"); if (value instanceof JDBCxlobHelper) { statement.setBinaryStream(position, ((JDBCxlobHelper) value).inputStream, ((JDBCxlobHelper) value).length); } else if (value instanceof Source) { statement.setBinaryStream(position, ((Source) value).getInputStream(), (int) ((Source) value).getContentLength()); } else if (value instanceof Part) { statement.setBinaryStream(position, ((Part) value).getInputStream(), ((Part) value).getSize()); } else { if (value instanceof File) { file = (File) value; } else if (value instanceof String) { file = new File((String) value); } else { throw new SQLException("Invalid type for blob: " + value.getClass().getName()); } //InputStream input = new BufferedInputStream(new FileInputStream(file)); FileInputStream input = new FileInputStream(file); statement.setBinaryStream(position, input, (int) file.length()); } break; case Types.INTEGER: //System.out.println("INTEGER"); Integer i = null; if (value instanceof Integer) { i = (Integer) value; } else if (value instanceof Number) { i = new Integer(((Number) value).intValue()); } else { i = new Integer(value.toString()); } statement.setInt(position, i.intValue()); break; case Types.BIT: //System.out.println("BIT"); Boolean bo = null; if (value instanceof Boolean) { bo = (Boolean) value; } else if (value instanceof Number) { bo = BooleanUtils.toBooleanObject(((Number) value).intValue() == 1); } else { bo = BooleanUtils.toBooleanObject(value.toString()); } statement.setBoolean(position, bo.booleanValue()); break; default: //System.out.println("default"); throw new SQLException("Impossible exception - invalid type "); } //System.out.println("========================================================================"); }