List of usage examples for java.lang Byte toString
public static String toString(byte b)
From source file:com.tesora.dve.mysqlapi.repl.messages.MyUserVarLogEvent.java
String processIntValue(ByteBuf cb, int valueLen) throws PEException { String value = StringUtils.EMPTY; switch (valueLen) { case 8://from w ww . j a va 2 s . c o m value = Long.toString(cb.readLong()); break; case 7: case 6: case 5: throw new PEException( "Cannot decode INT value of length '" + valueLen + "' for variable '" + variableName + "'"); case 4: value = Long.toString(cb.readInt()); break; case 3: value = Long.toString(cb.readMedium()); break; case 2: value = Long.toString(cb.readShort()); break; case 1: value = Byte.toString(cb.readByte()); break; } return value; }
From source file:org.hyperic.hq.ui.taglib.ConstantsTag.java
public int doEndTag() throws JspException { try {/*from w w w.j av a 2s .c o m*/ JspWriter out = pageContext.getOut(); if (className == null) { className = pageContext.getServletContext().getInitParameter(constantsClassNameParam); } if (validate(out)) { // we're misconfigured. getting this far // is a matter of what our failure mode is // if we haven't thrown an Error, carry on log.debug("constants tag misconfigured"); return EVAL_PAGE; } HashMap fieldMap; if (constants.containsKey(className)) { // we cache the result of the constants class // reflection field walk as a map fieldMap = (HashMap) constants.get(className); } else { fieldMap = new HashMap(); Class typeClass = Class.forName(className); //Object con = typeClass.newInstance(); Field[] fields = typeClass.getFields(); for (int i = 0; i < fields.length; i++) { // string comparisons of class names should be cheaper // than reflective Class comparisons, the asumption here // is that most constants are Strings, ints and booleans // but a minimal effort is made to accomadate all types // and represent them as String's for our tag's output //BIG NEW ASSUMPTION: Constants are statics and do not require instantiation of the class if (Modifier.isStatic(fields[i].getModifiers())) { String fieldType = fields[i].getType().getName(); String strVal; if (fieldType.equals("java.lang.String")) { strVal = (String) fields[i].get(null); } else if (fieldType.equals("int")) { strVal = Integer.toString(fields[i].getInt(null)); } else if (fieldType.equals("boolean")) { strVal = Boolean.toString(fields[i].getBoolean(null)); } else if (fieldType.equals("char")) { strVal = Character.toString(fields[i].getChar(null)); } else if (fieldType.equals("double")) { strVal = Double.toString(fields[i].getDouble(null)); } else if (fieldType.equals("float")) { strVal = Float.toString(fields[i].getFloat(null)); } else if (fieldType.equals("long")) { strVal = Long.toString(fields[i].getLong(null)); } else if (fieldType.equals("short")) { strVal = Short.toString(fields[i].getShort(null)); } else if (fieldType.equals("byte")) { strVal = Byte.toString(fields[i].getByte(null)); } else { Object val = (Object) fields[i].get(null); strVal = val.toString(); } fieldMap.put(fields[i].getName(), strVal); } } // cache the result constants.put(className, fieldMap); } if (symbol != null && !fieldMap.containsKey(symbol)) { // tell the developer that he's being a dummy and what // might be done to remedy the situation // TODO: what happens if the constants change? // do we need to throw a JspException, here? String err1 = symbol + " was not found in " + className + "\n"; String err2 = err1 + "use <constants:diag classname=\"" + className + "\"/>\n" + "to figure out what you're looking for"; log.error(err2); die(out, err1); } if (varSpecified) { doSet(fieldMap); } else { doOutput(fieldMap, out); } } catch (JspException e) { throw e; } catch (Exception e) { log.debug("doEndTag() failed: ", e); throw new JspException("Could not access constants tag", e); } return EVAL_PAGE; }
From source file:org.rhq.enterprise.gui.legacy.taglib.ConstantsTag.java
public int doEndTag() throws JspException { try {/*from w ww.j a va 2 s . c om*/ JspWriter out = pageContext.getOut(); if (className == null) { className = pageContext.getServletContext().getInitParameter(constantsClassNameParam); } if (validate(out)) { // we're misconfigured. getting this far // is a matter of what our failure mode is; // if we haven't thrown an Error, carry on log.debug("constants tag misconfigured"); return EVAL_PAGE; } Map<String, String> fieldMap; if (constants.containsKey(className)) { // we cache the result of the constant's class // reflection field walk as a map fieldMap = (Map<String, String>) constants.get(className); } else { fieldMap = new HashMap<String, String>(); Class typeClass = Class.forName(className); if (typeClass.isEnum()) { for (Object enumConstantObj : typeClass.getEnumConstants()) { Enum enumConstant = (Enum) enumConstantObj; // Set name *and* value to enum name (e.g. name of ResourceCategory.PLATFORM = "PLATFORM") // NOTE: We do not set the value to enumConstant.ordinal(), because there is no way to // convert the ordinal value back to an Enum (i.e. no Enum.valueOf(int ordinal) method). fieldMap.put(enumConstant.name(), enumConstant.name()); } } else { Object instance = typeClass.newInstance(); Field[] fields = typeClass.getFields(); for (Field field : fields) { // string comparisons of class names should be cheaper // than reflective Class comparisons, the asumption here // is that most constants are Strings, ints and booleans // but a minimal effort is made to accomadate all types // and represent them as String's for our tag's output String fieldType = field.getType().getName(); String strVal; if (fieldType.equals("java.lang.String")) { strVal = (String) field.get(instance); } else if (fieldType.equals("int")) { strVal = Integer.toString(field.getInt(instance)); } else if (fieldType.equals("boolean")) { strVal = Boolean.toString(field.getBoolean(instance)); } else if (fieldType.equals("char")) { strVal = Character.toString(field.getChar(instance)); } else if (fieldType.equals("double")) { strVal = Double.toString(field.getDouble(instance)); } else if (fieldType.equals("float")) { strVal = Float.toString(field.getFloat(instance)); } else if (fieldType.equals("long")) { strVal = Long.toString(field.getLong(instance)); } else if (fieldType.equals("short")) { strVal = Short.toString(field.getShort(instance)); } else if (fieldType.equals("byte")) { strVal = Byte.toString(field.getByte(instance)); } else { strVal = field.get(instance).toString(); } fieldMap.put(field.getName(), strVal); } } // cache the result constants.put(className, fieldMap); } if ((symbol != null) && !fieldMap.containsKey(symbol)) { // tell the developer that he's being a dummy and what // might be done to remedy the situation // TODO: what happens if the constants change? // do we need to throw a JspException, here? - mtk String err1 = symbol + " was not found in " + className + "\n"; String err2 = err1 + "use <constants:diag classname=\"" + className + "\"/>\n" + "to figure out what you're looking for"; log.error(err2); die(out, err1); } if (varSpecified) { doSet(fieldMap); } else { doOutput(fieldMap, out); } } catch (JspException e) { throw e; } catch (Exception e) { log.debug("doEndTag() failed: ", e); throw new JspException("Could not access constants tag", e); } return EVAL_PAGE; }
From source file:org.ethereum.rpc.Web3Impl.java
public String net_version() { String s = null;/* w ww.ja v a2 s . c om*/ try { byte netVersion = RskSystemProperties.RSKCONFIG.getBlockchainConfig().getCommonConstants().getChainId(); return s = Byte.toString(netVersion); } finally { if (logger.isDebugEnabled()) logger.debug("net_version(): " + s); } }
From source file:org.hobbit.core.components.AbstractEvaluationStorage.java
@Override public void init() throws Exception { super.init(); String queueName = EnvVariables.getString(Constants.TASK_GEN_2_EVAL_STORAGE_QUEUE_NAME_KEY, Constants.TASK_GEN_2_EVAL_STORAGE_DEFAULT_QUEUE_NAME); taskResultReceiver = DataReceiverImpl.builder().maxParallelProcessedMsgs(maxParallelProcessedMsgs) .queue(incomingDataQueueFactory, generateSessionQueueName(queueName)) .dataHandler(new DataHandler() { @Override//from w w w .j a v a 2 s. co m public void handleData(byte[] data) { ByteBuffer buffer = ByteBuffer.wrap(data); String taskId = RabbitMQUtils.readString(buffer); LOGGER.trace("Received from task generator {}.", taskId); byte[] taskData = RabbitMQUtils.readByteArray(buffer); long timestamp = buffer.getLong(); receiveExpectedResponseData(taskId, timestamp, taskData); } }).build(); queueName = EnvVariables.getString(Constants.SYSTEM_2_EVAL_STORAGE_QUEUE_NAME_KEY, Constants.SYSTEM_2_EVAL_STORAGE_DEFAULT_QUEUE_NAME); final boolean receiveTimeStamp = EnvVariables.getBoolean(RECEIVE_TIMESTAMP_FOR_SYSTEM_RESULTS_KEY, false, LOGGER); final String ackExchangeName = generateSessionQueueName(Constants.HOBBIT_ACK_EXCHANGE_NAME); systemResultReceiver = DataReceiverImpl.builder().maxParallelProcessedMsgs(maxParallelProcessedMsgs) .queue(incomingDataQueueFactory, generateSessionQueueName(queueName)) .dataHandler(new DataHandler() { @Override public void handleData(byte[] data) { ByteBuffer buffer = ByteBuffer.wrap(data); String taskId = RabbitMQUtils.readString(buffer); LOGGER.trace("Received from system {}.", taskId); byte[] responseData = RabbitMQUtils.readByteArray(buffer); long timestamp = receiveTimeStamp ? buffer.getLong() : System.currentTimeMillis(); receiveResponseData(taskId, timestamp, responseData); // If we should send acknowledgments (and there was no // error until now) if (ackChannel != null) { try { ackChannel.basicPublish(ackExchangeName, "", null, RabbitMQUtils.writeString(taskId)); } catch (IOException e) { LOGGER.error("Error while sending acknowledgement.", e); } LOGGER.trace("Sent ack {}.", taskId); } } }).build(); queueName = EnvVariables.getString(Constants.EVAL_MODULE_2_EVAL_STORAGE_QUEUE_NAME_KEY, Constants.EVAL_MODULE_2_EVAL_STORAGE_DEFAULT_QUEUE_NAME); evalModule2EvalStoreQueue = getFactoryForIncomingDataQueues() .createDefaultRabbitQueue(generateSessionQueueName(queueName)); evalModule2EvalStoreQueue.channel.basicConsume(evalModule2EvalStoreQueue.name, true, new DefaultConsumer(evalModule2EvalStoreQueue.channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException { byte response[] = null; // get iterator id ByteBuffer buffer = ByteBuffer.wrap(body); if (buffer.remaining() < 1) { response = EMPTY_RESPONSE; LOGGER.error("Got a request without a valid iterator Id. Returning emtpy response."); } else { byte iteratorId = buffer.get(); // get the iterator Iterator<? extends ResultPair> iterator = null; if (iteratorId == NEW_ITERATOR_ID) { // create and save a new iterator iteratorId = (byte) resultPairIterators.size(); LOGGER.info("Creating new iterator #{}", iteratorId); resultPairIterators.add(iterator = createIterator()); } else if ((iteratorId < 0) || iteratorId >= resultPairIterators.size()) { response = EMPTY_RESPONSE; LOGGER.error("Got a request without a valid iterator Id (" + Byte.toString(iteratorId) + "). Returning emtpy response."); } else { iterator = resultPairIterators.get(iteratorId); } if ((iterator != null) && (iterator.hasNext())) { ResultPair resultPair = iterator.next(); Result result = resultPair.getExpected(); byte expectedResultData[], expectedResultTimeStamp[], actualResultData[], actualResultTimeStamp[]; // Make sure that the result is not null if (result != null) { // Check whether the data array is null expectedResultData = result.getData() != null ? result.getData() : new byte[0]; expectedResultTimeStamp = RabbitMQUtils.writeLong(result.getSentTimestamp()); } else { expectedResultData = new byte[0]; expectedResultTimeStamp = RabbitMQUtils.writeLong(0); } result = resultPair.getActual(); // Make sure that the result is not null if (result != null) { // Check whether the data array is null actualResultData = result.getData() != null ? result.getData() : new byte[0]; actualResultTimeStamp = RabbitMQUtils.writeLong(result.getSentTimestamp()); } else { actualResultData = new byte[0]; actualResultTimeStamp = RabbitMQUtils.writeLong(0); } response = RabbitMQUtils.writeByteArrays( new byte[] { iteratorId }, new byte[][] { expectedResultTimeStamp, expectedResultData, actualResultTimeStamp, actualResultData }, null); } else { response = new byte[] { iteratorId }; } } getChannel().basicPublish("", properties.getReplyTo(), null, response); } }); boolean sendAcks = EnvVariables.getBoolean(Constants.ACKNOWLEDGEMENT_FLAG_KEY, false, LOGGER); if (sendAcks) { // Create channel for acknowledgements ackChannel = getFactoryForOutgoingCmdQueues().getConnection().createChannel(); ackChannel.exchangeDeclare(generateSessionQueueName(Constants.HOBBIT_ACK_EXCHANGE_NAME), "fanout", false, true, null); } }
From source file:org.apache.ojb.broker.util.pooling.PoolConfiguration.java
public void setWhenExhaustedAction(byte whenExhaustedAction) { this.setProperty(WHEN_EXHAUSTED_ACTION, Byte.toString(whenExhaustedAction)); }
From source file:com.ziaconsulting.zoho.EditorController.java
private String generateDocumentId(String base) { byte messageDigest[] = {}; try {// ww w . j av a2 s.c o m MessageDigest algorithm = MessageDigest.getInstance("MD5"); algorithm.reset(); algorithm.update(base.getBytes()); messageDigest = algorithm.digest(); } catch (NoSuchAlgorithmException nsae) { } String md5DocId; StringBuffer md5DocIdBuffer = new StringBuffer(); for (byte msg : messageDigest) { md5DocIdBuffer.append(Byte.toString(msg)); } // Changed this to invalidate the current documents // Id needs to be only integers, < 19 characters long md5DocId = "6" + md5DocIdBuffer.toString().replace("-", "").substring(0, 17); return md5DocId; }
From source file:org.fudgemsg.xml.FudgeXMLStreamWriter.java
protected void writeArray(final byte[] array) throws XMLStreamException { boolean first = true; for (byte value : array) { if (first) first = false;/* w w w . j a v a2 s . c om*/ else getWriter().writeCharacters(","); getWriter().writeCharacters(Byte.toString(value)); } }
From source file:pltag.corpus.StringTree.java
protected String printOriginUpChar(int nid) { byte index = indexUp[nid]; if (index != -1) return index < 10 ? String.valueOf((char) ('0' + index)) : Byte.toString(indexUp[nid]); if (containsOriginNode(nid, originUp)) { return "x"; }// w w w.ja v a 2s . com return "null"; }
From source file:paulscode.android.mupen64plusae.task.CacheRomInfoService.java
private void cacheFile(File file, RomDatabase database, ConfigFile config, File zipFileLocation) { if (mbStopped) return;/*from w w w .jav a 2 s . c om*/ mListener.GetProgressDialog().setMessage(R.string.cacheRomInfo_computingMD5); String md5 = ComputeMd5Task.computeMd5(file); RomHeader header = new RomHeader(file); if (mbStopped) return; mListener.GetProgressDialog().setMessage(R.string.cacheRomInfo_searchingDB); RomDetail detail = database.lookupByMd5WithFallback(md5, file, header.crc); String artPath = mArtDir + "/" + detail.artName; config.put(md5, "goodName", detail.goodName); if (detail.baseName != null && detail.baseName.length() != 0) config.put(md5, "baseName", detail.baseName); config.put(md5, "romPath", file.getAbsolutePath()); config.put(md5, "zipPath", zipFileLocation == null ? "" : zipFileLocation.getAbsolutePath()); config.put(md5, "artPath", artPath); config.put(md5, "crc", header.crc); config.put(md5, "headerName", header.name); //String countryCodeString = String.format( "%02x", header.countryCode ).substring( 0, 2 ); String countryCodeString = Byte.toString(header.countryCode); config.put(md5, "countryCode", countryCodeString); config.put(md5, "extracted", "false"); if (mDownloadArt) { if (mbStopped) return; mListener.GetProgressDialog().setMessage(R.string.cacheRomInfo_downloadingArt); Log.i("CacheRomInfoService", "Start art download: " + artPath); downloadFile(detail.artUrl, artPath); Log.i("CacheRomInfoService", "End art download: " + artPath); } if (mbStopped) return; mListener.GetProgressDialog().setMessage(R.string.cacheRomInfo_refreshingUI); }