List of usage examples for java.lang Byte Byte
@Deprecated(since = "9") public Byte(String s) throws NumberFormatException
From source file:com.willwinder.universalgcodesender.GrblControllerTest.java
/** * Test of resumeStreaming method, of class GrblController. *///from www .j av a 2 s .c om @Test public void testResumeStreaming() throws Exception { System.out.println("resumeStreaming"); GrblController instance = new GrblController(mgc); instance.openCommPort(getSettings().getConnectionDriver(), "blah", 1234); assertEquals(new Byte(GrblUtils.GRBL_RESET_COMMAND), mgc.sentBytes.get(mgc.sentBytes.size() - 1)); instance.resumeStreaming(); assertEquals(1, mgc.numResumeSendCalls); instance.rawResponseHandler("Grbl 0.7"); instance.resumeStreaming(); assertEquals(2, mgc.numResumeSendCalls); assertEquals(new Byte(GrblUtils.GRBL_RESET_COMMAND), mgc.sentBytes.get(mgc.sentBytes.size() - 1)); instance.rawResponseHandler("Grbl 0.8c"); instance.resumeStreaming(); assertEquals(3, mgc.numResumeSendCalls); assertEquals(new Byte(GrblUtils.GRBL_RESUME_COMMAND), mgc.sentBytes.get(mgc.sentBytes.size() - 1)); }
From source file:com.alibaba.wasp.jdbc.TestPreparedStatement.java
public void testObject() throws SQLException { Statement stat = conn.createStatement(); ResultSet rs;/*from w w w .j a va 2 s . c o m*/ stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"); stat.execute("INSERT INTO TEST VALUES(1, 'Hello')"); PreparedStatement prep = conn .prepareStatement("SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? FROM TEST"); prep.setObject(1, Boolean.TRUE); prep.setObject(2, "Abc"); prep.setObject(3, new BigDecimal("10.2")); prep.setObject(4, new Byte((byte) 0xff)); prep.setObject(5, new Short(Short.MAX_VALUE)); prep.setObject(6, new Integer(Integer.MIN_VALUE)); prep.setObject(7, new Long(Long.MAX_VALUE)); prep.setObject(8, new Float(Float.MAX_VALUE)); prep.setObject(9, new Double(Double.MAX_VALUE)); prep.setObject(10, Date.valueOf("2001-02-03")); prep.setObject(11, Time.valueOf("04:05:06")); prep.setObject(12, Timestamp.valueOf("2001-02-03 04:05:06.123456789")); prep.setObject(13, new java.util.Date(Date.valueOf("2001-02-03").getTime())); prep.setObject(14, new byte[] { 10, 20, 30 }); prep.setObject(15, new Character('a'), Types.OTHER); prep.setObject(16, "2001-01-02", Types.DATE); // converting to null seems strange... prep.setObject(17, "2001-01-02", Types.NULL); prep.setObject(18, "3.725", Types.DOUBLE); prep.setObject(19, "23:22:21", Types.TIME); prep.setObject(20, new java.math.BigInteger("12345"), Types.OTHER); rs = prep.executeQuery(); rs.next(); assertTrue(rs.getObject(1).equals(Boolean.TRUE)); assertTrue(rs.getObject(2).equals("Abc")); assertTrue(rs.getObject(3).equals(new BigDecimal("10.2"))); assertTrue(rs.getObject(4).equals((byte) 0xff)); assertTrue(rs.getObject(5).equals(new Short(Short.MAX_VALUE))); assertTrue(rs.getObject(6).equals(new Integer(Integer.MIN_VALUE))); assertTrue(rs.getObject(7).equals(new Long(Long.MAX_VALUE))); assertTrue(rs.getObject(8).equals(new Float(Float.MAX_VALUE))); assertTrue(rs.getObject(9).equals(new Double(Double.MAX_VALUE))); assertTrue(rs.getObject(10).equals(Date.valueOf("2001-02-03"))); assertEquals("04:05:06", rs.getObject(11).toString()); assertTrue(rs.getObject(11).equals(Time.valueOf("04:05:06"))); assertTrue(rs.getObject(12).equals(Timestamp.valueOf("2001-02-03 04:05:06.123456789"))); assertTrue(rs.getObject(13).equals(Timestamp.valueOf("2001-02-03 00:00:00"))); assertEquals(new byte[] { 10, 20, 30 }, (byte[]) rs.getObject(14)); assertTrue(rs.getObject(15).equals('a')); assertTrue(rs.getObject(16).equals(Date.valueOf("2001-01-02"))); assertTrue(rs.getObject(17) == null && rs.wasNull()); assertTrue(rs.getObject(18).equals(new Double(3.725))); assertTrue(rs.getObject(19).equals(Time.valueOf("23:22:21"))); assertTrue(rs.getObject(20).equals(new java.math.BigInteger("12345"))); // } else if(x instanceof java.io.Reader) { // return session.createLob(Value.CLOB, // TypeConverter.getInputStream((java.io.Reader)x), 0); // } else if(x instanceof java.io.InputStream) { // return session.createLob(Value.BLOB, (java.io.InputStream)x, 0); // } else { // return ValueBytes.get(TypeConverter.serialize(x)); stat.execute("DROP TABLE TEST"); }
From source file:eionet.gdem.utils.Utils.java
/** * * @param srcBytes/*w ww . ja va 2 s . co 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:wicket.util.lang.Objects.java
/** * Returns a new Number object of an appropriate type to hold the given * integer value. The type of the returned object is consistent with the * given type argument, which is a constant from the NumericTypes interface. * /* w ww.j a v a 2s.c om*/ * @param type * the nominal numeric type of the result, a constant from the * NumericTypes interface * @param value * the integer value to convert to a Number object * @return a Number object with the given value, of type implied by the type * argument */ public static Number newInteger(int type, long value) { switch (type) { case BOOL: case CHAR: case INT: return new Integer((int) value); case FLOAT: if (value == value) { return new Float(value); } // else fall through: case DOUBLE: if (value == value) { return new Double(value); } // else fall through: case LONG: return new Long(value); case BYTE: return new Byte((byte) value); case SHORT: return new Short((short) value); default: return BigInteger.valueOf(value); } }
From source file:net.sourceforge.msscodefactory.cfinternet.v2_0.CFInternetXMsgClient.CFInternetXMsgClientSchema.java
public static Byte getNullableByte(ResultSet reader, int colidx) { try {/*from w ww. j a v a 2s. co m*/ byte val = reader.getByte(colidx); if (reader.wasNull()) { return (null); } else { return (new Byte(val)); } } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(CFInternetXMsgClientSchema.class, "getNullableByte", e); } }
From source file:com.xwtec.xwserver.util.json.JSONArray.java
/** * Construct a JSONArray from an byte[].<br> * * @param array An byte[] array.// www. ja va 2 s .c om */ private static JSONArray _fromArray(byte[] array, JsonConfig jsonConfig) { if (!addInstance(array)) { try { return jsonConfig.getCycleDetectionStrategy().handleRepeatedReferenceAsArray(array); } catch (JSONException jsone) { removeInstance(array); fireErrorEvent(jsone, jsonConfig); throw jsone; } catch (RuntimeException e) { removeInstance(array); JSONException jsone = new JSONException(e); fireErrorEvent(jsone, jsonConfig); throw jsone; } } fireArrayStartEvent(jsonConfig); JSONArray jsonArray = new JSONArray(); for (int i = 0; i < array.length; i++) { Number n = JSONUtils.transformNumber(new Byte(array[i])); jsonArray.addValue(n, jsonConfig); fireElementAddedEvent(i, n, jsonConfig); } removeInstance(array); fireArrayEndEvent(jsonConfig); return jsonArray; }
From source file:eionet.gdem.utils.Utils.java
/** * * @param f// w ww . jav a2 s . c o 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:com.sun.faces.config.ManagedBeanFactory.java
private Object getConvertedValueConsideringPrimitives(Object value, Class valueType) throws FacesException { if (null != value && null != valueType) { if (valueType == Boolean.TYPE || valueType == java.lang.Boolean.class) { value = Boolean.valueOf(value.toString().toLowerCase()); } else if (valueType == Byte.TYPE || valueType == java.lang.Byte.class) { value = new Byte(value.toString()); } else if (valueType == Double.TYPE || valueType == java.lang.Double.class) { value = new Double(value.toString()); } else if (valueType == Float.TYPE || valueType == java.lang.Float.class) { value = new Float(value.toString()); } else if (valueType == Integer.TYPE || valueType == java.lang.Integer.class) { value = new Integer(value.toString()); } else if (valueType == Character.TYPE || valueType == java.lang.Character.class) { value = new Character(value.toString().charAt(0)); } else if (valueType == Short.TYPE || valueType == java.lang.Short.class) { value = new Short(value.toString()); } else if (valueType == Long.TYPE || valueType == java.lang.Long.class) { value = new Long(value.toString()); } else if (valueType == String.class) { } else if (!valueType.isAssignableFrom(value.getClass())) { throw new FacesException( Util.getExceptionMessageString(Util.MANAGED_BEAN_TYPE_CONVERSION_ERROR_ID, new Object[] { value.toString(), value.getClass(), valueType, managedBean.getManagedBeanName() })); }/*from w ww.j a v a 2s . c o m*/ } return value; }
From source file:de.javakaffee.kryoserializers.KryoTest.java
@DataProvider(name = "typesAsSessionAttributesProvider") protected Object[][] createTypesAsSessionAttributesData() { return new Object[][] { { Boolean.class, Boolean.TRUE }, { String.class, "42" }, { StringBuilder.class, new StringBuilder("42") }, { StringBuffer.class, new StringBuffer("42") }, { Class.class, String.class }, { Long.class, new Long(42) }, { Integer.class, new Integer(42) }, { Character.class, new Character('c') }, { Byte.class, new Byte("b".getBytes()[0]) }, { Double.class, new Double(42d) }, { Float.class, new Float(42f) }, { Short.class, new Short((short) 42) }, { BigDecimal.class, new BigDecimal(42) }, { AtomicInteger.class, new AtomicInteger(42) }, { AtomicLong.class, new AtomicLong(42) }, { MutableInt.class, new MutableInt(42) }, { Integer[].class, new Integer[] { 42 } }, { Date.class, new Date(System.currentTimeMillis() - 10000) }, { Calendar.class, Calendar.getInstance() }, { Currency.class, Currency.getInstance("EUR") }, { ArrayList.class, new ArrayList<String>(Arrays.asList("foo")) }, { int[].class, new int[] { 1, 2 } }, { long[].class, new long[] { 1, 2 } }, { short[].class, new short[] { 1, 2 } }, { float[].class, new float[] { 1, 2 } }, { double[].class, new double[] { 1, 2 } }, { int[].class, new int[] { 1, 2 } }, { byte[].class, "42".getBytes() }, { char[].class, "42".toCharArray() }, { String[].class, new String[] { "23", "42" } }, { Person[].class, new Person[] { createPerson("foo bar", Gender.MALE, 42) } } }; }
From source file:org.plasma.sdo.helper.DataConverter.java
public Object fromLong(Type targetType, long value) { DataType targetDataType = DataType.valueOf(targetType.getName()); switch (targetDataType) { case Long: return Long.valueOf(value); case Byte: return new Byte(Long.valueOf(value).byteValue()); case Double: return new Double(Long.valueOf(value).doubleValue()); case Float: return new Float(Long.valueOf(value).floatValue()); case Int:/*from www. j a v a 2 s. c o m*/ return new Integer(Long.valueOf(value).intValue()); case Short: return new Short(Long.valueOf(value).shortValue()); case Decimal: return new BigDecimal(Long.valueOf(value).longValue()); case Integer: return BigInteger.valueOf(Long.valueOf(value).longValue()); case Date: return new Date(value); case String: return Long.toString(value); default: throw new InvalidDataConversionException(targetDataType, DataType.Long, value); } }