List of usage examples for java.lang Byte valueOf
public static Byte valueOf(String s) throws NumberFormatException
From source file:org.red5.io.mock.Output.java
/** {@inheritDoc} */ public void writeXML(String xml) { list.add(Byte.valueOf(DataTypes.CORE_XML)); list.add(xml); }
From source file:com.ebay.nest.io.sede.MetadataTypedColumnsetSerDe.java
private String getByteValue(String altValue, String defaultVal) { if (altValue != null && altValue.length() > 0) { try {//from w ww .ja va 2s . co m byte[] b = new byte[1]; b[0] = Byte.valueOf(altValue).byteValue(); return new String(b); } catch (NumberFormatException e) { return altValue; } } return defaultVal; }
From source file:org.red5.io.mock.Output.java
/** {@inheritDoc} */ public void writeArray(Collection array, Serializer serializer) { list.add(Byte.valueOf(DataTypes.CORE_ARRAY)); list.add(array); }
From source file:StorageEngineClient.FormatStorageHiveOutputFormat.java
@Override public RecordWriter getHiveRecordWriter(JobConf jc, Path finalOutPath, Class<? extends Writable> valueClass, boolean isCompressed, Properties tbl, Progressable progress) throws IOException { boolean usenewformat = jc.getBoolean("fdf.newformat", false); IHead head = new IHead(usenewformat ? ConstVar.NewFormatFile : ConstVar.OldFormatFile); boolean flag = true; if (flag) {/*from w ww .jav a 2 s .co m*/ String columnTypeProperty = tbl.getProperty(Constants.LIST_COLUMN_TYPES); ArrayList<TypeInfo> types; if (columnTypeProperty == null) types = new ArrayList<TypeInfo>(); else types = TypeInfoUtils.getTypeInfosFromTypeString(columnTypeProperty); String compress = tbl.getProperty(ConstVar.Compress); String ifdfCompressionOn = jc.get(ConstVar.CompressionConfName); if ((ifdfCompressionOn != null && ifdfCompressionOn.equalsIgnoreCase("true")) || (compress != null && compress.equalsIgnoreCase("true"))) { head.setCompress((byte) 1); String strCompressionMethod = jc.get(ConstVar.CompressionMethodConfName); if (strCompressionMethod != null) { try { byte compressionMethod = Byte.valueOf(strCompressionMethod).byteValue(); head.setCompressStyle(compressionMethod); } catch (NumberFormatException e) { } } String compressionLevel = jc.get(ConstVar.ZlibCompressionLevelConfName); if (compressionLevel != null) { if (compressionLevel.equalsIgnoreCase("bestSpeed")) { jc.set("zlib.compress.level", ZlibCompressor.CompressionLevel.BEST_SPEED.toString()); } else if (compressionLevel.equalsIgnoreCase("bestCompression")) { jc.set("zlib.compress.level", ZlibCompressor.CompressionLevel.BEST_COMPRESSION.toString()); } } } IFieldMap map = new IFieldMap(); int i = 0; for (TypeInfo type : types) { byte fdftype = 0; String name = type.getTypeName(); if (name.equals(Constants.TINYINT_TYPE_NAME)) fdftype = ConstVar.FieldType_Byte; else if (name.equals(Constants.SMALLINT_TYPE_NAME)) fdftype = ConstVar.FieldType_Short; else if (name.equals(Constants.INT_TYPE_NAME)) fdftype = ConstVar.FieldType_Int; else if (name.equals(Constants.BIGINT_TYPE_NAME)) fdftype = ConstVar.FieldType_Long; else if (name.equals(Constants.FLOAT_TYPE_NAME)) fdftype = ConstVar.FieldType_Float; else if (name.equals(Constants.DOUBLE_TYPE_NAME)) fdftype = ConstVar.FieldType_Double; else if (name.equals(Constants.STRING_TYPE_NAME)) fdftype = ConstVar.FieldType_String; else if (name.equals(Constants.TIMESTAMP_TYPE_NAME)) fdftype = ConstVar.FieldType_String; map.addFieldType(new IRecord.IFType(fdftype, i++)); } head.setFieldMap(map); } final IFormatDataFile ifdf = new IFormatDataFile(jc); ifdf.create(finalOutPath.toString(), head); return new RecordWriter() { @Override public void write(Writable w) throws IOException { ifdf.addRecord((IRecord) w); } @Override public void close(boolean abort) throws IOException { ifdf.close(); } }; }
From source file:StorageEngineClient.FormatStorageIRecordReader.java
public FormatStorageIRecordReader(CombineFileSplit split, Configuration conf, Reporter report, Integer idx) throws IOException { int id = idx.intValue(); this.conf = conf; Path p = split.getPath(id);/* ww w . ja v a 2 s. co m*/ file = p.toString(); if (file.toLowerCase().endsWith(".gz")) { int index = file.lastIndexOf("_"); String sub = file.substring(index + 1, file.length() - 3); this.recnum = Integer.valueOf(sub); isGZ = true; compressionCodecs = new CompressionCodecFactory(conf); final CompressionCodec codec = compressionCodecs.getCodec(p); FileSystem fs = new Path(file).getFileSystem(conf); FSDataInputStream fileIn = fs.open(p); in = new LineReader(codec.createInputStream(fileIn), conf); Text t = new Text(); in.readLine(t); StringTokenizer stk = new StringTokenizer(t.toString(), new String(new char[] { '\01' })); int k = 0; while (stk.hasMoreTokens()) { String str = stk.nextToken(); byte b = Byte.valueOf(str); IRecord.IFType type = new IRecord.IFType(b, k); fieldtypes.put(k, type); k++; } maxLineLength = Integer.MAX_VALUE; currentrec = 0; } else { ifdf = new IFormatDataFile(conf); ifdf.open(file); ISegmentIndex isi = ifdf.segIndex(); if (isi.getSegnum() == 0) { this.recnum = 0; } else { long offset = split.getOffset(id); long len = split.getLength(id); int[] segids = isi.getsigidsinoffsetrange(offset, (int) len); System.out.println("fsplit:\toffset: " + offset + " len: " + len + " segids[0]: " + segids[0] + " segids[1]: " + segids[1]); if (segids[0] >= 0 && segids[0] < isi.getSegnum() && segids[1] <= isi.getSegnum() && segids[1] > segids[0]) { int line = isi.getILineIndex(segids[0]).beginline(); this.beginline = line; ifdf.seek(line); this.recnum = 0; for (int i = segids[0]; i < segids[1]; i++) { this.recnum += isi.getILineIndex(i).recnum(); } } else { this.recnum = 0; } } } }
From source file:com.ebay.nest.io.sede.lazy.LazySimpleSerDe.java
/** * Return the byte value of the number string. * * @param altValue//w w w .j a va 2 s .c o m * The string containing a number. * @param defaultVal * If the altValue does not represent a number, return the * defaultVal. */ public static byte getByte(String altValue, byte defaultVal) { if (altValue != null && altValue.length() > 0) { try { return Byte.valueOf(altValue).byteValue(); } catch (NumberFormatException e) { return (byte) altValue.charAt(0); } } return defaultVal; }
From source file:com.workday.autoparse.json.demo.JsonParserTest.java
private void testParse(String fileName) throws Exception { TestObject testObject = (TestObject) parser.parseJsonStream(getInputStream(fileName)); assertNotNull("testObject", testObject); assertEquals("testObject.discriminationValue", "testObject", testObject.discriminationValue); assertEquals("testObject.superDiscriminationValue", "testObject", testObject.superDiscriminationValue); // Basic Types assertTrue("testObject.myBoolean", testObject.myBoolean); assertEquals("testObject.myByte", (byte) 65, testObject.myByte); assertEquals("testObject.myChar", 'c', testObject.myChar); assertEquals("testObject.myDouble", 12.34, testObject.myDouble, ERROR); assertEquals("testObject.myFloat", 123.45f, testObject.myFloat, ERROR); assertEquals("testObject.myInt", 12, testObject.myInt); assertEquals("testObject.myLong", 123456, testObject.myLong); assertEquals("testObject.myShort", 17, testObject.myShort); assertTrue("testObject.myBoxedBoolean", testObject.myBoxedBoolean); assertEquals("testObject.myBoxedByte", Byte.valueOf("63"), testObject.myBoxedByte); assertEquals("testObject.myBoxedChar", Character.valueOf('d'), testObject.myBoxedChar); assertEquals("testObject.myBoxedDouble", Double.valueOf("12.345"), testObject.myBoxedDouble); assertEquals("testObject.myBoxedFloat", Float.valueOf("123.456"), testObject.myBoxedFloat); assertEquals("testObject.myBoxedInt", Integer.valueOf("123"), testObject.myBoxedInt); assertEquals("testObject.myBoxedLong", Long.valueOf(1234567), testObject.myBoxedLong); assertEquals("testObject.myBoxedShort", new Short("18"), testObject.myBoxedShort); assertEquals("testObject.myString", "hello", testObject.myString); assertEquals("testObject.myBigDecimal", new BigDecimal("123456789.0123456789"), testObject.myBigDecimal); assertEquals("testObject.myBigInteger", new BigInteger("1234567891011"), testObject.myBigInteger); assertEquals("testObject.overriddenThing", 123, testObject.overriddenThing); assertNull("testObject.superOverriddenThing", testObject.superOverriddenThing); // Maps// w ww. j a va 2s .c om assertNotNull("testObject.myStringMap", testObject.myStringMap); assertEquals("testObject.myStringMap.size", 2, testObject.myStringMap.size()); assertEquals("testObject.myStringMap[key1]", "value1", testObject.myStringMap.get("key1")); assertEquals("testObject.myStringMap[key2]", "value2", testObject.myStringMap.get("key2")); assertNotNull("testObject.myTestObjectMap", testObject.myTestObjectMap); assertEquals("testObject.myTestObjectMap.size", 2, testObject.myTestObjectMap.size()); assertEquals("testObject.myTestObjectMap[key1]", new SimpleTestObject("post-parse:string 1"), testObject.myTestObjectMap.get("key1")); assertEquals("testObject.myTestObjectMap[key2]", new SimpleTestObject("post-parse:string 2"), testObject.myTestObjectMap.get("key2")); assertNotNull("testObject.myInterfaceMap", testObject.myInterfaceMap); assertEquals("testObject.myInterfaceMap.size", 2, testObject.myInterfaceMap.size()); assertEquals("testObject.myInterfaceMap[key1]", new TestObject.InnerTestObject("string 1"), testObject.myInterfaceMap.get("key1")); assertEquals("testObject.myInterfaceMap[key2]", new TestObject.InnerTestObject("string 2"), testObject.myInterfaceMap.get("key2")); assertNotNull("testObject.myObjectMap", testObject.myObjectMap); assertEquals("testObject.myObjectMap.size", 2, testObject.myTestObjectMap.size()); assertEquals("testObject.myObjectMap[key1]", new SimpleTestObject("post-parse:string 1", "simpleTestObject"), testObject.myObjectMap.get("key1")); assertEquals("testObject.myObjectMap[key2]", "25", testObject.myObjectMap.get("key2")); // Collections assertEquals("testObject.myBooleanCollection", CollectionUtils.newHashSet(true, false, true), testObject.myBooleanCollection); assertEquals("testObject.myByteCollection", CollectionUtils.newHashSet((byte) 63, (byte) 64), testObject.myByteCollection); assertEquals("testObject.myCharCollection", new LinkedHashSet<>(CollectionUtils.newArrayList('d', 'e')), testObject.myCharCollection); assertEquals("testObject.myDoubleCollection", new LinkedList<>(CollectionUtils.newArrayList(12.345, 13.345)), testObject.myDoubleCollection); assertEquals("testObject.myFloatCollection", CollectionUtils.newArrayList(123.456f, 234.56f), testObject.myFloatCollection); assertEquals("testObject.myIntCollection", CollectionUtils.newArrayList(123, 456), testObject.myIntCollection); assertEquals("testObject.myLongCollection", CollectionUtils.newArrayList(1234567L, 2345678L), testObject.myLongCollection); assertEquals("testObject.myShortCollection", CollectionUtils.newArrayList((short) 18, (short) 19), testObject.myShortCollection); assertEquals("testObject.myStringCollection", CollectionUtils.newArrayList("hello", "there"), testObject.myStringCollection); assertEquals("testObject.myBigDecimalCollection", CollectionUtils .newArrayList(new BigDecimal("123456789.0123456789"), new BigDecimal("23456789.0123456789")), testObject.myBigDecimalCollection); assertEquals("testObject.myBigIntegerCollection", CollectionUtils.newArrayList(new BigInteger("1234567891011"), new BigInteger("234567891011")), testObject.myBigIntegerCollection); // Custom Objects SimpleTestObject singularChild = testObject.mySingularChild; assertNotNull("testObject.mySingularChild", singularChild); assertEquals("testObject.mySingularChild.myString", "post-parse:a singular child", singularChild.myString); assertTrue("testObject.mySingularChildByInterface instanceOf InnerTestObject", testObject.mySingularChildByInterface instanceof TestObject.InnerTestObject); assertEquals("testObject.mySingularChildByInterface.string", "an object", ((TestObject.InnerTestObject) (testObject.mySingularChildByInterface)).string); assertEquals("testObject.myInnerObject", new TestObject.InnerTestObject("an InnerTestObject"), testObject.myInnerObject); List<SimpleTestObject> list = testObject.myList; assertNotNull("testObject.myList", list); assertEquals("testObject.myList.size()", 2, list.size()); assertEquals("testObject.myList[0].myString", "post-parse:list child 0", list.get(0).myString); assertEquals("testObject.myList[1].myString", "post-parse:list child 1", list.get(1).myString); assertNotNull("testObject.myListByInterface", testObject.myListByInterface); assertEquals("testObject.myListByInterface", 2, testObject.myListByInterface.size()); assertTrue("testObject.myListByInterface[0] instanceOf InnerTestObject", testObject.myListByInterface.get(0) instanceof TestObject.InnerTestObject); assertEquals("testObject.myListByInterface[0]", "object 0", ((TestObject.InnerTestObject) (testObject.myListByInterface.get(0))).string); assertTrue("testObject.myListByInterface[1] instanceOf InnerTestObject", testObject.myListByInterface.get(1) instanceof TestObject.InnerTestObject); assertEquals("testObject.myListByInterface[1]", "object 1", ((TestObject.InnerTestObject) (testObject.myListByInterface.get(1))).string); List<List<Integer>> collectionOfCollections = testObject.myCollectionOfCollections; assertNotNull("testObject.collectionOfCollections", collectionOfCollections); assertEquals("testObject.collectionOfCollections.size()", 2, collectionOfCollections.size()); assertEquals("testObject.collectionOfCollection[0]", CollectionUtils.newArrayList(1, 2), collectionOfCollections.get(0)); assertEquals("testObject.collectionOfCollection[1]", CollectionUtils.newArrayList(3, 4), collectionOfCollections.get(1)); List<Set<SimpleTestObject>> collectionOfCollectionUtilsOfTestObjects = testObject.mySetsOfTestObjects; assertNotNull("testObject.myCollectionUtilsOfTestObjects", collectionOfCollectionUtilsOfTestObjects); assertEquals("testObject.myCollectionUtilsOfTestObjects[0][0]", CollectionUtils.newHashSet(new SimpleTestObject("post-parse:set 0 child 0", "simpleTestObject"), new SimpleTestObject("post-parse:set 0 child 1", "simpleTestObject")), collectionOfCollectionUtilsOfTestObjects.get(0)); assertEquals("testObject.myCollectionUtilsOfTestObjects[0][0]", CollectionUtils.newHashSet(new SimpleTestObject("post-parse:set 1 child 0", "simpleTestObject"), new SimpleTestObject("post-parse:set 1 child 1", "simpleTestObject")), collectionOfCollectionUtilsOfTestObjects.get(1)); assertEquals("testObject.myUnannotatedObject", new UnannotatedObject("singular unannotated object"), testObject.myUnannotatedObject); assertEquals("testObject.myUnannotatedObjectCollection", CollectionUtils.newArrayList(new UnannotatedObject("unannotated item 0"), new UnannotatedObject("unannotated item 1")), testObject.myUnannotatedObjectCollection); // JSON Natives assertNotNull("testObject.myJsonObject", testObject.myJsonObject); assertEquals("testObject.myJsonObject.getString(\"name\")", "value", testObject.myJsonObject.getString("name")); assertNotNull("testObject.myJsonArray", testObject.myJsonArray); assertEquals("testObject.myJsonArray.length()", 2, testObject.myJsonArray.length()); assertEquals("testObject.myJsonArray[0].(\"name 0\")", "value 0", ((JSONObject) testObject.myJsonArray.get(0)).getString("name 0")); assertEquals("testObject.myJsonArray[1].(\"name 1\")", "value 1", ((JSONObject) testObject.myJsonArray.get(1)).getString("name 1")); assertNotNull("testObject.myJsonObjectCollection", testObject.myJsonObjectCollection); assertEquals("testObject.myJsonObjectCollection.size()", 2, testObject.myJsonObjectCollection.size()); assertEquals("testObject.myJsonObjectCollection[0].(\"list name 0\")", "list value 0", testObject.myJsonObjectCollection.get(0).getString("list name 0")); assertEquals("testObject.myJsonObjectCollection[1].(\"list name 1\")", "list value 1", testObject.myJsonObjectCollection.get(1).getString("list name 1")); // Setters assertEquals("testObject.stringFromSetter", "string for setter", testObject.stringFromSetter); assertEquals("testObject.unannotatedObjectFromSetter", new UnannotatedObject("unannotated object for setter"), testObject.unannotatedObjectFromSetter); assertEquals("testObject.testObjectCollectionFromSetter", CollectionUtils.newArrayList(new ParserAnnotatedObject("object for list setter 0", null), new ParserAnnotatedObject("object for list setter 1", null)), testObject.testObjectCollectionFromSetter); assertNotNull("testObject.integerCollectionsFromSetter", testObject.integerCollectionsFromSetter); assertEquals("testObject.integerCollectionsFromSetter.size()", 2, testObject.integerCollectionsFromSetter.size()); assertEquals("testObject.integerCollectionsFromSetter.get(0)", CollectionUtils.newHashSet(1, 2), testObject.integerCollectionsFromSetter.get(0)); assertEquals("testObject.integerCollectionsFromSetter.get(1)", CollectionUtils.newHashSet(3, 4), testObject.integerCollectionsFromSetter.get(1)); // Empty Objects assertEquals("testObject.myEmptyObject", new SimpleTestObject(), testObject.myEmptyObject); assertNotNull("testObject.myEmptyCollection", testObject.myEmptyCollection); assertTrue("testObject.myEmptyCollection.isEmpty()", testObject.myEmptyCollection.isEmpty()); // Nulls assertEquals("testObject.myNullInt", 1, testObject.myNullInt); assertNull("testObject.myNullString", testObject.myNullString); assertNull("testObject.myNullTestObject", testObject.myNullTestObject); assertNull("testObject.myNullCollection", testObject.myNullCollection); assertEquals("testObject.myDefaultCollection", Collections.singleton("the one"), testObject.myDefaultCollection); }
From source file:org.red5.io.mock.Output.java
/** {@inheritDoc} */ public void writeArray(Object[] array, Serializer serializer) { list.add(Byte.valueOf(DataTypes.CORE_ARRAY)); list.add(array); }
From source file:org.apache.hadoop.hive.serde2.TestSerDe.java
@Override public void initialize(Configuration job, Properties tbl) throws SerDeException { separator = DefaultSeparator;/* ww w . j a v a2s .c o m*/ String altSep = tbl.getProperty(DEFAULT_SERIALIZATION_FORMAT); if (altSep != null && altSep.length() > 0) { try { byte[] b = new byte[1]; b[0] = Byte.valueOf(altSep).byteValue(); separator = new String(b); } catch (NumberFormatException e) { separator = altSep; } } String columnProperty = tbl.getProperty(COLUMNS); if (columnProperty == null || columnProperty.length() == 0) { // Hack for tables with no columns // Treat it as a table with a single column called "col" cachedObjectInspector = ObjectInspectorFactory.getReflectionObjectInspector(ColumnSet.class, ObjectInspectorFactory.ObjectInspectorOptions.JAVA); } else { columnNames = Arrays.asList(columnProperty.split(",")); cachedObjectInspector = MetadataListStructObjectInspector.getInstance(columnNames, Lists.newArrayList(Splitter.on('\0').split(tbl.getProperty(COLUMNS_COMMENTS)))); } LOG.info(getClass().getName() + ": initialized with columnNames: " + columnNames); }
From source file:me.rojo8399.placeholderapi.impl.utils.TypeUtils.java
@SuppressWarnings("unchecked") public static <T> T convertPrimitive(String val, Class<T> primitiveClass) { val = val.toLowerCase().trim(); if (primitiveClass.equals(char.class) || primitiveClass.equals(Character.class)) { return (T) (Character) val.charAt(0); }/*from w ww . ja v a2 s .c o m*/ if (primitiveClass.equals(int.class) || primitiveClass.equals(Integer.class)) { return (T) Integer.valueOf(val); } if (primitiveClass.equals(long.class) || primitiveClass.equals(Long.class)) { return (T) Long.valueOf(val); } if (primitiveClass.equals(short.class) || primitiveClass.equals(Short.class)) { return (T) Short.valueOf(val); } if (primitiveClass.equals(byte.class) || primitiveClass.equals(Byte.class)) { return (T) Byte.valueOf(val); } if (primitiveClass.equals(double.class) || primitiveClass.equals(Double.class)) { return (T) Double.valueOf(val); } if (primitiveClass.equals(float.class) || primitiveClass.equals(Float.class)) { return (T) Float.valueOf(val); } if (primitiveClass.equals(boolean.class) || primitiveClass.equals(Boolean.class)) { return (T) (Boolean) isTrue(val); } throw new IllegalArgumentException("Class is not primitive or a wrapper!"); }