List of usage examples for java.lang Byte parseByte
public static byte parseByte(String s) throws NumberFormatException
From source file:org.blockedit.core.world.WorldVersion.java
/** * Create the WorldVersion from a {@link String}. * * @param s The string that holds the version * @return Returns a new instance of {@link WorldVersion} * @throws ParseException If the string is not a correct version * @throws NumberFormatException If the program was unable to parse the string to a {@link Byte} *///from w w w .j av a 2 s . co m public static WorldVersion fromString(String s) throws ParseException, NumberFormatException { Matcher snapshotMatcher = Pattern.compile("^[0-9]{1,2}[a-z][0-9]{1,2}[a-z]$").matcher(s); Matcher versionMatcher = Pattern.compile("^[1].[0-9].([0-9]{1,2})$").matcher(s); Matcher preMatcher = Pattern.compile("^[1].[0-9].([0-9]{1,2})-(pre[0-9]{1}|pre)$").matcher(s); Matcher rcMatcher = Pattern.compile("^1.0.0-RC[1-2]$").matcher(s); if (rcMatcher.matches()) { throw new ParseException("Version " + s + " is obsolete and no longer supported!"); } if (snapshotMatcher.matches()) { return new WorldVersion(s); } if (versionMatcher.matches() && preMatcher.matches()) { String[] values = StringUtils.split(s, '.'); byte version = Byte.parseByte(values[0]); byte subVersion = Byte.parseByte(values[1]); byte release = Byte.parseByte(values[2]); return new WorldVersion(version, subVersion, release); } else { throw new ParseException("Invaild Format: " + s); } }
From source file:org.jcurl.core.io.OldConfigReader.java
private static boolean parseRock(final OldConfigReader ret, final Reader in) throws IOException { String tok = readToken(in);//from w ww .j av a2 s . com if (tok == null) return false; if (!"ROCK".equals(tok)) throw new IllegalStateException("Invalid token: [" + tok + "]"); final boolean isDark; { tok = readToken(in); if ("light".equals(tok)) isDark = false; else if ("dark".equals(tok)) isDark = true; else throw new IllegalStateException("Invalid token: [" + tok + "]"); } final int no = Byte.parseByte(readToken(in)) - 1; for (;;) { tok = readToken(in); if ("from".equals(tok)) { tok = readToken(in); if ("OUT".equals(tok)) ret.setOut(ret, isDark, no); else if ("RELEASE".equals(tok)) ret.setRelease(ret, isDark, no); else ret.setFrom(ret, isDark, no, tok, readToken(in)); } else if ("to".equals(tok)) { tok = readToken(in); if ("OUT".equals(tok)) ret.setOut(ret, isDark, no); else ret.setTo(ret, isDark, no, tok, readToken(in)); } else if ("speed".equals(tok)) ret.setSpeed(ret, isDark, no, readToken(in)); else if ("and".equals(tok)) ; else if ("with".equals(tok)) ; else if ("spin".equals(tok)) ret.setSpin(ret, isDark, no, readToken(in)); else if ("angle".equals(tok)) ret.setAngle(isDark, no, readToken(in)); else if ("DONE".equals(tok)) return true; else throw new IllegalStateException("Invalid token: [" + tok + "]"); } }
From source file:ca.watier.echechess.services.GameMessageHandlerService.java
/** * Message pattern: {@link UUID#toString()}|{@link CasePosition from}|{@link CasePosition to}|{@link MoveType#getValue()}|{@link Side#getValue()()} * * @param messageAsString/* w w w . j av a 2s . c o m*/ */ private void handleReceivedMoveMessage(String messageAsString) { String[] messages = messageAsString.split("\\|"); String uuid = messages[0]; CasePosition from = CasePosition.valueOf(messages[1]); CasePosition to = CasePosition.valueOf(messages[2]); MoveType moveType = MoveType.getFromValue(Byte.parseByte(messages[3])); Side playerSide = Side.getFromValue(Byte.parseByte(messages[4])); GenericGameHandlerWrapper<GenericGameHandler> handlerWrapper = gameRepository.get(uuid); GenericGameHandler gameFromUuid = handlerWrapper.getGenericGameHandler(); if (MoveType.isMoved(moveType)) { KingStatus currentKingStatus = gameFromUuid.getEvaluatedKingStatusBySide(playerSide); KingStatus otherKingStatus = gameFromUuid .getEvaluatedKingStatusBySide(Side.getOtherPlayerSide(playerSide)); sendMovedPieceMessage(from, to, uuid, gameFromUuid, playerSide); sendCheckOrCheckmateMessages(currentKingStatus, otherKingStatus, playerSide, uuid); } }
From source file:de.weltraumschaf.registermachine.asm.LineParser.java
private static byte parseToByte(final Token t) { return Byte.parseByte(t.getValue()); }
From source file:org.duracloud.common.util.EncryptionUtil.java
/** * Decodes a String back into a byte array. *//*from w w w. j a v a2 s . c o m*/ private byte[] decodeBytes(String cipherString) { String[] cipherStringBytes = cipherString.split(":"); byte[] cipherBytes = new byte[cipherStringBytes.length]; for (int i = 0; i < cipherStringBytes.length; i++) { cipherBytes[i] = Byte.parseByte(cipherStringBytes[i]); } return cipherBytes; }
From source file:com.l2jfree.gameserver.datatables.SummonItemsData.java
private SummonItemsData() { _summonitems = new FastMap<Integer, L2SummonItem>(); Document doc = null;/*ww w. j a va2 s . c om*/ File file = new File(Config.DATAPACK_ROOT, "data/summon_items.xml"); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(true); factory.setIgnoringComments(true); doc = factory.newDocumentBuilder().parse(file); int itemID = 0, npcID = 0; byte summonType = 0; Node a; for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling()) { if ("list".equalsIgnoreCase(n.getNodeName())) { for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling()) { if ("item".equalsIgnoreCase(d.getNodeName())) { a = d.getAttributes().getNamedItem("id"); if (a == null) throw new Exception("Error in summon item defenition!"); itemID = Integer.parseInt(a.getNodeValue()); for (Node e = d.getFirstChild(); e != null; e = e.getNextSibling()) { if ("npcId".equalsIgnoreCase(e.getNodeName())) { a = e.getAttributes().getNamedItem("val"); if (a == null) throw new Exception( "Not defined npc id for summon item id=" + itemID + "!"); npcID = Integer.parseInt(a.getNodeValue()); } else if ("summonType".equalsIgnoreCase(e.getNodeName())) { a = e.getAttributes().getNamedItem("val"); if (a == null) throw new Exception( "Not defined summon type for summon item id=" + itemID + "!"); summonType = Byte.parseByte(a.getNodeValue()); } } L2SummonItem summonitem = new L2SummonItem(itemID, npcID, summonType); _summonitems.put(itemID, summonitem); } } } } _summonItemIds = new int[_summonitems.size()]; int i = 0; for (int itemId : _summonitems.keySet()) _summonItemIds[i++] = itemId; } catch (IOException e) { _log.warn("SummonItemsData: Can not find " + file.getAbsolutePath() + " !", e); } catch (Exception e) { _log.warn("SummonItemsData: Error while parsing " + file.getAbsolutePath() + " !", e); } _log.info("SummonItemsData: Loaded " + _summonitems.size() + " Summon Items from " + file.getName()); }
From source file:com.itemanalysis.psychometrics.irt.estimation.ItemResponseFileSummary.java
/** * Reads a comma delimited file./*from w w w. java2 s . com*/ * * @param f file to be summarized * @param headerIncluded true if header included. False otherwise. The header will be omitted (ignored). * @return */ public ItemResponseVector[] getResponseVectors(File f, int start, int nItems, boolean headerIncluded) { String responseString = ""; String[] line = null; ArrayList<ItemResponseVector> responseData = new ArrayList<ItemResponseVector>(); int lineCount = 0; byte[] rv = null; ItemResponseVector irv = null; ItemResponseVector[] itemResponseVector = null; try (BufferedReader br = new BufferedReader(new FileReader(f))) { if (headerIncluded) br.readLine();//skip header while ((responseString = br.readLine()) != null) { line = responseString.split(","); rv = new byte[nItems]; for (int j = 0; j < nItems; j++) { rv[j] = Byte.parseByte(line[j + start]); } irv = new ItemResponseVector(rv, 1.0); responseData.add(irv); lineCount++; } itemResponseVector = new ItemResponseVector[lineCount]; for (int i = 0; i < lineCount; i++) { itemResponseVector[i] = responseData.get(i); } } catch (IOException ex) { ex.printStackTrace(); } return itemResponseVector; }
From source file:javadz.beanutils.converters.ByteArrayConverter.java
/** * Convert the specified input object into an output object of the * specified type.//from www . j a va 2 s. co m * * @param type Data type to which this value should be converted * @param value The input value to be converted * @return the converted value * @exception ConversionException if conversion cannot be performed * successfully */ public Object convert(Class type, Object value) { // Deal with a null value if (value == null) { if (useDefault) { return (defaultValue); } else { throw new ConversionException("No value specified"); } } // Deal with the no-conversion-needed case if (MODEL.getClass() == value.getClass()) { return (value); } // Deal with input value as a String array if (strings.getClass() == value.getClass()) { try { String[] values = (String[]) value; byte[] results = new byte[values.length]; for (int i = 0; i < values.length; i++) { results[i] = Byte.parseByte(values[i]); } return (results); } catch (Exception e) { if (useDefault) { return (defaultValue); } else { throw new ConversionException(value.toString(), e); } } } // Parse the input value as a String into elements // and convert to the appropriate type try { List list = parseElements(value.toString()); byte[] results = new byte[list.size()]; for (int i = 0; i < results.length; i++) { results[i] = Byte.parseByte((String) list.get(i)); } return (results); } catch (Exception e) { if (useDefault) { return (defaultValue); } else { throw new ConversionException(value.toString(), e); } } }
From source file:org.apache.ambari.view.hive.persistence.utils.ContextConfigurationAdapter.java
@Override public Byte getByte(String s, Byte aByte) { String data = context.getInstanceData(s); return (data != null) ? Byte.parseByte(data) : aByte; }
From source file:org.jcodec.player.filters.http.Downloader.java
private static TapeTimecode parseTimecode(String timecodeRaw) { if (StringUtils.isEmpty(timecodeRaw)) return null; String[] split = StringUtils.split(timecodeRaw, ":"); if (split.length == 4) { return new TapeTimecode(Short.parseShort(split[0]), Byte.parseByte(split[1]), Byte.parseByte(split[2]), Byte.parseByte(split[3]), false); } else if (split.length == 3) { String[] split1 = StringUtils.split(split[2], ";"); if (split1.length == 2) return new TapeTimecode(Short.parseShort(split[0]), Byte.parseByte(split[1]), Byte.parseByte(split1[0]), Byte.parseByte(split1[1]), true); }/*from w w w . j a va 2s . co m*/ return null; }