[ 
https://issues.apache.org/jira/browse/HDDS-14788?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tsz-wo Sze updated HDDS-14788:
------------------------------
    Description: 
As shown in the test below, Guava Ints and Longs are the same as ByteBuffer.  
It is better to just use standard Java library.
{code}
  @Test
  public void testInts() {
    for(int i = 0; i < 1000; i++) {
      final int original = ThreadLocalRandom.current().nextInt();
      final byte[] ints = Ints.toByteArray(original);

      final ByteBuffer buffer = ByteBuffer.allocate(4);
      buffer.putInt(original);
      buffer.flip();
      assertArrayEquals(ints, buffer.array());

      assertEquals(original, Ints.fromByteArray(ints));
      assertEquals(original, buffer.getInt());
    }
  }
{code}

{code}
  @Test
  public void testLongs() {
    for(int i = 0; i < 1000; i++) {
      final long original = ThreadLocalRandom.current().nextLong();
      final byte[] longs = Longs.toByteArray(original);

      final ByteBuffer buffer = ByteBuffer.allocate(8);
      buffer.putLong(original);
      buffer.flip();
      assertArrayEquals(longs, buffer.array());

      assertEquals(original, Longs.fromByteArray(longs));
      assertEquals(original, buffer.getLong());
    }
  }
{code}


  was:
As shown in the test below, Guava Ints is the same as ByteBuffer.  It is better 
to just use standard Java library.
{code}
  @Test
  public void testInts() {
    for(int i = 0; i < 1000; i++) {
      final int original = ThreadLocalRandom.current().nextInt();
      final byte[] ints = Ints.toByteArray(original);

      final ByteBuffer buffer = ByteBuffer.allocate(4);
      buffer.putInt(original);
      buffer.flip();
      assertArrayEquals(ints, buffer.array());

      assertEquals(original, Ints.fromByteArray(ints));
      assertEquals(original, buffer.getInt());
    }
  }
{code}

        Summary: Avoid using guava Ints/Longs to convert byte arrays  (was: 
Avoid using guava Ints to convert byte arrays)

> Avoid using guava Ints/Longs to convert byte arrays
> ---------------------------------------------------
>
>                 Key: HDDS-14788
>                 URL: https://issues.apache.org/jira/browse/HDDS-14788
>             Project: Apache Ozone
>          Issue Type: Sub-task
>          Components: common, SCM HA
>            Reporter: Tsz-wo Sze
>            Priority: Major
>
> As shown in the test below, Guava Ints and Longs are the same as ByteBuffer.  
> It is better to just use standard Java library.
> {code}
>   @Test
>   public void testInts() {
>     for(int i = 0; i < 1000; i++) {
>       final int original = ThreadLocalRandom.current().nextInt();
>       final byte[] ints = Ints.toByteArray(original);
>       final ByteBuffer buffer = ByteBuffer.allocate(4);
>       buffer.putInt(original);
>       buffer.flip();
>       assertArrayEquals(ints, buffer.array());
>       assertEquals(original, Ints.fromByteArray(ints));
>       assertEquals(original, buffer.getInt());
>     }
>   }
> {code}
> {code}
>   @Test
>   public void testLongs() {
>     for(int i = 0; i < 1000; i++) {
>       final long original = ThreadLocalRandom.current().nextLong();
>       final byte[] longs = Longs.toByteArray(original);
>       final ByteBuffer buffer = ByteBuffer.allocate(8);
>       buffer.putLong(original);
>       buffer.flip();
>       assertArrayEquals(longs, buffer.array());
>       assertEquals(original, Longs.fromByteArray(longs));
>       assertEquals(original, buffer.getLong());
>     }
>   }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to