Base64Decoder provides two interfaces for performing base64 decoding.
A high-level interface decodes from an input String to an output String. This interface comprises a single member function, decode().
A low-level interface allows decoding by passing multiple buffers to the decoder. The correct procedure for using this interface is described below.
Using the Low-Level Interface
The low-level interface allows you to decode data one buffer at a time; thus you may decode data of unlimited size using a limited amount of memory. For example, if you want to decode data from an input file to an output file, you may read from the input file one buffer at a time, pass each buffer to the decoder, and write to the output file one buffer at a time.
The low-level interface comprises two member functions: start() and decodeSegment(). The procedure is described here:
inBuf, set inBuf.chars to a char array that contains the data to be decoded, set inBuf.pos to the offset of the beginning of the data in inBuf.chars, and set inBuf.endPos to the offset of the first byte past the end of the data in inBuf.chars. To initialize an output buffer named outBuf, set outBuf.bytes to a char array, set outBuf.pos to zero, and set outBuf.endPos to the length of the array referenced by outBuf.bytes.
outBuf.pos == outBuf.endPos, then the output buffer is full, and you must make room in the output buffer before you call decodeSegment() again. If inBuf.pos == inBuf.endPos, then the input buffer is empty, and you must supply the input buffer with more data before you call decodeSegment() again. If decodeSegment() returns -1, then the decoder has detected a decoding error.
You may use the same decoder object for multiple decode operations.
Dealing With Errors
The decoder correctly decodes all data that is correctly encoded. However, if the data is not correctly encoded, the decoder detects these errors. All decoding errors are treated as fatal errors -- the decoder does not try to recover. The decoder notifies your application of decoding errors by returning -1 from the decodeSegment() member function.
Public Member Functions | |
| Base64Decoder () | |
| Default constructor. | |
| ~Base64Decoder () | |
| Destructor. | |
| void | start () |
| Starts a multiple-buffer decode operation. | |
| int | decodeSegment (CharBuffer *inBuf, ByteBuffer *outBuf) |
| Decodes data from the input buffer to the output buffer. | |
| String | decode (const String &encoded) |
| Performs single-step buffer-to-buffer base64 decoding. | |
|
|
Default constructor. |
|
|
Destructor. |
|
|
Performs single-step buffer-to-buffer base64 decoding. To perform base64 decoding using this function, create a String containing the data you want to decode and pass it as the function's argument. The returned String contains the decoded output. If a decoding error occurs, the function returns an empty string. This member function makes it very simple to perform base64 decoding. The disadvantage of this function is that it requires all the data to be kept in memory for processing. You may use the low-level interface, described in the overview section, to perform base64 decoding of large data using limited memory. This member function uses the low-level interface internally.
|
|
||||||||||||
|
Decodes data from the input buffer to the output buffer. This member function is an essential part of the low-level interface and performs most of the work of decoding for the Base64Decoder class. It takes an input buffer and an output buffer as parameters, and decodes data from the input buffer until the input buffer is empty, the output buffer is full, or a decoding error has been detected. In other words, one of the following conditions is guaranteed to be satisfied when the function returns:
You may call the function multiple times to decode multiple buffers of input data. However, before you call the function, both of the following conditions should be true:
For more information on using the low-level interface, see the overview section for Base64Decoder.
|
|
|
Starts a multiple-buffer decode operation. If you use the low-level interface for multiple-buffer decoding, you must call start() to begin the decode operation. You may use a Base64Decoder instance for many decode operations, but you must call start() to begin each operation. For more information on using the low-level interface, see the overview section for Base64Decoder. You do not need to call this method if you use the decode() member function for decoding. |
Copyright © 2001-2007 Hunny Software, Inc. All rights reserved.