List of usage examples for java.lang Byte toString
public String toString()
From source file:Main.java
public static void main(String[] args) { Byte bObj = new Byte("10"); String str = bObj.toString(); System.out.println(str);/*from ww w . ja va2 s.co m*/ }
From source file:Main.java
public static void main(String[] args) { Byte byteObject = new Byte("10"); String str = byteObject.toString(); System.out.println("str:" + str); }
From source file:com.github.jessemull.microflex.util.BigIntegerUtil.java
/** * Safely converts a number to a BigInteger. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Object object to parse// w w w . j a va 2 s.c o m * @return parsed object * @throws ArithmeticException on overflow */ public static BigInteger toBigInteger(Object obj) { /* Switch on class and convert to BigInteger */ String type = obj.getClass().getSimpleName(); BigInteger parsed; switch (type) { case "Byte": Byte by = (Byte) obj; parsed = new BigInteger(by.toString()); break; case "Short": Short sh = (Short) obj; parsed = new BigInteger(sh.toString()); break; case "Integer": Integer in = (Integer) obj; parsed = new BigInteger(in.toString()); break; case "Long": Long lo = (Long) obj; parsed = new BigInteger(lo.toString()); break; case "Float": Float fl = (Float) obj; parsed = new BigInteger(fl.toString()); break; case "BigInteger": parsed = (BigInteger) obj; break; case "BigDecimal": parsed = ((BigDecimal) obj).toBigInteger(); break; case "Double": Double db = (Double) obj; parsed = new BigInteger(db.toString()); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }
From source file:com.github.jessemull.microflex.util.BigIntegerUtil.java
/** * Safely converts a number to a BigInteger. Loss of precision may occur. Throws * an arithmetic exception upon overflow. * @param Number object to parse// ww w .ja va2 s .co m * @return parsed object * @throws ArithmeticException on overflow */ public static BigInteger toBigInteger(Number number) { /* Switch on class and convert to BigInteger */ String type = number.getClass().getSimpleName(); BigInteger parsed; switch (type) { case "Byte": Byte by = (Byte) number; parsed = new BigInteger(by.toString()); break; case "Short": Short sh = (Short) number; parsed = new BigInteger(sh.toString()); break; case "Integer": Integer in = (Integer) number; parsed = new BigInteger(in.toString()); break; case "Long": Long lo = (Long) number; parsed = new BigInteger(lo.toString()); break; case "Float": Float fl = (Float) number; parsed = new BigInteger(fl.toString()); break; case "BigInteger": parsed = (BigInteger) number; break; case "BigDecimal": parsed = ((BigDecimal) number).toBigInteger(); break; case "Double": Double db = (Double) number; parsed = new BigInteger(db.toString()); break; default: throw new IllegalArgumentException( "Invalid type: " + type + "\nData values " + "must extend the abstract Number class."); } return parsed; }
From source file:edu.ku.brc.helpers.XMLHelper.java
public static void xmlAttr(final StringBuilder sb, final String attr, final Byte val) { if (val != null || isEmptyAttrOK) { xmlAttr(sb, attr, val.toString()); }/* www .ja va 2s.co m*/ }
From source file:org.apache.hadoop.hive.ql.udf.UDFToString.java
public String evaluate(Byte i) { if (i == null) { return null; } else {//from www .j a v a2 s . co m return i.toString(); } }
From source file:com.couchbase.sqoop.mapreduce.db.CouchbaseRecordReadSerializeTest.java
@Before @Override/*ww w . j a v a 2 s.c o m*/ public void setUp() throws Exception { super.setUp(); tappedStuff = new HashMap<String, ResponseMessage>(); URI uri = new URI(CouchbaseUtils.CONNECT_STRING); String user = CouchbaseUtils.COUCHBASE_USER_NAME; String pass = CouchbaseUtils.COUCHBASE_USER_PASS; try { cb = new CouchbaseClient(Arrays.asList(uri), user, pass); } catch (IOException e) { LOG.error("Couldn't connect to server" + e.getMessage()); fail(e.toString()); } this.client = new TapClient(Arrays.asList(uri), user, pass); cb.flush(); Thread.sleep(500); // set up the items we're going to deserialize Integer anint = new Integer(Integer.MIN_VALUE); cb.set(anint.toString(), 0x300, anint).get(); Long along = new Long(Long.MAX_VALUE); cb.set(along.toString(), 0, along).get(); Float afloat = new Float(Float.MAX_VALUE); cb.set(afloat.toString(), 0, afloat).get(); Double doubleBase = new Double(Double.NEGATIVE_INFINITY); cb.set(doubleBase.toString(), 0, doubleBase).get(); Boolean booleanBase = true; cb.set(booleanBase.toString(), 0, booleanBase).get(); rightnow = new Date(); // instance, needed later dateText = rightnow.toString().replaceAll(" ", "_"); cb.set(dateText, 0, rightnow).get(); Byte byteMeSix = new Byte("6"); cb.set(byteMeSix.toString(), 0, byteMeSix).get(); String ourString = "hi,there"; cb.set(ourString.toString(), 0, ourString).get(); client.tapDump("tester"); while (client.hasMoreMessages()) { ResponseMessage m = client.getNextMessage(); if (m == null) { continue; } tappedStuff.put(m.getKey(), m); } }
From source file:uk.ac.ebi.mdk.service.loader.writer.DefaultCrossReferenceIndexWriter.java
public Byte newIdentifierDocument(Class c) throws IOException { Byte id = ticker.byteValue(); map.put(c, id);//w w w .j a v a2 s .c o m ticker.increment(); Document document = new Document(); document.add(create(CLASS_NAME, c.getName(), Field.Store.YES, Field.Index.NOT_ANALYZED)); document.add(create(CLASS_ID, id.toString(), Field.Store.YES, Field.Index.NOT_ANALYZED)); add(document); return id; }
From source file:com.ebay.erl.mobius.core.mapred.MobiusInputSampler.java
@Override public Object[] getSample(InputFormat inf, JobConf job) throws IOException { // the following codes are copied from {@link InputSampler#RandomSampler}, // but require some modifications. InputSplit[] splits = inf.getSplits(job, job.getNumMapTasks()); ArrayList<DataJoinKey> samples = new ArrayList<DataJoinKey>(this.numSamples); int splitsToSample = Math.min(this.maxSplitsSampled, splits.length); Random r = new Random(); long seed = r.nextLong(); r.setSeed(seed);/*ww w .ja v a 2s. c om*/ // get Sorters Sorter[] sorters = null; if (job.get(ConfigureConstants.SORTERS, null) != null) { // total sort job sorters = (Sorter[]) SerializableUtil.deserializeFromBase64(job.get(ConfigureConstants.SORTERS), job); } else { // there is no sorter, should be reducer/join job Column[] keys = (Column[]) SerializableUtil .deserializeFromBase64(job.get(ConfigureConstants.ALL_GROUP_KEY_COLUMNS), job); sorters = new Sorter[keys.length]; for (int i = 0; i < keys.length; i++) { sorters[i] = new Sorter(keys[i].getInputColumnName(), Ordering.ASC); } } long proportion = 10L; while ((int) (this.freq * proportion) == 0) { proportion = proportion * 10; } proportion = 5L * proportion; // shuffle splits for (int i = 0; i < splits.length; ++i) { InputSplit tmp = splits[i]; int j = r.nextInt(splits.length); splits[i] = splits[j]; splits[j] = tmp; } SamplingOutputCollector collector = new SamplingOutputCollector(); for (int i = 0; i < splitsToSample || (i < splits.length && samples.size() < numSamples); i++) { LOGGER.info("Sampling from split #" + (i + 1) + ", collected samples:" + samples.size()); RecordReader<WritableComparable, WritableComparable> reader = inf.getRecordReader(splits[i], job, Reporter.NULL); WritableComparable key = reader.createKey(); WritableComparable value = reader.createValue(); if (!(inf instanceof MobiusDelegatingInputFormat)) { // not mobius delegating input format, so the CURRENT_DATASET_ID // will not be set by inf#getRecordReader, we set them here. // // set the current dataset id, as the AbstractMobiusMapper#configure // method needs this property. job.set(ConfigureConstants.CURRENT_DATASET_ID, job.get(ConfigureConstants.ALL_DATASET_IDS)); } Byte datasetID = Byte.valueOf(job.get(ConfigureConstants.CURRENT_DATASET_ID)); LOGGER.info("Samples coming from dataset: " + datasetID.toString()); AbstractMobiusMapper mapper = this.getMapper(inf, splits[i], job); mapper.configure(job); // reading elements from one split long readElement = 0; while (reader.next(key, value)) { collector.clear(); Tuple tuple = mapper.parse(key, value); readElement++; if (readElement > (((long) numSamples) * ((long) proportion))) { // a split might be very big (ex: a large gz file), // so we just need to read the break; } if (r.nextDouble() <= freq) { if (samples.size() < numSamples) { mapper.joinmap(key, value, collector, Reporter.NULL); // joinmap function might generate more than one output key // per <code>key</code> input. for (Tuple t : collector.getOutKey()) { Tuple mt = Tuple.merge(tuple, t); DataJoinKey nkey = this.getKey(mt, sorters, datasetID, mapper, job); samples.add(nkey); } } else { // When exceeding the maximum number of samples, replace // a random element with this one, then adjust the // frequency to reflect the possibility of existing // elements being pushed out mapper.joinmap(key, value, collector, Reporter.NULL); for (Tuple t : collector.getOutKey()) { int ind = r.nextInt(numSamples); if (ind != numSamples) { Tuple mt = Tuple.merge(tuple, t); DataJoinKey nkey = this.getKey(mt, sorters, datasetID, mapper, job); samples.set(ind, nkey); } } freq *= (numSamples - collector.getOutKey().size()) / (double) numSamples; } key = reader.createKey(); value = reader.createValue(); } } reader.close(); } LOGGER.info("Samples have been collected, return."); return samples.toArray(); }
From source file:org.vertx.java.http.eventbusbridge.integration.MessageSendTest.java
@Test public void testSendingByteJson() throws IOException { final EventBusMessageType messageType = EventBusMessageType.Byte; final Byte sentByte = Byte.MAX_VALUE; Map<String, String> expectations = createExpectations("someaddress", Base64.encodeAsString(sentByte.toString()), messageType); Handler<Message> messageConsumerHandler = new MessageSendHandler(sentByte, expectations); vertx.eventBus().registerHandler(expectations.get("address"), messageConsumerHandler); String body = TemplateHelper.generateOutputUsingTemplate(SEND_REQUEST_TEMPLATE_JSON, expectations); HttpRequestHelper.sendHttpPostRequest(url, body, (VertxInternal) vertx, Status.ACCEPTED.getStatusCode(), MediaType.APPLICATION_JSON); }