tecgraf.ftc_1_3.utils
Class ByteBufferUtils

java.lang.Object
  extended by tecgraf.ftc_1_3.utils.ByteBufferUtils

public final class ByteBufferUtils
extends Object

Classe utilitária para o tratamento de buffers de bytes ( ByteBuffer).

Todos os métodos desta classe são síncronos, ou seja, ficam travados até que se obtenha a resposta necessária.

Author:
Tecgraf/PUC-Rio

Constructor Summary
ByteBufferUtils()
           
 
Method Summary
static byte readByte(ByteBuffer buffer, ReadableByteChannel channel)
          Lê uma valor do tipo byte.
static long readLong(ByteBuffer buffer, ReadableByteChannel channel)
          Lê uma valor do tipo long.
static void writeByte(ByteBuffer buffer, WritableByteChannel channel, byte value)
          Escreve um valor do tipo byte no canal.
static void writeByte(ByteBuffer buffer, WritableByteChannel channel, int extraBytes, byte value)
          Escreve um valor do tipo byte no canal.
static void writeBytes(ByteBuffer buffer, WritableByteChannel channel, byte[] value)
          Escreve um valor do tipo byte[] no canal.
static void writeBytes(ByteBuffer buffer, WritableByteChannel channel, int extraBytes, byte[] value)
          Escreve um valor do tipo byte[] no canal.
static void writeLong(ByteBuffer buffer, WritableByteChannel channel, int extraBytes, long value)
          Escreve um valor do tipo long no canal.
static void writeLong(ByteBuffer buffer, WritableByteChannel channel, long value)
          Escreve um valor do tipo long no canal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteBufferUtils

public ByteBufferUtils()
Method Detail

readLong

public static long readLong(ByteBuffer buffer,
                            ReadableByteChannel channel)
                     throws IOException
Lê uma valor do tipo long.

Parameters:
buffer - O buffer utilizado na obtenção do valor.
channel - O canal de onde será lido o valor.
Returns:
O valor solicitado.
Throws:
IOException - Caso ocorra algum problema na leitura do valor.

readByte

public static byte readByte(ByteBuffer buffer,
                            ReadableByteChannel channel)
                     throws IOException
Lê uma valor do tipo byte.

Parameters:
buffer - O buffer utilizado na obtenção do valor.
channel - O canal de onde será lido o valor.
Returns:
O valor solicitado.
Throws:
IOException - Caso ocorra algum problema na leitura do valor.

writeByte

public static void writeByte(ByteBuffer buffer,
                             WritableByteChannel channel,
                             byte value)
                      throws IOException
Escreve um valor do tipo byte no canal.

Parameters:
buffer - O buffer utilizado para escrever o valor.
channel - O canal para onde será enviado o valor.
value - O valor.
Throws:
IOException - Caso ocorra algum problema ao escrever o valor.

writeByte

public static void writeByte(ByteBuffer buffer,
                             WritableByteChannel channel,
                             int extraBytes,
                             byte value)
                      throws IOException
Escreve um valor do tipo byte no canal.

É possível enviar valores que já tenham sido inseridos anteriormente no buffer.

Parameters:
buffer - O buffer utilizado para escrever o valor.
channel - O canal para onde será enviado o valor.
extraBytes - Quantos bytes já foram inseridos no buffer anteriormente e que também devem ser enviados.
value - O valor.
Throws:
IOException - Caso ocorra algum problema ao escrever o valor.

writeLong

public static void writeLong(ByteBuffer buffer,
                             WritableByteChannel channel,
                             long value)
                      throws IOException
Escreve um valor do tipo long no canal.

Parameters:
buffer - O buffer utilizado para escrever o valor.
channel - O canal para onde será enviado o valor.
value - O valor.
Throws:
IOException - Caso ocorra algum problema ao escrever o valor.

writeLong

public static void writeLong(ByteBuffer buffer,
                             WritableByteChannel channel,
                             int extraBytes,
                             long value)
                      throws IOException
Escreve um valor do tipo long no canal.

É possível enviar valores que já tenham sido inseridos anteriormente no buffer.

Parameters:
buffer - O buffer utilizado para escrever o valor.
channel - O canal para onde será enviado o valor.
extraBytes - Quantos bytes já foram inseridos no buffer anteriormente e que também devem ser enviados.
value - O valor.
Throws:
IOException - Caso ocorra algum problema ao escrever o valor.

writeBytes

public static void writeBytes(ByteBuffer buffer,
                              WritableByteChannel channel,
                              byte[] value)
                       throws IOException
Escreve um valor do tipo byte[] no canal.

Parameters:
buffer - O buffer utilizado para escrever o valor.
channel - O canal para onde será enviado o valor.
value - O valor.
Throws:
IOException - Caso ocorra algum problema ao escrever o valor.

writeBytes

public static void writeBytes(ByteBuffer buffer,
                              WritableByteChannel channel,
                              int extraBytes,
                              byte[] value)
                       throws IOException
Escreve um valor do tipo byte[] no canal.

É possível enviar valores que já tenham sido inseridos anteriormente no buffer.

Parameters:
buffer - O buffer utilizado para escrever o valor.
channel - O canal para onde será enviado o valor.
extraBytes - Quantos bytes já foram inseridos no buffer anteriormente e que também devem ser enviados.
value - O valor.
Throws:
IOException - Caso ocorra algum problema ao escrever o valor.


Copyright © 2018 Tecgraf/PUC-Rio. All rights reserved.