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:org.mule.transport.jms.JmsMessageUtilsTestCase.java

@Test
public void testStreamMessageSerialization() throws Exception {
    Session session = mock(Session.class);
    when(session.createStreamMessage()).thenReturn(new ActiveMQStreamMessage());

    // Creates a test list with data
    List data = new ArrayList();
    data.add(Boolean.TRUE);/*from   ww w. j  ava2s.com*/
    data.add(new Byte("1"));
    data.add(new Short("2"));
    data.add(new Character('3'));
    data.add(new Integer("4"));
    // can't write Longs: https://issues.apache.org/activemq/browse/AMQ-1965
    // data.add(new Long("5"));
    data.add(new Float("6"));
    data.add(new Double("7"));
    data.add(new String("8"));
    data.add(null);
    data.add(new byte[] { 9, 10 });

    StreamMessage result = (StreamMessage) JmsMessageUtils.toMessage(data, session);

    // Resets so it's readable
    result.reset();
    assertEquals(Boolean.TRUE, result.readObject());
    assertEquals(new Byte("1"), result.readObject());
    assertEquals(new Short("2"), result.readObject());
    assertEquals(new Character('3'), result.readObject());
    assertEquals(new Integer("4"), result.readObject());
    // can't write Longs: https://issues.apache.org/activemq/browse/AMQ-1965
    // assertEquals(new Long("5"), result.readObject());
    assertEquals(new Float("6"), result.readObject());
    assertEquals(new Double("7"), result.readObject());
    assertEquals(new String("8"), result.readObject());
    assertNull(result.readObject());
    assertTrue(Arrays.equals(new byte[] { 9, 10 }, (byte[]) result.readObject()));
}

From source file:com.igorbaiborodine.example.mybatis.customer.TestCustomerMapper.java

private Customer createCustomer() {
    int random = (new Random()).nextInt(1000);
    String firstName = "FIRST_NAME_ANT_" + random;
    String lastName = "LAST_NAME_ANT_" + random;
    Byte storeId = new Byte("1");
    Short addressId = new Short("1");

    Customer customer = new Customer();

    customer.setAddressId(addressId);//from   w ww. j  ava2 s. c om
    customer.setFirstName(firstName);
    customer.setLastName(lastName);
    customer.setEmail(random + "_test.mapper@sakilacustomer.org");
    customer.setStoreId(storeId);
    customer.setActive(true);
    customer.setCreateDate(new Date());

    return customer;
}

From source file:org.opencms.util.CmsDataTypeUtil.java

/**
 * Formats the given data into a string value.<p>
 * //from ww  w  . j  av  a 2  s . co m
 * @param data the data to format
 * 
 * @return a string representation of the given data
 */
public static String format(byte data) {

    return new Byte(data).toString();
}

From source file:de.unibayreuth.bayeos.goat.table.MassenTableModel.java

public boolean updateRow(ObjektNode objektNode, int row, Vector values) {
    boolean bol = false;
    try {/* ww  w  .  j  a  v a  2  s.c om*/

        // get update columns
        java.util.Date new_von = (java.util.Date) values.elementAt(0);
        Double wert = (Double) values.elementAt(1);
        Integer status = (Integer) values.elementAt(2);

        java.util.Date old_von = (java.util.Date) getValueAt(row, 0);

        Vector params = new Vector();
        params.add(objektNode.getId());
        params.add(old_von);
        params.add(status);
        params.add(wert);
        params.add(new_von);

        bol = ((Boolean) xmlClient.execute("MassenTableHandler.updateRow", params)).booleanValue();

        // Update display values 
        setValueAt(new_von, row, 0);
        setValueAt(wert, row, 1);
        setValueAt(new Byte(status.byteValue()), row, 2);
        fireTableDataChanged();

    } catch (XmlRpcException x) {
        MsgBox.error(x.getMessage());
        return false;
    }

    return bol;
}

From source file:com.jaspersoft.jasperserver.ws.axis2.scheduling.ReportJobBeanTraslator.java

protected String toStringConstant(String constant, byte value) {
    return toStringConstant(constant, new Byte(value));
}

From source file:net.handle.servlet.Protocol.java

/**
 * <p>/*from   ww w.  java  2 s  . c  om*/
 * Returns an integer representing this protocol, as specified by
 * {@link Interface}.
 * </p>
 *
 * @return the int
 */
public int toInt() {
    Integer i = null;

    switch (this) {
    case HTTP:
        i = new Byte(Interface.SP_HDL_HTTP).intValue();
        break;
    case TCP:
        i = new Byte(Interface.SP_HDL_TCP).intValue();
        break;
    case UDP:
        i = new Byte(Interface.SP_HDL_UDP).intValue();
    }

    return i;
}

From source file:de.javakaffee.web.msm.serializer.javolution.AaltoTranscoderTest.java

@DataProvider(name = "typesAsSessionAttributesProvider")
protected Object[][] createTypesAsSessionAttributesData() {
    return new Object[][] { { int.class, 42 }, { long.class, 42 }, { Boolean.class, Boolean.TRUE },
            { String.class, "42" }, { Class.class, String.class }, { Long.class, new Long(42) },
            { Integer.class, new Integer(42) }, { Character.class, new Character('c') },
            { Byte.class, new Byte("b".getBytes()[0]) }, { Double.class, new Double(42d) },
            { Float.class, new Float(42f) }, { Short.class, new Short((short) 42) },
            { BigDecimal.class, new BigDecimal(42) }, { AtomicInteger.class, new AtomicInteger(42) },
            { AtomicLong.class, new AtomicLong(42) }, { MutableInt.class, new MutableInt(42) },
            { Integer[].class, new Integer[] { 42 } },
            { Date.class, new Date(System.currentTimeMillis() - 10000) },
            { Calendar.class, Calendar.getInstance() },
            { ArrayList.class, new ArrayList<String>(Arrays.asList("foo")) },
            { int[].class, new int[] { 1, 2 } }, { long[].class, new long[] { 1, 2 } },
            { short[].class, new short[] { 1, 2 } }, { float[].class, new float[] { 1, 2 } },
            { double[].class, new double[] { 1, 2 } }, { boolean[].class, new boolean[] { true, false } },
            { byte[].class, "42".getBytes() }, { char[].class, "42".toCharArray() },
            { String[].class, new String[] { "23", "42" } },
            { Person[].class, new Person[] { createPerson("foo bar", Gender.MALE, 42) } } };
}

From source file:edu.hawaii.soest.pacioos.text.SocketTextSource.java

@Override
protected boolean execute() {

    log.debug("SocketTextSource.execute() called.");
    // do not execute the stream if there is no connection
    if (!isConnected())
        return false;

    boolean failed = false;

    /* Get a connection to the instrument */
    SocketChannel socket = getSocketConnection();
    if (socket == null)
        return false;

    // while data are being sent, read them into the buffer
    try {/*from  w  w w  .  j  a v  a 2  s .  com*/
        // create four byte placeholders used to evaluate up to a four-byte 
        // window.  The FIFO layout looks like:
        //           -------------------------
        //   in ---> | One | Two |Three|Four |  ---> out
        //           -------------------------
        byte byteOne = 0x00, // set initial placeholder values
                byteTwo = 0x00, byteThree = 0x00, byteFour = 0x00;

        // Create a buffer that will store the sample bytes as they are read
        ByteBuffer sampleBuffer = ByteBuffer.allocate(getBufferSize());

        // create a byte buffer to store bytes from the TCP stream
        ByteBuffer buffer = ByteBuffer.allocateDirect(getBufferSize());

        // while there are bytes to read from the socket ...
        while (socket.read(buffer) != -1 || buffer.position() > 0) {

            // prepare the buffer for reading
            buffer.flip();

            // while there are unread bytes in the ByteBuffer
            while (buffer.hasRemaining()) {
                byteOne = buffer.get();

                // log the byte stream
                String character = new String(new byte[] { byteOne });
                if (log.isDebugEnabled()) {
                    List<Byte> whitespaceBytes = new ArrayList<Byte>();
                    whitespaceBytes.add(new Byte((byte) 0x0A));
                    whitespaceBytes.add(new Byte((byte) 0x0D));
                    if (whitespaceBytes.contains(new Byte(byteOne))) {
                        character = new String(Hex.encodeHex((new byte[] { byteOne })));

                    }
                }
                log.debug("char: " + character + "\t" + "b1: "
                        + new String(Hex.encodeHex((new byte[] { byteOne }))) + "\t" + "b2: "
                        + new String(Hex.encodeHex((new byte[] { byteTwo }))) + "\t" + "b3: "
                        + new String(Hex.encodeHex((new byte[] { byteThree }))) + "\t" + "b4: "
                        + new String(Hex.encodeHex((new byte[] { byteFour }))) + "\t" + "sample pos: "
                        + sampleBuffer.position() + "\t" + "sample rem: " + sampleBuffer.remaining() + "\t"
                        + "sample cnt: " + sampleByteCount + "\t" + "buffer pos: " + buffer.position() + "\t"
                        + "buffer rem: " + buffer.remaining() + "\t" + "state: " + state);

                // evaluate each byte to find the record delimiter(s), and when found, validate and
                // send the sample to the DataTurbine.
                int numberOfChannelsFlushed = 0;

                if (getRecordDelimiters().length == 2) {
                    // have we hit the delimiters in the stream yet?
                    if (byteTwo == getFirstDelimiterByte() && byteOne == getSecondDelimiterByte()) {
                        sampleBuffer.put(byteOne);
                        sampleByteCount++;
                        // extract just the length of the sample bytes out of the
                        // sample buffer, and place it in the channel map as a 
                        // byte array.  Then, send it to the DataTurbine.
                        log.debug("Sample byte count: " + sampleByteCount);
                        byte[] sampleArray = new byte[sampleByteCount];
                        sampleBuffer.flip();
                        sampleBuffer.get(sampleArray);
                        String sampleString = new String(sampleArray, "US-ASCII");

                        if (validateSample(sampleString)) {
                            numberOfChannelsFlushed = sendSample(sampleString);

                        }

                        sampleBuffer.clear();
                        sampleByteCount = 0;
                        byteOne = 0x00;
                        byteTwo = 0x00;
                        byteThree = 0x00;
                        byteFour = 0x00;
                        log.debug("Cleared b1,b2,b3,b4. Cleared sampleBuffer. Cleared rbnbChannelMap.");

                    } else {
                        // still in the middle of the sample, keep adding bytes
                        sampleByteCount++; // add each byte found

                        if (sampleBuffer.remaining() > 0) {
                            sampleBuffer.put(byteOne);

                        } else {
                            sampleBuffer.compact();
                            log.debug("Compacting sampleBuffer ...");
                            sampleBuffer.put(byteOne);

                        }

                    }

                } else if (getRecordDelimiters().length == 1) {
                    // have we hit the delimiter in the stream yet?
                    if (byteOne == getFirstDelimiterByte()) {
                        sampleBuffer.put(byteOne);
                        sampleByteCount++;
                        // extract just the length of the sample bytes out of the
                        // sample buffer, and place it in the channel map as a 
                        // byte array.  Then, send it to the DataTurbine.
                        byte[] sampleArray = new byte[sampleByteCount];
                        sampleBuffer.flip();
                        sampleBuffer.get(sampleArray);
                        String sampleString = new String(sampleArray, "US-ASCII");

                        if (validateSample(sampleString)) {
                            numberOfChannelsFlushed = sendSample(sampleString);

                        }

                        sampleBuffer.clear();
                        sampleByteCount = 0;
                        byteOne = 0x00;
                        byteTwo = 0x00;
                        byteThree = 0x00;
                        byteFour = 0x00;
                        log.debug("Cleared b1,b2,b3,b4. Cleared sampleBuffer. Cleared rbnbChannelMap.");

                    } else {
                        // still in the middle of the sample, keep adding bytes
                        sampleByteCount++; // add each byte found

                        if (sampleBuffer.remaining() > 0) {
                            sampleBuffer.put(byteOne);

                        } else {
                            sampleBuffer.compact();
                            log.debug("Compacting sampleBuffer ...");
                            sampleBuffer.put(byteOne);

                        }

                    }

                } // end getRecordDelimiters().length

                // shift the bytes in the FIFO window
                byteFour = byteThree;
                byteThree = byteTwo;
                byteTwo = byteOne;

            } //end while (more unread bytes)

            // prepare the buffer to read in more bytes from the stream
            buffer.compact();

        } // end while (more socket bytes to read)
        socket.close();

    } catch (IOException e) {
        // handle exceptions
        // In the event of an i/o exception, log the exception, and allow execute()
        // to return false, which will prompt a retry.
        failed = true;
        log.error("There was a communication error in sending the data sample. The message was: "
                + e.getMessage());
        if (log.isDebugEnabled()) {
            e.printStackTrace();
        }
        return !failed;

    } catch (SAPIException sapie) {
        // In the event of an RBNB communication  exception, log the exception, 
        // and allow execute() to return false, which will prompt a retry.
        failed = true;
        log.error("There was an RBNB error while sending the data sample. The message was: "
                + sapie.getMessage());
        if (log.isDebugEnabled()) {
            sapie.printStackTrace();
        }
        return !failed;
    }

    return !failed;

}

From source file:info.archinnov.achilles.it.TestEntityWithComplexTypes.java

@Test
public void should_insert() throws Exception {
    //Given//w w  w . ja v  a 2  s  .  c  o m
    final long id = RandomUtils.nextLong(0L, Long.MAX_VALUE);
    final TestUDT udt = new TestUDT();
    udt.setList(asList("list"));
    udt.setName("name");
    udt.setMap(ImmutableMap.of(1, "1"));
    UUID timeuuid = UUIDs.timeBased();
    java.time.Instant jdkInstant = Instant.now();
    java.time.LocalDate jdkLocalDate = java.time.LocalDate.now();
    java.time.LocalTime jdkLocalTime = java.time.LocalTime.now();
    java.time.ZonedDateTime jdkZonedDateTime = java.time.ZonedDateTime.now();

    final EntityWithComplexTypes entity = new EntityWithComplexTypes();
    entity.setId(id);
    entity.setCodecOnClass(new ClassAnnotatedByCodec());
    entity.setComplexNestingMap(
            ImmutableMap.of(udt, ImmutableMap.of(1, Tuple3.of(1, 2, ConsistencyLevel.ALL))));
    entity.setConsistencyLevel(ConsistencyLevel.EACH_QUORUM);
    entity.setInteger(123);
    entity.setJsonMap(ImmutableMap.of(1, asList(1, 2, 3)));
    entity.setListNesting(asList(ImmutableMap.of(1, "one")));
    entity.setListUdt(asList(udt));
    entity.setMapUdt(ImmutableMap.of(1, udt));
    entity.setMapWithNestedJson(ImmutableMap.of(1, asList(ImmutableMap.of(1, "one"))));
    entity.setObjectBoolean(new Boolean(true));
    entity.setObjectByte(new Byte("5"));
    entity.setObjectByteArray(new Byte[] { 7 });
    entity.setOkSet(Sets.newHashSet(ConsistencyLevel.LOCAL_ONE, ConsistencyLevel.LOCAL_QUORUM));
    entity.setPrimitiveBoolean(true);
    entity.setPrimitiveByte((byte) 3);
    entity.setPrimitiveByteArray(new byte[] { 4 });
    entity.setSimpleUdt(udt);
    entity.setTime(buildDate());
    entity.setTimeuuid(timeuuid);
    entity.setTuple1(Tuple1.of(ConsistencyLevel.THREE));
    entity.setTuple2(Tuple2.of(ConsistencyLevel.TWO, 2));
    entity.setTupleNesting(Tuple2.of(1, asList("1")));
    entity.setValue("val");
    entity.setWriteTime(1000L);
    entity.setWriteTimeWithCodec("2000");
    entity.setIntWrapper(new IntWrapper(123));
    entity.setProtocolVersion(ProtocolVersion.V4);
    entity.setEncoding(Enumerated.Encoding.ORDINAL);
    entity.setDoubleArray(new double[] { 1.0, 2.0 });
    entity.setFloatArray(new float[] { 3.0f, 4.0f });
    entity.setIntArray(new int[] { 5, 6 });
    entity.setLongArray(new long[] { 7L, 8L });
    entity.setListOfLongArray(Arrays.asList(new long[] { 9L, 10L }));
    entity.setJdkInstant(jdkInstant);
    entity.setJdkLocalDate(jdkLocalDate);
    entity.setJdkLocalTime(jdkLocalTime);
    entity.setJdkZonedDateTime(jdkZonedDateTime);
    entity.setProtocolVersionAsOrdinal(ProtocolVersion.V2);
    entity.setOptionalString(Optional.empty());
    entity.setOptionalProtocolVersion(Optional.of(ProtocolVersion.V3));
    entity.setOptionalEncodingAsOrdinal(Optional.of(ProtocolVersion.V2));
    entity.setListOfOptional(Arrays.asList(Optional.of("1"), Optional.of("2")));

    //When
    manager.crud().insert(entity).execute();

    //Then
    final Metadata metadata = session.getCluster().getMetadata();
    final TupleValue tupleValue = metadata.newTupleType(text(), cint(), cint()).newValue("1", 2, 5);

    final TupleValue nestedTuple2Value = metadata.newTupleType(cint(), list(text())).newValue(1, asList("1"));

    final Row actual = session.execute("SELECT * FROM entity_complex_types WHERE id = " + id).one();

    assertThat(actual).isNotNull();
    assertThat(actual.getString("codec_on_class")).isEqualTo("ClassAnnotatedByCodec{}");
    final Map<String, Map<Integer, TupleValue>> complexMapNesting = actual.getMap("complex_nesting_map",
            new TypeToken<String>() {
            }, new TypeToken<Map<Integer, TupleValue>>() {
            });
    assertThat(complexMapNesting).containsEntry("{\"list\":[\"list\"],\"map\":{\"1\":\"1\"},\"name\":\"name\"}",
            ImmutableMap.of(1, tupleValue));
    assertThat(actual.getString("consistencylevel")).isEqualTo("EACH_QUORUM");
    assertThat(actual.getString("integer")).isEqualTo("123");
    assertThat(actual.getString("json_map")).isEqualTo("{\"1\":[1,2,3]}");
    assertThat(actual.getList("list_nesting", new TypeToken<Map<Integer, String>>() {
    })).containsExactly(ImmutableMap.of(1, "one"));
    final UDTValue foundUDT = actual.getUDTValue("simple_udt");
    assertThat(foundUDT.getString("name")).isEqualTo("name");
    assertThat(foundUDT.getList("list", String.class)).containsExactly("list");
    assertThat(foundUDT.getMap("map", String.class, String.class)).containsEntry("1", "1");
    assertThat(actual.getList("list_udt", UDTValue.class)).containsExactly(foundUDT);
    assertThat(actual.getMap("map_udt", Integer.class, UDTValue.class)).containsEntry(1, foundUDT);
    assertThat(actual.getMap("map_with_nested_json", Integer.class, String.class)).containsEntry(1,
            "[{\"1\":\"one\"}]");
    assertThat(actual.getBool("object_bool")).isTrue();
    assertThat(actual.getByte("object_byte")).isEqualTo((byte) 5);
    assertThat(actual.getBytes("object_byte_array")).isEqualTo(ByteBuffer.wrap(new byte[] { (byte) 7 }));
    assertThat(actual.getSet("ok_set", Integer.class)).containsExactly(6, 10);
    assertThat(actual.getBool("primitive_bool")).isTrue();
    assertThat(actual.getByte("primitive_byte")).isEqualTo((byte) 3);
    assertThat(actual.getBytes("primitive_byte_array")).isEqualTo(ByteBuffer.wrap(new byte[] { (byte) 4 }));
    assertThat(actual.getString("time")).isEqualTo(buildDate().getTime() + "");
    assertThat(actual.getUUID("timeuuid")).isEqualTo(timeuuid);
    assertThat(actual.getTupleValue("tuple1").get(0, String.class)).isEqualTo("\"THREE\"");
    assertThat(actual.getTupleValue("tuple2").get(0, String.class)).isEqualTo("\"TWO\"");
    assertThat(actual.getTupleValue("tuple2").get(1, String.class)).isEqualTo("2");
    assertThat(actual.getTupleValue("tuple_nesting")).isEqualTo(nestedTuple2Value);
    assertThat(actual.getString("value")).isEqualTo("val");
    assertThat(actual.getInt("intwrapper")).isEqualTo(123);
    assertThat(actual.getString("protocolversion")).isEqualTo("V4");
    assertThat(actual.getInt("encoding")).isEqualTo(1);
    assertThat(actual.get("doublearray", double[].class)).isEqualTo(new double[] { 1.0, 2.0 });
    assertThat(actual.get("floatarray", float[].class)).isEqualTo(new float[] { 3.0f, 4.0f });
    assertThat(actual.get("intarray", int[].class)).isEqualTo(new int[] { 5, 6 });
    assertThat(actual.get("longarray", long[].class)).isEqualTo(new long[] { 7L, 8L });
    assertThat(actual.getList("listoflongarray", long[].class)).containsExactly(new long[] { 9L, 10L });
    assertThat(actual.get("jdkinstant", java.time.Instant.class)).isNotNull();
    assertThat(actual.get("jdklocaldate", java.time.LocalDate.class)).isNotNull();
    assertThat(actual.get("jdklocaltime", java.time.LocalTime.class)).isNotNull();
    assertThat(actual.get("jdkzoneddatetime", java.time.ZonedDateTime.class)).isNotNull();
    assertThat(actual.getInt("protocolversionasordinal")).isEqualTo(1);
    assertThat(actual.isNull("optionalstring")).isTrue();
    assertThat(actual.getString("optionalprotocolversion")).isEqualTo("V3");
    assertThat(actual.getInt("optionalencodingasordinal")).isEqualTo(1);
    assertThat(actual.getList("listofoptional", String.class)).containsExactly("1", "2");
}