Example usage for java.lang Byte Byte

List of usage examples for java.lang Byte Byte

Introduction

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

Prototype

@Deprecated(since = "9")
public Byte(String s) throws NumberFormatException 

Source Link

Document

Constructs a newly allocated Byte object that represents the byte value indicated by the String parameter.

Usage

From source file:javadz.beanutils.converters.NumberConverter.java

/**
 * Default String to Number conversion./*from ww w .  jav  a  2  s .  com*/
 * <p>
 * This method handles conversion from a String to the following types:
 * <ul>
 *     <li><code>java.lang.Byte</code></li>
 *     <li><code>java.lang.Short</code></li>
 *     <li><code>java.lang.Integer</code></li>
 *     <li><code>java.lang.Long</code></li>
 *     <li><code>java.lang.Float</code></li>
 *     <li><code>java.lang.Double</code></li>
 *     <li><code>java.math.BigDecimal</code></li>
 *     <li><code>java.math.BigInteger</code></li>
 * </ul>
 * @param sourceType The type being converted from
 * @param targetType The Number type to convert to
 * @param value The String value to convert.
 *
 * @return The converted Number value.
 */
private Number toNumber(Class sourceType, Class targetType, String value) {

    // Byte
    if (targetType.equals(Byte.class)) {
        return new Byte(value);
    }

    // Short
    if (targetType.equals(Short.class)) {
        return new Short(value);
    }

    // Integer
    if (targetType.equals(Integer.class)) {
        return new Integer(value);
    }

    // Long
    if (targetType.equals(Long.class)) {
        return new Long(value);
    }

    // Float
    if (targetType.equals(Float.class)) {
        return new Float(value);
    }

    // Double
    if (targetType.equals(Double.class)) {
        return new Double(value);
    }

    // BigDecimal
    if (targetType.equals(BigDecimal.class)) {
        return new BigDecimal(value);
    }

    // BigInteger
    if (targetType.equals(BigInteger.class)) {
        return new BigInteger(value);
    }

    String msg = toString(getClass()) + " cannot handle conversion from '" + toString(sourceType) + "' to '"
            + toString(targetType) + "'";
    if (log().isWarnEnabled()) {
        log().warn("    " + msg);
    }
    throw new ConversionException(msg);
}

From source file:com.sun.honeycomb.adm.client.AdminClientImpl.java

public int delCell(byte cellId) throws MgmtException, ConnectException, PermissionException {
    if (!loggedIn())
        throw new PermissionException();
    HCCell cell = getCell(SiloInfo.getInstance().getMasterUrl());
    Object[] params = { Long.toString(this._sessionId), Byte.toString(cellId) };
    this.extLog(ExtLevel.EXT_INFO, AdminResourcesConstants.MSG_KEY_REMOVE_CELL, params, "delCell");
    BigInteger result = cell.delCell(new Byte(cellId));
    return result.intValue();
}

From source file:com.cognitect.transit.TransitTest.java

public void testWriteInteger() throws Exception {

    assertEquals(scalarVerbose("42"), writeJsonVerbose(42));
    assertEquals(scalarVerbose("42"), writeJsonVerbose(42L));
    assertEquals(scalarVerbose("42"), writeJsonVerbose(new Byte("42")));
    assertEquals(scalarVerbose("42"), writeJsonVerbose(new Short("42")));
    assertEquals(scalarVerbose("42"), writeJsonVerbose(new Integer("42")));
    assertEquals(scalarVerbose("42"), writeJsonVerbose(new Long("42")));
    assertEquals(scalarVerbose("\"~n42\""), writeJsonVerbose(new BigInteger("42")));
    assertEquals(scalarVerbose("\"~n4256768765123454321897654321234567\""),
            writeJsonVerbose(new BigInteger("4256768765123454321897654321234567")));
}

From source file:Base64InputStream.java

/**
 * Returns an iterator over this buffer's elements.
 *
 * @return an iterator over this buffer's elements
 *//* w ww  . j  av a  2 s  .  c o  m*/
public Iterator<Byte> iterator() {
    return new Iterator<Byte>() {

        private int index = head;
        private int lastReturnedIndex = -1;

        public boolean hasNext() {
            return index != tail;

        }

        public Byte next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            lastReturnedIndex = index;
            index = increment(index);
            return new Byte(buffer[lastReturnedIndex]);
        }

        public void remove() {
            if (lastReturnedIndex == -1) {
                throw new IllegalStateException();
            }

            // First element can be removed quickly
            if (lastReturnedIndex == head) {
                UnboundedFifoByteBuffer.this.remove();
                lastReturnedIndex = -1;
                return;
            }

            // Other elements require us to shift the subsequent elements
            int i = lastReturnedIndex + 1;
            while (i != tail) {
                if (i >= buffer.length) {
                    buffer[i - 1] = buffer[0];
                    i = 0;
                } else {
                    buffer[i - 1] = buffer[i];
                    i++;
                }
            }

            lastReturnedIndex = -1;
            tail = decrement(tail);
            buffer[tail] = 0;
            index = decrement(index);
        }

    };
}

From source file:com.jaspersoft.jasperserver.war.action.ViewReportAction.java

protected void setReportUnitAttributes(RequestContext context, ReportUnit reportUnit) {
    super.setReportUnitAttributes(context, reportUnit);

    MutableAttributeMap flowScope = context.getFlowScope();
    flowScope.put(getAttributeReportControlsLayout(), new Byte(reportUnit.getControlsLayout()));
    flowScope.put(getAttributeReportForceControls(), Boolean.valueOf(reportUnit.isAlwaysPromptControls()));
}

From source file:edu.umass.cs.msocket.proxy.console.ConsoleModule.java

/**
 * Implements SEQUOIA-887. We would like to create a BufferedReader to use its
 * readLine() method but can't because its eager cache would steal bytes from
 * JLine and drop them when we return, so painfully implement here our own
 * readLine() method, tyring to be bug for bug compatible with JLine.
 * <p>/*from  www.j a  v a 2s .c  o  m*/
 * This is a quite ugly hack. Among others we cannot use any read buffering
 * since consoleReader is exported and might be used elsewhere. At the very
 * least we would like to encapsulate the consoleReader so we can avoid
 * creating one in non-JLine mode. Re-open SEQUOIA-887 for such a proper fix.
 */
private String readLineBypassJLine() throws IOException {
    // If JLine implements any kind of internal read buffering, we
    // are screwed.
    InputStream jlineInternal = console.getInput();

    /*
     * Unfortunately we can't do this because InputStreamReader returns -1/EOF
     * after every line!? So we have to decode bytes->characters by ourselves,
     * see below. Because of this we will FAIL with exotic locales, see
     * SEQUOIA-911
     */
    // Reader jlineInternal = new InputStreamReader(consoleReader.getInput());
    currentLine.clear();

    int ch = jlineInternal.read();

    if (ch == -1 /* EOF */ || ch == 4 /* ASCII EOT */)
        return null;

    /**
     * @see java.io.BufferedReader#readLine(boolean)
     * @see java.io.DataInputStream#readLine() and also the less elaborate JLine
     *      keybinding.properties
     */
    // discard any LF following a CR
    if (lastWasCR && ch == '\n')
        ch = jlineInternal.read();

    // EOF also counts as an end of line. Not sure this is what JLine does but
    // it looks good.
    while (ch != -1 && ch != '\n' && ch != '\r') {
        currentLine.add(new Byte((byte) ch));
        ch = jlineInternal.read();
    }

    // SEQUOIA-911 FIXME: we may have found a '\n' or '\r' INSIDE a multibyte
    // character. Definitely not a real newline.

    lastWasCR = (ch == '\r');

    // "cast" byte List into a primitive byte array
    byte[] encoded = new byte[currentLine.size()];
    Iterator it = currentLine.iterator();
    for (int i = 0; it.hasNext(); i++)
        encoded[i] = ((Byte) it.next()).byteValue();

    /**
     * This String ctor is using the "default" java.nio.Charset encoding which
     * is locale-dependent; a Good Thing.
     */
    String line = new String(encoded);

    return line;
}

From source file:org.shampoo.goldenembed.parser.GoldenEmbedParserMain.java

private void ANTrxMsg(byte[] rxIN, int size, GoldenCheetah gc) {
    int i = 2;//from   ww w.  ja v a  2s. c  o  m
    if (megaDebug)
        System.out.println("Converting 0x" + UnicodeFormatter.byteToHex(rxIN[i]));
    switch (rxIN[i]) {
    case MESG_RESPONSE_EVENT_ID:
        if (debug)
            System.out.println("ID: MESG_RESPONSE_EVENT_ID\n");
        ANTresponseHandler(rxIN, size, gc);
        break;
    case MESG_CAPABILITIES_ID:
        if (debug)
            System.out.println("ID: MESG_CAPABILITIES_ID\n");
        i = ANTCfgCapabilties(i, size); // rxBuf[3] .. skip sync, size, msg
        break;
    case MESG_BROADCAST_DATA_ID:
        if (debug)
            System.out.println("ID: MESG_BROADCAST_DATA_ID\n");
        Byte aByte = new Byte(rxIN[++i]);
        int chan = aByte.intValue();
        if (chan == 0)
            ANTparseHRM(rxIN, gc);
        else if (chan == 1)
            power.ANTParsePower(rxIN, size, gc, gcArray);
        break;

    case MESG_CHANNEL_ID_ID:
        if (debug)
            System.out.println("ID: MESG_CHANNEL_ID_ID\n");
        ANTChannelID(rxIN, gc);
        break;
    default:
        if (debug)
            System.out.println("ID: Unknown 0x" + UnicodeFormatter.byteToHex(rxIN[i]));
    }
    return;
}

From source file:eionet.util.Util.java

/**
 * A method for creating a unique Hexa-Decimal digest of a String message.
 *
 * @param src/*from   ww  w  .jav a  2  s .c om*/
 *            String to be digested.
 * @param algosrithm
 *            Digesting algorithm (please see Java documentation for allowable values).
 * @return A unique String-typed Hexa-Decimal digest of the input message.
 */
public static String digestHexDec(String src, String algorithm) throws GeneralSecurityException {

    byte[] srcBytes = src.getBytes();
    byte[] dstBytes = new byte[16];

    MessageDigest md = MessageDigest.getInstance(algorithm);
    md.update(srcBytes);
    dstBytes = md.digest();
    md.reset();

    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < dstBytes.length; i++) {
        Byte byteWrapper = new Byte(dstBytes[i]);
        int k = byteWrapper.intValue();
        String s = Integer.toHexString(byteWrapper.intValue());
        if (s.length() == 1) {
            s = "0" + s;
        }
        buf.append(s.substring(s.length() - 2));
    }

    return buf.toString();
}

From source file:TypeConversionHelper.java

/**
 * Convert a byte[] into an instance of our value class.
 * @param buf byte array to be converted
 * @return converted Byte array as object
 *///from   w  ww.j  a v a2  s. com
public static Object getByteObjectArrayFromByteArray(byte[] buf) {
    if (buf == null) {
        return null;
    }

    Byte[] a = new Byte[buf.length];
    for (int i = 0; i < a.length; i++) {
        a[i] = new Byte(buf[i]);
    }
    return a;
}