com.bytecream.codec
Class Base64EncoderNIO

java.lang.Object
  extended bycom.bytecream.codec.Base64EncoderNIO

public final class Base64EncoderNIO
extends java.lang.Object

Provides a set of static methods to encode a ByteBuffer or a ByteChannel with the Base64 algorithm.

The methods encodeXXXWithLineSeparator(...) uses the system line separator provided by System.getProperty("line.separator"). This line separator must be CRLF or a string of length 1.

For the best performance, use this library in server mode and disable assertions.
java -server ...


Method Summary
static java.nio.ByteBuffer encodeToByteBufferWithCRLF(java.nio.ByteBuffer _data, boolean _end, boolean _direct)
          Encodes the remaining bytes of a ByteBuffer, inserting a CRLF every 76 characters.
static java.nio.ByteBuffer encodeToByteBufferWithCRLF(java.nio.ByteBuffer _data, int _length, boolean _end, boolean _direct)
          Encodes a given number of bytes of a ByteBuffer, inserting a CRLF every 76 characters.
static java.nio.ByteBuffer encodeToByteBufferWithLineSeparator(java.nio.ByteBuffer _data, boolean _end, boolean _direct)
          Encodes the remaining bytes of a ByteBuffer, inserting a line separator every 76 characters.
static java.nio.ByteBuffer encodeToByteBufferWithLineSeparator(java.nio.ByteBuffer _data, int _length, boolean _end, boolean _direct)
          Encodes a given number of bytes of a ByteBuffer, inserting a line separator every 76 characters.
static java.nio.ByteBuffer encodeToByteBufferWithoutSeparator(java.nio.ByteBuffer _data, boolean _direct)
          Encodes the remaining bytes of a ByteBuffer.
static java.nio.ByteBuffer encodeToByteBufferWithoutSeparator(java.nio.ByteBuffer _data, int _length, boolean _direct)
          Encodes a given number of bytes of a ByteBuffer.
static void encodeWithCRLF(java.nio.ByteBuffer _data, java.nio.ByteBuffer _output, boolean _end)
          Encodes the remaining bytes of a ByteBuffer, inserting a CRLF every 76 characters.
static void encodeWithCRLF(java.nio.ByteBuffer _data, int _length, java.nio.ByteBuffer _output, boolean _end)
          Encodes a given number of bytes of a ByteBuffer, inserting a CRLF every 76 characters.
static void encodeWithCRLF(java.nio.channels.ReadableByteChannel _input, java.nio.channels.WritableByteChannel _output)
          Encodes the data read from a byte channel and write it on a byte channel, inserting a CRLF every 76 characters.
static void encodeWithLineSeparator(java.nio.ByteBuffer _data, java.nio.ByteBuffer _output, boolean _end)
          Encodes the remaining bytes of a ByteBuffer, inserting a line separator every 76 characters.
static void encodeWithLineSeparator(java.nio.ByteBuffer _data, int _length, java.nio.ByteBuffer _output, boolean _end)
          Encodes a given number of bytes of a ByteBuffer, inserting a line separator every 76 characters.
static void encodeWithLineSeparator(java.nio.channels.ReadableByteChannel _input, java.nio.channels.WritableByteChannel _output)
          Encodes the data read from a byte channel and write it on a byte channel, inserting a line separator every 76 characters.
static void encodeWithoutSeparator(java.nio.ByteBuffer _data, java.nio.ByteBuffer _output)
          Encodes the remaining bytes of a ByteBuffer.
static void encodeWithoutSeparator(java.nio.ByteBuffer _data, int _length, java.nio.ByteBuffer _output)
          Encodes a given number of bytes of a ByteBuffer.
static void encodeWithoutSeparator(java.nio.channels.ReadableByteChannel _input, java.nio.channels.WritableByteChannel _output)
          Encodes the data read from a byte channel and write it on a byte channel.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encodeToByteBufferWithCRLF

public static final java.nio.ByteBuffer encodeToByteBufferWithCRLF(java.nio.ByteBuffer _data,
                                                                   boolean _end,
                                                                   boolean _direct)
Encodes the remaining bytes of a ByteBuffer, inserting a CRLF every 76 characters.

Parameters:
_data - the buffer of bytes to read.
_end - if true add a CRLF at the end.
_direct - if true return a direct buffer.
Returns:
a new buffer with the encoded data.

encodeToByteBufferWithCRLF

public static final java.nio.ByteBuffer encodeToByteBufferWithCRLF(java.nio.ByteBuffer _data,
                                                                   int _length,
                                                                   boolean _end,
                                                                   boolean _direct)
Encodes a given number of bytes of a ByteBuffer, inserting a CRLF every 76 characters.

Parameters:
_data - the buffer of bytes to read.
_length - the number of bytes to read.
_end - if true add a CRLF at the end.
_direct - if true return a direct buffer.
Returns:
a new buffer with the encoded data.

encodeToByteBufferWithLineSeparator

public static final java.nio.ByteBuffer encodeToByteBufferWithLineSeparator(java.nio.ByteBuffer _data,
                                                                            boolean _end,
                                                                            boolean _direct)
Encodes the remaining bytes of a ByteBuffer, inserting a line separator every 76 characters.

Parameters:
_data - the buffer of bytes to read.
_end - if true add a line separator at the end.
_direct - if true return a direct buffer.
Returns:
a new buffer with the encoded data.

encodeToByteBufferWithLineSeparator

public static final java.nio.ByteBuffer encodeToByteBufferWithLineSeparator(java.nio.ByteBuffer _data,
                                                                            int _length,
                                                                            boolean _end,
                                                                            boolean _direct)
Encodes a given number of bytes of a ByteBuffer, inserting a line separator every 76 characters.

Parameters:
_data - the buffer of bytes to read.
_length - the number of bytes to read.
_end - if true add a line separator at the end.
_direct - if true return a direct buffer.
Returns:
a new buffer with the encoded data.

encodeToByteBufferWithoutSeparator

public static final java.nio.ByteBuffer encodeToByteBufferWithoutSeparator(java.nio.ByteBuffer _data,
                                                                           boolean _direct)
Encodes the remaining bytes of a ByteBuffer. No separator is inserted. separator every 76 characters.

Parameters:
_data - the buffer of bytes to read.
_direct - if true return a direct buffer.
Returns:
a new buffer with the encoded data.

encodeToByteBufferWithoutSeparator

public static final java.nio.ByteBuffer encodeToByteBufferWithoutSeparator(java.nio.ByteBuffer _data,
                                                                           int _length,
                                                                           boolean _direct)
Encodes a given number of bytes of a ByteBuffer. No separator is inserted.

Parameters:
_data - the buffer of bytes to read.
_length - the number of bytes to read.
_direct - if true return a direct buffer.
Returns:
a new buffer with the encoded data.

encodeWithCRLF

public static final void encodeWithCRLF(java.nio.ByteBuffer _data,
                                        java.nio.ByteBuffer _output,
                                        boolean _end)
Encodes the remaining bytes of a ByteBuffer, inserting a CRLF every 76 characters.

Parameters:
_data - the buffer of bytes to read.
_output - the buffer of bytes to write.
_end - if true add a CRLF at the end.

encodeWithCRLF

public static final void encodeWithCRLF(java.nio.ByteBuffer _data,
                                        int _length,
                                        java.nio.ByteBuffer _output,
                                        boolean _end)
Encodes a given number of bytes of a ByteBuffer, inserting a CRLF every 76 characters.

Parameters:
_data - the buffer of bytes to read.
_length - the number of bytes to read.
_output - the buffer of bytes to write.
_end - if true add a CRLF at the end.

encodeWithLineSeparator

public static final void encodeWithLineSeparator(java.nio.ByteBuffer _data,
                                                 java.nio.ByteBuffer _output,
                                                 boolean _end)
Encodes the remaining bytes of a ByteBuffer, inserting a line separator every 76 characters.

Parameters:
_data - the buffer of bytes to read.
_output - the buffer of bytes to write.
_end - if true add a CRLF at the end.

encodeWithLineSeparator

public static final void encodeWithLineSeparator(java.nio.ByteBuffer _data,
                                                 int _length,
                                                 java.nio.ByteBuffer _output,
                                                 boolean _end)
Encodes a given number of bytes of a ByteBuffer, inserting a line separator every 76 characters.

Parameters:
_data - the buffer of bytes to read.
_length - the number of bytes to read.
_output - the buffer of bytes to write.
_end - if true add a line separator at the end.

encodeWithoutSeparator

public static final void encodeWithoutSeparator(java.nio.ByteBuffer _data,
                                                java.nio.ByteBuffer _output)
Encodes the remaining bytes of a ByteBuffer. No separator is inserted.

Parameters:
_data - the buffer of bytes to read.
_output - the buffer of bytes to write.

encodeWithoutSeparator

public static final void encodeWithoutSeparator(java.nio.ByteBuffer _data,
                                                int _length,
                                                java.nio.ByteBuffer _output)
Encodes a given number of bytes of a ByteBuffer. No separator is inserted.

Parameters:
_data - the buffer of bytes to read.
_length - the number of bytes to read.
_output - the buffer of bytes to write.

encodeWithCRLF

public static final void encodeWithCRLF(java.nio.channels.ReadableByteChannel _input,
                                        java.nio.channels.WritableByteChannel _output)
                                 throws java.io.IOException
Encodes the data read from a byte channel and write it on a byte channel, inserting a CRLF every 76 characters. There is always a CRLF written at the end except if there is no input.

Parameters:
_input - the byte channel to read.
_output - the byte channel to write on.
Throws:
java.io.IOException - if an I/O error occurs.

encodeWithLineSeparator

public static final void encodeWithLineSeparator(java.nio.channels.ReadableByteChannel _input,
                                                 java.nio.channels.WritableByteChannel _output)
                                          throws java.io.IOException
Encodes the data read from a byte channel and write it on a byte channel, inserting a line separator every 76 characters. There is always a line separator written at the end except if there is no input.

Parameters:
_input - the byte channel to read.
_output - the byte channel to write on.
Throws:
java.io.IOException - if an I/O error occurs.

encodeWithoutSeparator

public static final void encodeWithoutSeparator(java.nio.channels.ReadableByteChannel _input,
                                                java.nio.channels.WritableByteChannel _output)
                                         throws java.io.IOException
Encodes the data read from a byte channel and write it on a byte channel. No separator is inserted.

Parameters:
_input - the byte channel to read.
_output - the byte channel to write on.
Throws:
java.io.IOException - if an I/O error occurs.



Copyright © 2004 ByteCream.
All Rights Reserved.