Example usage for java.lang Byte parseByte

List of usage examples for java.lang Byte parseByte

Introduction

In this page you can find the example usage for java.lang Byte parseByte.

Prototype

public static byte parseByte(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal byte .

Usage

From source file:de.doncarnage.minecraft.baseplugin.util.ItemUtil.java

/**
 * Returns the corresponding item for the given item and sub string.
 *
 * @param item the wanted item, e.g. log or step
 * @param sub  the data byte of the material
 * @return a {@link MaterialData} instance reflecting this item
 *///from  w w  w  .ja  va2  s . c  o  m
@SuppressWarnings("deprecation")
public static MaterialData getMaterialDataByString(String item, String sub) {
    Preconditions.checkNotNull(item);
    Material mat = Material.getMaterial(item.toUpperCase());
    if (mat == null) {
        return null;
    }
    MaterialData matData = new MaterialData(mat);
    if (!StringUtils.isBlank(sub)) {
        try {
            matData.setData(Byte.parseByte(sub));
        } catch (NumberFormatException nfe) {
            return null;
        }
    }
    return matData;
}

From source file:org.lwes.serializer.StringParser.java

public static byte fromStringBYTE(String string) {
    return Byte.parseByte(string);
}

From source file:org.exolab.castor.xml.parsing.primitive.objects.PrimitiveByte.java

@Override
public Object getObject(Class<?> type, String value) {
    if (StringUtils.isEmpty(value)) {
        return Byte.valueOf((byte) 0);
    }/*ww  w. j  a va2 s  .  c o m*/

    return Byte.valueOf(Byte.parseByte(value));
}

From source file:org.ext4spring.parameter.converter.simple.ByteConverter.java

@Override
public <T> T toTypedValue(String stringValue, Class<T> type) {
    return (stringValue != null) ? type.cast(Byte.parseByte(stringValue)) : null;
}

From source file:net.lordsofcode.zephyrus.spells.Conjure.java

@Override
public void run(Player player, String[] args) {
    int id;/*from w w  w.j a  va 2s  . c o  m*/
    byte data = 0;
    int amount = 1;
    if (args[1].contains("\\:")) {
        String[] ids = args[1].split("\\:");
        id = Integer.parseInt(ids[0]);
        data = Byte.parseByte(ids[1]);
    } else {
        id = Integer.parseInt(args[1]);
    }
    if (args.length == 3) {
        amount = Integer.parseInt(args[2]);
    }
    ItemStack item = new ItemStack(Material.getMaterial(id), amount, data);
    HashMap<Integer, ItemStack> map = player.getInventory().addItem(item);
    if (!map.isEmpty()) {
        player.sendMessage(ChatColor.GRAY + "Your inventory is full!");
    } else {
        player.sendMessage(ChatColor.GRAY + "You have conjured " + ChatColor.GOLD + amount + " "
                + WordUtils.capitalizeFully(item.getType().toString().replace("_", " ")));
        LevelManager.drainMana(player, getValue(id) * amount);
    }
}

From source file:org.mypackage.controller.impl.NewEmailControllerImpl.java

@Override
public int addNewEmail(String address, String categoryValue, String contactId)
        throws MalformedIdentifierException, DalException, MalformedCategoryException, DuplicateEmailException {
    Email email = new Email();
    Byte category;/*from   w w  w.  j ava2s.  co m*/
    email.setAddress(address);

    try {
        category = Byte.parseByte(categoryValue);
        email.setCategory(Email.Category.forValue(category));
    } catch (NumberFormatException ex) {
        throw new MalformedCategoryException(categoryValue, ex);
    }

    try {
        email.setfContactId(Integer.parseInt(contactId));
    } catch (NumberFormatException ex) {
        throw new MalformedIdentifierException(contactId, ex);
    }
    //        int passedContactId;
    int emailId;
    if (!(this.contactRepository.checkIfEmailExists(email))) {
        emailId = this.contactRepository.addEmail(email);
        //            passedContactId = email.getfContactId();
    } else {
        throw new DuplicateEmailException(email.getAddress());
    }
    return emailId;
    //        return passedContactId;
}

From source file:springapp.web.controller.theme.DownloadController.java

public ModelAndView handleRequest(HttpServletRequest httpServletRequest,
        HttpServletResponse httpServletResponse) throws Exception {

    String templateIdString = httpServletRequest.getParameter(ApplicationConstants.TEMPLATE_ID);

    byte templateId = null != templateIdString ? Byte.parseByte(templateIdString) : 0;
    String templateName = templateId == 0 ? "blue" : "gray";

    String shemaNameParam = httpServletRequest.getParameter(ApplicationConstants.NEW_SCHEMA_NAME);
    String newSchemaName = (null != shemaNameParam) && (!"".equals(shemaNameParam)) ? shemaNameParam
            : "default";

    String versionString = httpServletRequest.getParameter("version");
    String version = (null == versionString) ? "3.2" : versionString;

    HttpSession session = httpServletRequest.getSession();

    ServletContext servletContext = session.getServletContext();
    WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
    //String resourcesPath = (String)context.getBean("resourcesPath");

    ResourcesHolder currentSchema = (ResourcesHolder) session
            .getAttribute(ApplicationConstants.CURRENT_SCHEMA_ATTRIBUTE_NAME/*+version*/);
    String resourcesPath = currentSchema.getResourcesPath();
    ResourcesLoader loader = loaderFactory.getResourcesLoader(currentSchema, context);

    httpServletResponse.setContentType("application/zip");

    httpServletResponse.setHeader("Pragma", "no-cache");
    httpServletResponse.setHeader("Cache-Control", "no-cache");
    httpServletResponse.setHeader("Expires", "-1");
    httpServletResponse.setHeader("Content-Disposition",
            "attachment; filename=\"xtheme-" + newSchemaName + ".zip\";");
    //httpServletResponse.setContentLength(zipOS.size());
    ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
    ZipOutputStream zipOS = new ZipOutputStream(servletOutputStream);

    zipOS = loader.outForZip(currentSchema, resourcesPath, zipOS, context, newSchemaName, templateName,
            version);/*w  w  w. ja  v a 2  s  . c o  m*/

    zipOS.flush();
    zipOS.close();
    servletOutputStream.flush();
    servletOutputStream.close();

    logger.info("DownloadController processed! ");

    return null;
}

From source file:de.Keyle.MyPet.api.Util.java

public static boolean isByte(String number) {
    try {//from   www .  j av a 2  s .com
        Byte.parseByte(number);
        return true;
    } catch (NumberFormatException nFE) {
        return false;
    }
}

From source file:org.mypackage.controller.impl.UpdateEmailControllerImpl.java

@Override
public Email updateEmail(String id, String address, String categoryValue, String fContactId)
        throws MalformedIdentifierException, MalformedCategoryException, DalException, DuplicateEmailException {
    Email email = new Email();
    try {//www.  ja  v  a  2s.  c o m
        email.setId(Integer.parseInt(id));
    } catch (NumberFormatException ex) {
        throw new MalformedIdentifierException(id, ex);
    }
    email.setAddress(address);

    try {
        category = Byte.parseByte(categoryValue);
        email.setCategory(Email.Category.forValue(category));
    } catch (NumberFormatException ex) {
        throw new MalformedCategoryException(categoryValue, ex);
    }

    try {
        email.setfContactId(Integer.parseInt(fContactId));
    } catch (NumberFormatException ex) {
        throw new MalformedIdentifierException(fContactId, ex);
    }

    if (!(this.contactRepository.checkIfEmailExists(email))) {
        this.contactRepository.updateEmailById(email);
    } else {
        throw new DuplicateEmailException(email.getAddress());
    }

    return email;
}

From source file:com.ExtendedAlpha.SWI.SeparatorLib.BannerSeparator.java

public static BannerMeta getBannerMeta(JSONObject json) {
    try {//  w w w  . j a v a  2 s.  c o m
        BannerMeta dummy = (BannerMeta) new ItemStack(Material.BANNER).getItemMeta();
        if (json.has("base-color"))
            dummy.setBaseColor(DyeColor.getByDyeData(Byte.parseByte("" + json.get("base-color"))));

        JSONArray colors = json.getJSONArray("colors");
        JSONArray patternTypes = json.getJSONArray("pattern-types");
        for (int i = 0; i < colors.length(); i++) {
            dummy.addPattern(
                    new Pattern(DyeColor.getByDyeData(Integer.valueOf((int) colors.get(i)).byteValue()),
                            PatternType.getByIdentifier(patternTypes.getString(i))));
        }

        return dummy;
    } catch (JSONException ex) {
        ex.printStackTrace();
        return null;
    }
}