List of usage examples for java.lang Byte parseByte
public static byte parseByte(String s) throws NumberFormatException
From source file:wtf.cowbay.libraven.compact.CompactCoder.java
public static byte[] strings2compact(List<String> ips) { ByteArrayOutputStream out = new ByteArrayOutputStream(); for (String ip : ips) { Matcher matcher = IP_ADDRESS_WITH_PORT.matcher(ip); if (!matcher.find()) { throw new IllegalArgumentException(ip + " is not a valide ip address(with port)"); } else {/*from w w w .ja v a2 s. c o m*/ out.write(Byte.parseByte(matcher.group(2))); out.write(Byte.parseByte(matcher.group(3))); out.write(Byte.parseByte(matcher.group(4))); out.write(Byte.parseByte(matcher.group(5))); //port int port = Integer.parseInt(matcher.group(6)); out.write(port >> 8); out.write(port & 0xFF); } } return out.toByteArray(); }
From source file:com.gmail.frogocomics.schematic.BiomeWorldV2Object.java
public static BiomeWorldV2Object load(File file) throws IOException { BufferedReader settingsReader; if (!file.exists()) { throw new FileNotFoundException(); }/* www.ja v a 2 s . c om*/ settingsReader = new BufferedReader(new FileReader(file)); int lineNumber = 0; String thisLine; ArrayList<BiomeWorldObjectBlock> bo2Blocks = new ArrayList<>(); while ((thisLine = settingsReader.readLine()) != null) { lineNumber++; if (Pattern.compile("[0-9]").matcher(thisLine.substring(0, 1)).matches() || thisLine.substring(0, 1).equalsIgnoreCase("-")) { //Example: -1,-1,5:18.4 // x,z,y:id.data String[] location = thisLine.split(":")[0].split(","); String[] block = thisLine.split(":")[1].split("\\."); bo2Blocks.add(new BiomeWorldObjectBlock(Integer.parseInt(location[0]), Integer.parseInt(location[2]), Integer.parseInt(location[1]), Short.parseShort(block[0]), Byte.parseByte(block[1]))); } } ArrayList<Integer> maxXMap = new ArrayList<>(); ArrayList<Integer> maxYMap = new ArrayList<>(); ArrayList<Integer> maxZMap = new ArrayList<>(); for (BiomeWorldObjectBlock bo2 : bo2Blocks) { maxXMap.add(bo2.getX()); maxYMap.add(bo2.getY()); maxZMap.add(bo2.getZ()); } int maxX = Collections.max(maxXMap); int maxY = Collections.max(maxYMap); int maxZ = Collections.max(maxZMap); int minX = Collections.min(maxXMap); int minY = Collections.min(maxYMap); int minZ = Collections.min(maxZMap); int differenceX = maxX - minX + 1; int differenceY = maxY - minY + 1; int differenceZ = maxZ - minZ + 1; HashMap<Integer, Set<BiomeWorldObjectBlock>> blocks = new HashMap<>(); for (int i = 0; i < differenceY + 1; i++) { blocks.put(i, new HashSet<>()); } for (BiomeWorldObjectBlock bo2 : bo2Blocks) { Set<BiomeWorldObjectBlock> a = blocks.get(bo2.getY() - minY); a.add(bo2); blocks.replace(bo2.getY(), a); } //System.out.println(differenceX + " " + differenceZ); SliceStack schematic = new SliceStack(differenceY, differenceX, differenceZ); for (Map.Entry<Integer, Set<BiomeWorldObjectBlock>> next : blocks.entrySet()) { Slice slice = new Slice(differenceX, differenceZ); for (BiomeWorldObjectBlock block : next.getValue()) { //System.out.println("Added block at " + String.valueOf(block.getX() - minX) + "," + String.valueOf(block.getZ() - minZ)); slice.setBlock(block.getBlock(), block.getX() - minX, block.getZ() - minZ); } schematic.addSlice(slice); } //System.out.println(schematic.toString()); return new BiomeWorldV2Object(schematic, FilenameUtils.getBaseName(file.getAbsolutePath())); }
From source file:org.apache.sysml.runtime.instructions.mr.TernaryInstruction.java
private TernaryInstruction(Operator op, CPOperand in1, CPOperand in2, CPOperand in3, CPOperand out, String istr) {/*from w w w .j a va 2 s . c o m*/ super(MRType.Ternary, op, Byte.parseByte(out.getName())); instString = istr; input1 = in1; input2 = in2; input3 = in3; output = out; ixinput1 = input1.isMatrix() ? Byte.parseByte(input1.getName()) : -1; ixinput2 = input2.isMatrix() ? Byte.parseByte(input2.getName()) : -1; ixinput3 = input3.isMatrix() ? Byte.parseByte(input3.getName()) : -1; ixoutput = output.isMatrix() ? Byte.parseByte(output.getName()) : -1; m1 = input1.isMatrix() ? null : new MatrixBlock(Double.parseDouble(input1.getName())); m2 = input2.isMatrix() ? null : new MatrixBlock(Double.parseDouble(input2.getName())); m3 = input3.isMatrix() ? null : new MatrixBlock(Double.parseDouble(input3.getName())); }
From source file:com.bt.download.android.gui.httpserver.BrowseHandler.java
@Override public void handle(HttpExchange exchange) throws IOException { assertUPnPActive();/*from ww w . j a v a2 s . com*/ GZIPOutputStream os = null; byte type = -1; try { List<NameValuePair> query = URLEncodedUtils.parse(exchange.getRequestURI(), "UTF-8"); for (NameValuePair item : query) { if (item.getName().equals("type")) { type = Byte.parseByte(item.getValue()); } } if (type == -1) { exchange.sendResponseHeaders(Code.HTTP_BAD_REQUEST, 0); return; } String response = getResponse(exchange, type); exchange.getResponseHeaders().set("Content-Encoding", "gzip"); exchange.getResponseHeaders().set("Content-Type", "text/json; charset=UTF-8"); exchange.sendResponseHeaders(Code.HTTP_OK, 0); os = new GZIPOutputStream(exchange.getResponseBody()); os.write(response.getBytes("UTF-8")); os.finish(); } catch (IOException e) { LOG.warning("Error browsing files type=" + type); throw e; } finally { if (os != null) { os.close(); } exchange.close(); } }
From source file:co.marcin.novaguilds.util.ItemStackUtils.java
@SuppressWarnings("deprecation") public static ItemStack stringToItemStack(String str) { if (!str.isEmpty()) { ItemStack itemStack;//from www.ja va2 s . c o m Material material; String name = ""; int amount = 0; List<String> lore = new ArrayList<>(); String loreString = ""; String bookAuthor = null; String bookBook = null; String player = null; short durability = 0; PotionType potionType = null; int potionLevel = 0; byte data = (byte) 0; Map<Enchantment, Integer> enchantments = new HashMap<>(); String[] explode = str.split(" "); String materialString = explode[0]; DyeColor color; if (explode[0].contains(":")) { String[] dataSplit = explode[0].split(":"); materialString = dataSplit[0]; String dataString = dataSplit[1]; if (NumberUtils.isNumeric(dataString)) { durability = Short.parseShort(dataString); data = Byte.parseByte(dataString); } else { color = DyeColor.valueOf(dataString.toUpperCase()); if (color != null) { data = color.getData(); } durability = data; } } if (NumberUtils.isNumeric(materialString)) { material = Material.getMaterial(Integer.parseInt(materialString)); } else { material = Material.getMaterial(materialString.toUpperCase()); } if (material == null) { return stringToItemStack("DIRT 1 name:&cINVALID_ITEM"); } if (explode.length > 1) { //amount if (NumberUtils.isNumeric(explode[1])) { amount = Integer.parseInt(explode[1]); explode[1] = null; } } else { amount = material.getMaxStackSize(); } explode[0] = null; for (String detail : explode) { if (detail != null) { if (detail.contains(":")) { String[] detailSplit = detail.split(":"); String value = detailSplit[1]; //Bukkit.getLogger().info(detailSplit[0] + " : " + value); switch (detailSplit[0].toLowerCase()) { case "name": name = value; break; case "lore": loreString = value; break; case "title": name = value; break; case "author": bookAuthor = value; break; case "book": bookBook = value; break; case "power": if (material == Material.BOW) { enchantments.put(Enchantment.ARROW_DAMAGE, Integer.valueOf(value)); } else if (material == Material.POTION) { if (NumberUtils.isNumeric(value)) { potionLevel = Integer.parseInt(value); } } else if (material == Material.FIREWORK) { //TODO } break; case "effect": if (material == Material.POTION) { potionType = PotionType.valueOf(value.toUpperCase()); } break; case "duration": break; case "color": color = DyeColor.valueOf(value.toUpperCase()); break; case "player": player = value; break; case "fade": break; case "shape": break; case "sharpness": case "alldamage": enchantments.put(Enchantment.DAMAGE_ALL, Integer.valueOf(value)); break; case "arrowdamage": case "ardmg": enchantments.put(Enchantment.ARROW_DAMAGE, Integer.valueOf(value)); break; case "baneofarthropods": enchantments.put(Enchantment.DAMAGE_ARTHROPODS, Integer.valueOf(value)); break; case "durability": case "unbreaking": enchantments.put(Enchantment.DURABILITY, Integer.valueOf(value)); break; case "fire": case "fireaspect": enchantments.put(Enchantment.FIRE_ASPECT, Integer.valueOf(value)); break; case "knockback": enchantments.put(Enchantment.KNOCKBACK, Integer.valueOf(value)); break; case "looting": case "fortune": enchantments.put(Enchantment.LOOT_BONUS_BLOCKS, Integer.valueOf(value)); break; case "mobloot": enchantments.put(Enchantment.LOOT_BONUS_MOBS, Integer.valueOf(value)); break; case "smite": case "undeaddamage": enchantments.put(Enchantment.DAMAGE_UNDEAD, Integer.valueOf(value)); break; case "arrowknockback": case "punch": enchantments.put(Enchantment.ARROW_KNOCKBACK, Integer.valueOf(value)); break; case "flame": case "flamearrow": enchantments.put(Enchantment.ARROW_FIRE, Integer.valueOf(value)); break; case "infarrows": case "infinity": enchantments.put(Enchantment.ARROW_INFINITE, Integer.valueOf(value)); break; case "digspeed": case "efficiency": enchantments.put(Enchantment.DIG_SPEED, Integer.valueOf(value)); case "silktouch": enchantments.put(Enchantment.SILK_TOUCH, Integer.valueOf(value)); break; case "highcrit": case "thorns": enchantments.put(Enchantment.THORNS, Integer.valueOf(value)); break; case "blastprotect": enchantments.put(Enchantment.PROTECTION_EXPLOSIONS, Integer.valueOf(value)); break; case "fallprot": case "featherfall": enchantments.put(Enchantment.PROTECTION_FALL, Integer.valueOf(value)); break; case "fireprot": case "fireprotect": enchantments.put(Enchantment.PROTECTION_FIRE, Integer.valueOf(value)); break; case "projectileprotection": case "projprot": enchantments.put(Enchantment.PROTECTION_PROJECTILE, Integer.valueOf(value)); break; case "protect": case "protection": enchantments.put(Enchantment.PROTECTION_ENVIRONMENTAL, Integer.valueOf(value)); break; case "waterworker": enchantments.put(Enchantment.WATER_WORKER, Integer.valueOf(value)); break; case "respiration": case "breath": case "aquainfinity": enchantments.put(Enchantment.OXYGEN, Integer.valueOf(value)); break; case "luck": enchantments.put(Enchantment.LUCK, Integer.valueOf(value)); break; case "lure": enchantments.put(Enchantment.LURE, Integer.valueOf(value)); break; } } } } //replace _ with spaces name = name.replace("_", " "); name = StringUtils.fixColors(name); loreString = loreString.replace("_", " "); loreString = StringUtils.fixColors(loreString); if (loreString.contains("|")) { Collections.addAll(lore, org.apache.commons.lang.StringUtils.split(loreString, '|')); } else { lore.add(loreString); } itemStack = new ItemStack(material, amount, data); itemStack.addUnsafeEnchantments(enchantments); ItemMeta itemMeta = itemStack.getItemMeta(); if (!name.isEmpty()) { itemMeta.setDisplayName(name); } if (!loreString.isEmpty()) { itemMeta.setLore(lore); } if (material == Material.POTION && potionLevel != 0 && potionType != null) { Potion potion = new Potion(potionType, potionLevel); potion.apply(itemStack); } itemStack.setDurability(durability); itemStack.setItemMeta(itemMeta); if (player != null && itemStack.getType() == Material.SKULL_ITEM) { SkullMeta skullMeta = (SkullMeta) Bukkit.getItemFactory().getItemMeta(Material.SKULL_ITEM); skullMeta.setOwner(player); itemStack.setItemMeta(skullMeta); } return itemStack; } return stringToItemStack("DIRT 1 name:&cINVALID_ITEM"); }
From source file:com.itemanalysis.psychometrics.irt.estimation.ItemResponseFileSummary.java
public ItemResponseVector[] getResponseVectors(File f, boolean headerIncluded) { String responseString = ""; String[] line = null;//from ww w . j a v a2s .c o m ArrayList<ItemResponseVector> responseData = new ArrayList<ItemResponseVector>(); 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[line.length]; for (int j = 0; j < line.length; j++) { rv[j] = Byte.parseByte(line[j]); } irv = new ItemResponseVector(rv, 1.0); responseData.add(irv); } itemResponseVector = new ItemResponseVector[responseData.size()]; for (int i = 0; i < responseData.size(); i++) { itemResponseVector[i] = responseData.get(i); } } catch (IOException ex) { ex.printStackTrace(); } return itemResponseVector; }
From source file:de.ailis.wlandsuite.PackGame.java
/** * @see de.ailis.wlandsuite.cli.CLIProg#processOption(int, * gnu.getopt.Getopt)//from w ww . j ava2 s. c om */ @Override protected void processOption(int opt, Getopt getopt) { switch (opt) { case 'D': this.disk = Byte.parseByte(getopt.getOptarg()); break; } }
From source file:net.lordsofcode.zephyrus.spells.Conjure.java
@Override public boolean canRun(Player player, String[] args) { if (!(args.length < 2)) { int id = -1; if (args[1].contains("\\:")) { String[] ids = args[1].split("\\:"); if (ids.length == 2) { try { id = Integer.parseInt(ids[0]); Byte.parseByte(ids[1]); } catch (Exception e) { player.sendMessage(ChatColor.GRAY + "Invalid id!"); return false; }/*from w w w. j av a2 s . com*/ } else { player.sendMessage(ChatColor.GRAY + "Invalid id!"); return false; } } else { try { id = Integer.parseInt(args[1]); } catch (Exception e) { player.sendMessage(ChatColor.GRAY + "Invalid id!"); return false; } } int amount = 1; if (args.length == 3) { try { amount = Integer.parseInt(args[2]); } catch (Exception e) { player.sendMessage(ChatColor.GRAY + "Amount must be a number!"); return false; } } if (getValue(id) == -1) { player.sendMessage(ChatColor.GRAY + "That item cannot be conjured!"); return false; } if (LevelManager.getMana(player) < getValue(id) * amount) { player.sendMessage(ChatColor.GRAY + "You do not have enough mana to conjure that item!"); return false; } else { return true; } } else { player.sendMessage(ChatColor.GRAY + "You must specify an item!"); } return false; }
From source file:dev.maisentito.suca.commands.AdminCommandHandler.java
@Override public void handleCommand(MessageEvent event, String[] args) throws Throwable { if ((!Main.config.verifyOwner || event.getUser().isVerified()) && event.getUser().getNick().equals(getStringGlobal(Main.GLOBAL_OWNER, ""))) { if (args.length < 2) { if (args.length == 1) { if (getGlobals().has(args[0], Object.class)) { event.respond(/* w w w . ja va2 s . c o m*/ String.format("!admin: %s = %s", args[0], getGlobals().get(args[0]).toString())); } else { event.respond(String.format("!admin: %s = null", args[0])); } return; } else { event.respond("!admin: not enough arguments"); return; } } else if (args[1].length() < 3) { event.respond("!admin: invalid value"); return; } String key = args[0]; String full = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), ' '); Object value; switch (args[1].charAt(0)) { case 'c': value = args[1].charAt(2); break; case 'b': value = Byte.parseByte(args[1].substring(2)); break; case 's': value = Short.parseShort(args[1].substring(2)); break; case 'i': value = Integer.parseInt(args[1].substring(2)); break; case 'l': value = Long.parseLong(args[1].substring(2)); break; case 'f': value = Float.parseFloat(args[1].substring(2)); break; case 'd': value = Double.parseDouble(args[1].substring(2)); break; case 'z': value = Boolean.parseBoolean(args[1].substring(2)); break; case 'a': value = full.substring(2); break; default: event.respond("!admin: invalid type"); return; } getGlobals().put(key, value); event.respond("success"); } else { event.respond("nope"); } }
From source file:com.jk.security.JKEncDec.java
/** * //from w w w .j a v a 2s . c o m * @param cipherText * @return */ private static byte[] toBytes(String cipherText) { // rever to bytes from string called from toString(byte[]) method String[] split = cipherText.split(","); byte[] bytes = new byte[split.length]; int i = 0; for (String b : split) { bytes[i++] = Byte.parseByte(b); } return bytes; }