List of usage examples for java.lang Byte parseByte
public static byte parseByte(String s, int radix) throws NumberFormatException
From source file:fr.landel.utils.commons.NumberUtilsParsers.java
/** * Parse a string into a byte. (Null safe and number safe). * /*from w w w . jav a2 s . c om*/ * @param string * The input * @param defaultValue * If the input cannot be parse, value is returned * @param radix * The radix to be used while parsing the string * @param noThrow * true, to avoid throwing a {@link NumberFormatException} if * parse failed * @return The parsed result * @throws NumberFormatException * if the number cannot be parsed and {@code noThrow} is * {@code false} */ public static Byte parseByte(final String string, final Byte defaultValue, final int radix, final boolean noThrow) { return parse(string, defaultValue, s -> Byte.parseByte(s, radix), noThrow); }
From source file:se.inera.axel.shs.broker.validation.certificate.CertificateExtractorImpl.java
private String convertFromHexToString(String hexString) { byte[] txtInByte = new byte[hexString.length() / 2]; int j = 0;//w w w .ja va2s .c o m for (int i = 0; i < hexString.length(); i += 2) { txtInByte[j++] = Byte.parseByte(hexString.substring(i, i + 2), 16); } return new String(txtInByte); }
From source file:com.liferay.lms.servlet.SCORMFileServerServlet.java
private String hexStringToStringByAscii(String hexString) { byte[] bytes = new byte[hexString.length() / 2]; for (int i = 0; i < hexString.length() / 2; i++) { String oneHexa = hexString.substring(i * 2, i * 2 + 2); bytes[i] = Byte.parseByte(oneHexa, 16); }//from w w w . j a v a 2 s . com try { return new String(bytes, "ASCII"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:de.arago.portlet.util.UserContainer.java
private static String hexStringToStringByAscii(String hexString) { byte[] bytes = new byte[hexString.length() / 2]; for (int i = 0; i < hexString.length() / 2; i++) { String oneHexa = hexString.substring(i * 2, i * 2 + 2); bytes[i] = Byte.parseByte(oneHexa, 16); }/*www. j a v a 2s. c om*/ try { return new String(bytes, "ASCII"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:org.apache.xml.security.utils.RFC2253Parser.java
/** * Method changeLess32toRFC/*from w ww. j a v a2s . co m*/ * * @param string * @return normalized string * @throws IOException */ static String changeLess32toRFC(String string) throws IOException { StringBuffer sb = new StringBuffer(); StringReader sr = new StringReader(string); int i = 0; char c; for (; (i = sr.read()) > -1;) { c = (char) i; if (c == '\\') { sb.append(c); char c1 = (char) sr.read(); char c2 = (char) sr.read(); //65 (A) 97 (a) if ((((c1 >= 48) && (c1 <= 57)) || ((c1 >= 65) && (c1 <= 70)) || ((c1 >= 97) && (c1 <= 102))) && (((c2 >= 48) && (c2 <= 57)) || ((c2 >= 65) && (c2 <= 70)) || ((c2 >= 97) && (c2 <= 102)))) { char ch = (char) Byte.parseByte("" + c1 + c2, 16); sb.append(ch); } else { sb.append(c1); sb.append(c2); } } else { sb.append(c); } } return sb.toString(); }
From source file:org.rifidi.emulator.reader.awid.commandhandler.AwidAutonomous.java
private static byte[] calculateProtocolArray(String header, String protocol, byte[] tagData) { byte[] retVal = new byte[tagData.length + 2]; retVal[0] = Byte.parseByte(header, 16); retVal[1] = Byte.parseByte(protocol, 16); for (int i = 2; i < (tagData.length + 2); i++) { retVal[i] = tagData[i - 2];/* w w w . j a v a2 s . c o m*/ } return retVal; }
From source file:edu.hawaii.soest.pacioos.text.SimpleTextSource.java
/** * Constructor: create an instance of the simple SimpleTextSource * @param xmlConfig //from w w w. j av a 2 s. c o m */ public SimpleTextSource(XMLConfiguration xmlConfig) throws ConfigurationException { this.xmlConfig = xmlConfig; // Pull the general configuration from the properties file Configuration config = new PropertiesConfiguration("textsource.properties"); this.archiveMode = config.getString("textsource.archive_mode"); this.rbnbChannelName = config.getString("textsource.rbnb_channel"); this.serverName = config.getString("textsource.server_name "); this.delimiter = config.getString("textsource.delimiter"); this.pollInterval = config.getInt("textsource.poll_interval"); this.retryInterval = config.getInt("textsource.retry_interval"); this.defaultDateFormat = new SimpleDateFormat(config.getString("textsource.default_date_format")); // parse the record delimiter from the config file // set the XML configuration in the simple text source for later use this.setConfiguration(xmlConfig); // set the common configuration fields String connectionType = this.xmlConfig.getString("connectionType"); this.setConnectionType(connectionType); String channelName = xmlConfig.getString("channelName"); this.setChannelName(channelName); String identifier = xmlConfig.getString("identifier"); this.setIdentifier(identifier); String rbnbName = xmlConfig.getString("rbnbName"); this.setRBNBClientName(rbnbName); String rbnbServer = xmlConfig.getString("rbnbServer"); this.setServerName(rbnbServer); int rbnbPort = xmlConfig.getInt("rbnbPort"); this.setServerPort(rbnbPort); int archiveMemory = xmlConfig.getInt("archiveMemory"); this.setCacheSize(archiveMemory); int archiveSize = xmlConfig.getInt("archiveSize"); this.setArchiveSize(archiveSize); // set the default channel information Object channels = xmlConfig.getList("channels.channel.name"); int totalChannels = 1; if (channels instanceof Collection) { totalChannels = ((Collection<?>) channels).size(); } // find the default channel with the ASCII data string for (int i = 0; i < totalChannels; i++) { boolean isDefaultChannel = xmlConfig.getBoolean("channels.channel(" + i + ")[@default]"); if (isDefaultChannel) { String name = xmlConfig.getString("channels.channel(" + i + ").name"); this.setChannelName(name); String dataPattern = xmlConfig.getString("channels.channel(" + i + ").dataPattern"); this.setPattern(dataPattern); String fieldDelimiter = xmlConfig.getString("channels.channel(" + i + ").fieldDelimiter"); // handle hex-encoded field delimiters if (fieldDelimiter.startsWith("0x") || fieldDelimiter.startsWith("\\x")) { Byte delimBytes = Byte.parseByte(fieldDelimiter.substring(2), 16); byte[] delimAsByteArray = new byte[] { delimBytes.byteValue() }; String delim = null; try { delim = new String(delimAsByteArray, 0, delimAsByteArray.length, "ASCII"); } catch (UnsupportedEncodingException e) { throw new ConfigurationException("There was an error parsing the field delimiter." + " The message was: " + e.getMessage()); } this.setDelimiter(delim); } else { this.setDelimiter(fieldDelimiter); } String[] recordDelimiters = xmlConfig .getStringArray("channels.channel(" + i + ").recordDelimiters"); this.setRecordDelimiters(recordDelimiters); // set the date formats list List<String> dateFormats = (List<String>) xmlConfig .getList("channels.channel(" + i + ").dateFormats.dateFormat"); if (dateFormats.size() != 0) { for (String dateFormat : dateFormats) { // validate the date format string try { SimpleDateFormat format = new SimpleDateFormat(dateFormat); } catch (IllegalFormatException ife) { String msg = "There was an error parsing the date format " + dateFormat + ". The message was: " + ife.getMessage(); if (log.isDebugEnabled()) { ife.printStackTrace(); } throw new ConfigurationException(msg); } } setDateFormats(dateFormats); } else { log.warn("No date formats have been configured for this instrument."); } // set the date fields list List<String> dateFieldList = xmlConfig.getList("channels.channel(" + i + ").dateFields.dateField"); List<Integer> dateFields = new ArrayList<Integer>(); if (dateFieldList.size() != 0) { for (String dateField : dateFieldList) { try { Integer newDateField = new Integer(dateField); dateFields.add(newDateField); } catch (NumberFormatException e) { String msg = "There was an error parsing the dateFields. The message was: " + e.getMessage(); throw new ConfigurationException(msg); } } setDateFields(dateFields); } else { log.warn("No date fields have been configured for this instrument."); } String timeZone = xmlConfig.getString("channels.channel(" + i + ").timeZone"); this.setTimezone(timeZone); break; } } // Check the record delimiters length and set the first and optionally second delim characters if (this.recordDelimiters.length == 1) { this.firstDelimiterByte = (byte) Integer.decode(this.recordDelimiters[0]).byteValue(); } else if (this.recordDelimiters.length == 2) { this.firstDelimiterByte = (byte) Integer.decode(this.recordDelimiters[0]).byteValue(); this.secondDelimiterByte = (byte) Integer.decode(this.recordDelimiters[1]).byteValue(); } else { throw new ConfigurationException("The recordDelimiter must be one or two characters, " + "separated by a pipe symbol (|) if there is more than one delimiter character."); } byte[] delimiters = new byte[] {}; }
From source file:org.apache.james.repository.file.AbstractFileRepository.java
/** * Inverse of encode exept it do not use path. So decode(encode(s) - m_path) * = s. In other words it returns a String that can be used as key to * retrieve the record contained in the 'filename' file. * /*from w ww . j a v a2 s . c o m*/ * @param filename * the filename for which the key should generated * @return key a String which can be used to retrieve the filename */ protected String decode(String filename) { filename = filename.substring(0, filename.length() - m_extension.length()); final int size = filename.length(); final byte[] bytes = new byte[size >>> 1]; for (int i = 0, j = 0; i < size; j++) { bytes[j] = Byte.parseByte(filename.substring(i, i + 2), 16); i += 2; } return new String(bytes); }
From source file:org.shirdrn.tinyframework.core.conf.Context.java
public byte getByte(String name, byte defaultValue) { String valueString = get(name); if (valueString == null) return defaultValue; try {//from ww w . j av a 2s . c om String hexString = getHexDigits(valueString); if (hexString != null) { return Byte.parseByte(hexString, 16); } return Byte.parseByte(valueString); } catch (NumberFormatException e) { return defaultValue; } }
From source file:org.firstopen.singularity.devicemgr.interrogator.WaveTrend_IO.java
protected byte[] toBinArray(String hexStr) { byte bArray[] = new byte[hexStr.length() / 2]; for (int i = 0; i < bArray.length; i++) { bArray[i] = Byte.parseByte(hexStr.substring(2 * i, 2 * i + 2), 16); }//from w w w . j a va2s.c om return bArray; }