List of usage examples for java.lang Byte Byte
@Deprecated(since = "9") public Byte(String s) throws NumberFormatException
From source file:net.sf.jvifm.ResourceManager.java
@SuppressWarnings("unchecked") public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) { String fontName = name + "|" + size + "|" + style + "|" + strikeout + "|" + underline; if (resources.containsKey(fontName)) return (Font) resources.get(fontName); FontData fd = new FontData(name, size, style); if (strikeout || underline) { try {//w ww . j a v a 2s . co m Class lfCls = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); Object lf = FontData.class.getField("data").get(fd); if (lf != null && lfCls != null) { if (strikeout) lfCls.getField("lfStrikeOut").set(lf, new Byte((byte) 1)); if (underline) lfCls.getField("lfUnderline").set(lf, new Byte((byte) 1)); } } catch (Throwable e) { System.err.println( "Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); } } Font font = new Font(Display.getDefault(), fd); resources.put(fontName, font); return font; }
From source file:org.openvpms.component.business.service.archetype.JXPathGenericObjectCreationFactory.java
@Override public boolean createObject(JXPathContext context, Pointer ptr, Object parent, String name, int index) { try {// w w w .j a v a 2 s .c o m NodeDescriptor node = (NodeDescriptor) context.getVariables().getVariable("node"); if (logger.isDebugEnabled()) { logger.debug("root: " + context.getContextBean().toString() + " parent: " + parent.toString() + " name: " + name + " index: " + index + " type: " + node.getType()); } Class clazz = Thread.currentThread().getContextClassLoader().loadClass(node.getType()); if (clazz == Boolean.class) { ptr.setValue(new Boolean(false)); } else if (clazz == Integer.class) { ptr.setValue(new Integer(0)); } else if (clazz == Long.class) { ptr.setValue(new Long(0L)); } else if (clazz == Double.class) { ptr.setValue(new Double(0.0)); } else if (clazz == Float.class) { ptr.setValue(new Float(0.0)); } else if (clazz == Short.class) { ptr.setValue(new Short((short) 0)); } else if (clazz == Byte.class) { ptr.setValue(new Byte((byte) 0)); } else if (clazz == Money.class) { ptr.setValue(new Money("0.0")); } else if (clazz == BigDecimal.class) { ptr.setValue(BigDecimal.valueOf(0.0)); } else { ptr.setValue(clazz.newInstance()); } } catch (Exception exception) { logger.error("root: " + context.getContextBean().toString() + " parent: " + parent.toString() + " name: " + name + " index: " + index, exception); return false; } return true; }
From source file:org.jboss.dashboard.factory.PropertySubstractProcessingInstruction.java
public Object getValueAfterChange(Object originalValue, Class expectedClass) throws Exception { if (log.isDebugEnabled()) log.debug("Processing instruction " + this + " on value " + originalValue + " (" + expectedClass + ")"); Object valueToSubstract = null; Object currentValue = originalValue; currentValue = currentValue == null ? getNewInstanceForClass(expectedClass) : currentValue; valueToSubstract = getValueForParameter(getPropertyValue(), expectedClass); if (valueToSubstract != null) { if (expectedClass.isArray()) { if (((Object[]) valueToSubstract).length == 0) { return null; //Special case. Using stringProperty-=, sets it to null. } else { //Otherwise, occurrences of valueToSubstract are removed from the array List list = new ArrayList(); list.addAll(Arrays.asList((Object[]) currentValue)); list.removeAll(Arrays.asList((Object[]) valueToSubstract)); return list.toArray((Object[]) getBaseArray(expectedClass.getComponentType(), list.size())); }/*w w w. j a va 2 s . c o m*/ } else if (expectedClass.equals(int.class)) { return new Integer(((Integer) currentValue).intValue() - ((Integer) valueToSubstract).intValue()); } else if (expectedClass.equals(long.class)) { return new Long(((Long) currentValue).longValue() - ((Long) valueToSubstract).longValue()); } else if (expectedClass.equals(double.class)) { return new Double( ((Double) currentValue).doubleValue() - ((Double) valueToSubstract).doubleValue()); } else if (expectedClass.equals(float.class)) { return new Float(((Float) currentValue).floatValue() - ((Float) valueToSubstract).floatValue()); } else if (expectedClass.equals(byte.class)) { return new Byte((byte) (((Byte) currentValue).byteValue() - ((Byte) valueToSubstract).byteValue())); } else if (expectedClass.equals(short.class)) { return new Short( (short) (((Short) currentValue).shortValue() - ((Short) valueToSubstract).shortValue())); } else if (expectedClass.equals(Integer.class)) { return new Integer(((Integer) currentValue).intValue() - ((Integer) valueToSubstract).intValue()); } else if (expectedClass.equals(Long.class)) { return new Long(((Long) currentValue).longValue() - ((Long) valueToSubstract).longValue()); } else if (expectedClass.equals(Double.class)) { return new Double( ((Double) currentValue).doubleValue() - ((Double) valueToSubstract).doubleValue()); } else if (expectedClass.equals(Float.class)) { return new Float(((Float) currentValue).floatValue() - ((Float) valueToSubstract).floatValue()); } else if (expectedClass.equals(Byte.class)) { return new Byte((byte) (((Byte) currentValue).byteValue() - ((Byte) valueToSubstract).byteValue())); } else if (expectedClass.equals(Short.class)) { return new Short( (short) (((Short) currentValue).shortValue() - ((Short) valueToSubstract).shortValue())); } else if (expectedClass.equals(String.class)) { if ("".equals(valueToSubstract)) { return null; //Special case. Using stringProperty-=, sets it to null. } if (((String) currentValue).indexOf((String) valueToSubstract) != -1) { currentValue = StringUtil.replaceAll((String) currentValue, (String) valueToSubstract, ""); } //Otherwise, occurrences of valueToSubstract are removed from the String. } else { log.error("Addition not supported for class " + expectedClass + ". Ignoring property " + getPropertyName() + "+=" + getPropertyValue()); } } return originalValue; }
From source file:org.apache.flex.forks.velocity.test.CommonsExtPropTestCase.java
/** * Runs the test./*from w w w . j a v a2 s . c om*/ */ public void runTest() { try { assureResultsDirectoryExists(RESULTS_DIR); ExtendedProperties c = new ExtendedProperties(TEST_CONFIG); FileWriter result = new FileWriter(getFileName(RESULTS_DIR, "output", "res")); message(result, "Testing order of keys ..."); showIterator(result, c.getKeys()); message(result, "Testing retrieval of CSV values ..."); showVector(result, c.getVector("resource.loader")); message(result, "Testing subset(prefix).getKeys() ..."); ExtendedProperties subset = c.subset("file.resource.loader"); showIterator(result, subset.getKeys()); message(result, "Testing getVector(prefix) ..."); showVector(result, subset.getVector("path")); message(result, "Testing getString(key) ..."); result.write(c.getString("config.string.value")); result.write("\n\n"); message(result, "Testing getBoolean(key) ..."); result.write(new Boolean(c.getBoolean("config.boolean.value")).toString()); result.write("\n\n"); message(result, "Testing getByte(key) ..."); result.write(new Byte(c.getByte("config.byte.value")).toString()); result.write("\n\n"); message(result, "Testing getShort(key) ..."); result.write(new Short(c.getShort("config.short.value")).toString()); result.write("\n\n"); message(result, "Testing getInt(key) ..."); result.write(new Integer(c.getInt("config.int.value")).toString()); result.write("\n\n"); message(result, "Testing getLong(key) ..."); result.write(new Long(c.getLong("config.long.value")).toString()); result.write("\n\n"); message(result, "Testing getFloat(key) ..."); result.write(new Float(c.getFloat("config.float.value")).toString()); result.write("\n\n"); message(result, "Testing getDouble(key) ..."); result.write(new Double(c.getDouble("config.double.value")).toString()); result.write("\n\n"); message(result, "Testing escaped-comma scalar..."); result.write(c.getString("escape.comma1")); result.write("\n\n"); message(result, "Testing escaped-comma vector..."); showVector(result, c.getVector("escape.comma2")); result.write("\n\n"); result.flush(); result.close(); if (!isMatch(RESULTS_DIR, COMPARE_DIR, "output", "res", "cmp")) { fail("Output incorrect."); } } catch (Exception e) { System.err.println("Cannot setup CommonsExtPropTestCase!"); e.printStackTrace(); System.exit(1); } }
From source file:org.openTwoFactor.clientExt.net.sf.ezmorph.array.ByteArrayMorpher.java
public Object morph(Object array) { if (array == null) { return null; }//from w ww . j a v a 2 s . c o m if (BYTE_ARRAY_CLASS.isAssignableFrom(array.getClass())) { // no conversion needed return (byte[]) array; } if (array.getClass().isArray()) { int length = Array.getLength(array); int dims = getDimensions(array.getClass()); int[] dimensions = createDimensions(dims, length); Object result = Array.newInstance(byte.class, dimensions); ByteMorpher morpher = isUseDefault() ? new ByteMorpher(defaultValue) : new ByteMorpher(); if (dims == 1) { for (int index = 0; index < length; index++) { Array.set(result, index, new Byte(morpher.morph(Array.get(array, index)))); } } else { for (int index = 0; index < length; index++) { Array.set(result, index, morph(Array.get(array, index))); } } return result; } else { throw new MorphException("argument is not an array: " + array.getClass()); } }
From source file:org.apache.phoenix.hive.util.PhoenixStorageHandlerUtil.java
public static Object[] toTypedValues(JobConf jobConf, String typeName, String[] values) throws Exception { Object[] results = new Object[values.length]; DateFormat df = null;/*from w ww. j a v a 2 s . c o m*/ for (int i = 0, limit = values.length; i < limit; i++) { if (serdeConstants.STRING_TYPE_NAME.equals(typeName) || typeName.startsWith(serdeConstants.CHAR_TYPE_NAME) || typeName.startsWith(serdeConstants.VARCHAR_TYPE_NAME)) { results[i] = values[i]; } else if (serdeConstants.INT_TYPE_NAME.equals(typeName)) { results[i] = new Integer(values[i]); } else if (serdeConstants.BIGINT_TYPE_NAME.equals(typeName)) { results[i] = new Long(values[i]); } else if (serdeConstants.DOUBLE_TYPE_NAME.equals(typeName)) { results[i] = new Double(values[i]); } else if (serdeConstants.FLOAT_TYPE_NAME.equals(typeName)) { results[i] = new Float(values[i]); } else if (serdeConstants.SMALLINT_TYPE_NAME.equals(typeName)) { results[i] = new Short(values[i]); } else if (serdeConstants.TINYINT_TYPE_NAME.equals(typeName)) { results[i] = new Byte(values[i]); } else if (serdeConstants.DATE_TYPE_NAME.equals(typeName)) { String dateFormat = jobConf.get(PhoenixStorageHandlerConstants.HBASE_DATE_FORMAT, PhoenixStorageHandlerConstants.DEFAULT_DATE_FORMAT); df = new SimpleDateFormat(dateFormat); results[i] = new Long(df.parse(values[i]).getTime()); } else if (serdeConstants.TIMESTAMP_TYPE_NAME.equals(typeName)) { String timestampFormat = jobConf.get(PhoenixStorageHandlerConstants.HBASE_TIMESTAMP_FORMAT, PhoenixStorageHandlerConstants.DEFAULT_TIMESTAMP_FORMAT); df = new SimpleDateFormat(timestampFormat); results[i] = new Long(df.parse(values[i]).getTime()); } else if (typeName.contains(serdeConstants.DECIMAL_TYPE_NAME)) { results[i] = new BigDecimal(values[i]); } } return results; }
From source file:org.apache.velocity.test.CommonsExtPropTestCase.java
/** * Runs the test./*from w w w . j a v a 2s.c o m*/ */ public void testExtendedProperties() throws Exception { assureResultsDirectoryExists(RESULTS_DIR); ExtendedProperties c = new ExtendedProperties(TEST_CONFIG); FileWriter result = new FileWriter(getFileName(RESULTS_DIR, "output", "res")); message(result, "Testing order of keys ..."); showIterator(result, c.getKeys()); message(result, "Testing retrieval of CSV values ..."); showVector(result, c.getVector("resource.loader")); message(result, "Testing subset(prefix).getKeys() ..."); ExtendedProperties subset = c.subset("file.resource.loader"); showIterator(result, subset.getKeys()); message(result, "Testing getVector(prefix) ..."); showVector(result, subset.getVector("path")); message(result, "Testing getString(key) ..."); result.write(c.getString("config.string.value")); result.write("\n\n"); message(result, "Testing getBoolean(key) ..."); result.write(new Boolean(c.getBoolean("config.boolean.value")).toString()); result.write("\n\n"); message(result, "Testing getByte(key) ..."); result.write(new Byte(c.getByte("config.byte.value")).toString()); result.write("\n\n"); message(result, "Testing getShort(key) ..."); result.write(new Short(c.getShort("config.short.value")).toString()); result.write("\n\n"); message(result, "Testing getInt(key) ..."); result.write(new Integer(c.getInt("config.int.value")).toString()); result.write("\n\n"); message(result, "Testing getLong(key) ..."); result.write(new Long(c.getLong("config.long.value")).toString()); result.write("\n\n"); message(result, "Testing getFloat(key) ..."); result.write(new Float(c.getFloat("config.float.value")).toString()); result.write("\n\n"); message(result, "Testing getDouble(key) ..."); result.write(new Double(c.getDouble("config.double.value")).toString()); result.write("\n\n"); message(result, "Testing escaped-comma scalar..."); result.write(c.getString("escape.comma1")); result.write("\n\n"); message(result, "Testing escaped-comma vector..."); showVector(result, c.getVector("escape.comma2")); result.write("\n\n"); result.flush(); result.close(); if (!isMatch(RESULTS_DIR, COMPARE_DIR, "output", "res", "cmp")) { fail("Output incorrect."); } }
From source file:com.neovisionaries.security.DigestTest.java
@Test public void test2() { List<Number> list = new ArrayList<Number>(); list.add(new Byte((byte) 1)); list.add(new Short((short) 2)); list.add(new Integer(3)); list.add(new Long(4)); list.add(new Float(5)); list.add(new Double(6)); String digest1 = sha1().update(list).digestAsString(); String digest2 = sha1().update((byte) 1).update((short) 2).update(3).update((long) 4).update((float) 5) .update((double) 6).digestAsString(); assertEquals(digest1, digest2);// w ww .j a va 2s.c o m }
From source file:Crypt.java
private String decryptByDES(String str) throws Exception { Cipher c;/*from w w w . j a va 2 s .c om*/ try { byte[] tmp = new byte[str.length() / 2]; int index = 0; while (index < str.length()) { // convert hexadecimal number into decimal number. int num = Integer.parseInt(str.substring(index, index + 2), 16); // convert into signed byte. if (num < 128) { tmp[index / 2] = new Byte(Integer.toString(num)).byteValue(); } else { tmp[index / 2] = new Byte(Integer.toString(((num ^ 255) + 1) * -1)).byteValue(); } index += 2; } c = Cipher.getInstance("DES/ECB/PKCS5Padding"); c.init(Cipher.DECRYPT_MODE, secretKey); return new String(c.doFinal(tmp)); } catch (InvalidKeyException e) { log.error("The information of the private key may be broken.", e); throw e; } catch (IllegalBlockSizeException e) { log.error("he length of data is unjust.", e); throw e; } }
From source file:edu.utah.further.core.api.collections.ToParameterMapBuilder.java
/** * Append a byte field value./*from ww w .ja va 2 s .co m*/ * * @param fieldName * the name of the field, usually the member variable name * @param value * the field value * @return this, to support call-chaining */ public ToParameterMapBuilder append(final String fieldName, final byte value) { return append(fieldName, new Byte(value)); }