wjhk.jupload2.upload.helper
Interface ByteArrayEncoder

All Known Implementing Classes:
ByteArrayEncoderHTTP

public interface ByteArrayEncoder

This interface contains all technical methods to encode data, into a given character encoding. This is especially useful to encode the HTTP output to the server.

Each appendXxxx method returns the current instance. This allows easy concatanation of calls to this class. For instance:

 bae.append(a).appendFileProperty(b, c).append(d);
 

Author:
etienne_sf
See Also:
FileUploadThreadHTTP

Method Summary
 ByteArrayEncoder append(byte[] b)
          Append a stream, to be encoded at the current end of the byte array.
 ByteArrayEncoder append(ByteArrayEncoder bae)
          Append a string, to be encoded at the current end of the byte array.
 ByteArrayEncoder append(int b)
          Append a byte, to be encoded at the current end of the byte array. he byte to be written is the eight low-order bits of the argument b.
 ByteArrayEncoder append(java.lang.String str)
          Append a string, to be encoded at the current end of the byte array.
 ByteArrayEncoder appendEndPropertyList()
          Finish a property list.
 ByteArrayEncoder appendFormVariables(java.lang.String formname)
          Add to the current encoder all properties contained in the given HTML form.
 ByteArrayEncoder appendTextProperty(java.lang.String name, java.lang.String value, int index)
          Append a property, name and value.
 void close()
          Closes the encoding writer, and prepares the encoded length and byte array.
 java.lang.String getBoundary()
          Gets the HTTP boundary, that separate the form variables.
 byte[] getEncodedByteArray()
          Get the encoded result.
 int getEncodedLength()
          Get the length of the encoded result.
 java.lang.String getEncoding()
           
 java.lang.String getString()
          Get the String that matches the encoded result.
 boolean isClosed()
           
 

Method Detail

close

void close()
           throws JUploadIOException
Closes the encoding writer, and prepares the encoded length and byte array. This method must be called before call to getEncodedLength() and getEncodedByteArray(). Note: After a call to this method, you can not append any new data to the encoder.

Throws:
JUploadIOException - Encapsulates any IO Exception

append

ByteArrayEncoder append(java.lang.String str)
                        throws JUploadIOException
Append a string, to be encoded at the current end of the byte array.

Parameters:
str - The string to append and encode.
Returns:
Return the current ByteArrayEncoder, to allow chained call (see explanation, here above).
Throws:
JUploadIOException

append

ByteArrayEncoder append(int b)
                        throws JUploadIOException
Append a byte, to be encoded at the current end of the byte array. he byte to be written is the eight low-order bits of the argument b. The 24 high-order bits of b are ignored.

Parameters:
b - Writes the specified byte to this output stream.
Returns:
Return the current ByteArrayEncoder, to allow chained call (see explanation, here above).
Throws:
JUploadIOException

append

ByteArrayEncoder append(byte[] b)
                        throws JUploadIOException
Append a stream, to be encoded at the current end of the byte array.

Parameters:
b -
Returns:
Return the current ByteArrayEncoder, to allow chained call (see explanation, here above).
Throws:
JUploadIOException

appendTextProperty

ByteArrayEncoder appendTextProperty(java.lang.String name,
                                    java.lang.String value,
                                    int index)
                                    throws JUploadIOException
Append a property, name and value. It will be encoded at the current end of the byte array.
Note: After the last call to appendTextProperty, you should call appendEndPropertyList(), to properly finish the property list. In HTTP mode, it will add the last boundary, at a specific format.

Parameters:
name - Name of the property to be added
value - Value of this property for the current file. It's up to the caller to call this method at the right time.
index - Index of the file concerned by this value. -1 if this is a global parameter.
Returns:
Return the current ByteArrayEncoder, to allow chained call (see explanation, here above).
Throws:
JUploadIOException
See Also:
appendEndPropertyList()

appendEndPropertyList

ByteArrayEncoder appendEndPropertyList()
                                       throws JUploadIOException
Finish a property list. In HTTP mode, the last boundary for the form/multipart content is added. After a call to this method, no more property may be written. If several ByteEncoder are used, it's up to the called to call this mehod only once, for the ByteEncoder that will be written last on the request.

Returns:
Return the current ByteArrayEncoder, to allow chained call (see explanation, here above).
Throws:
JUploadIOException

appendFormVariables

ByteArrayEncoder appendFormVariables(java.lang.String formname)
                                     throws JUploadIOException
Add to the current encoder all properties contained in the given HTML form. There is no index for the current file: all the form parameters are global parameters (index will be set to -1 when calling appendTextProperty(String, String, int).

Parameters:
formname - The HTML form name. This method will get the data from this form, by using the JUploadContext.getApplet() method.
Returns:
Return the current ByteArrayEncoder, to allow chained call (see explanation, here above).
Throws:
JUploadIOException

append

ByteArrayEncoder append(ByteArrayEncoder bae)
                        throws JUploadIOException
Append a string, to be encoded at the current end of the byte array.

Parameters:
bae - The ByteArrayEncoder whose encoding result should be appended to the current encoder. bae must be closed, before being appended.
Returns:
Return the current ByteArrayEncoder, to allow chained call (see explanation, here above).
Throws:
JUploadIOException - This exception is thrown when this method is called on a non-closed encoder.

isClosed

boolean isClosed()
Returns:
the closed

getBoundary

java.lang.String getBoundary()
Gets the HTTP boundary, that separate the form variables.

Returns:
The HTTP boundary, that was generated when the instance was created.

getEncoding

java.lang.String getEncoding()
Returns:
the encoding

getEncodedLength

int getEncodedLength()
                     throws JUploadIOException
Get the length of the encoded result. Can be called only once the encoder has been closed.

Returns:
the encodedLength
Throws:
JUploadIOException - This exception is thrown when this method is called on a non-closed encoder.

getEncodedByteArray

byte[] getEncodedByteArray()
                           throws JUploadIOException
Get the encoded result. Can be called only once the encoder has been closed.

Returns:
the encodedByteArray
Throws:
JUploadIOException - This exception is thrown when this method is called on a non-closed encoder.

getString

java.lang.String getString()
                           throws JUploadIOException
Get the String that matches the encoded result. Can be called only once the encoder has been closed.

Returns:
the String that has been encoded.
Throws:
JUploadIOException - This exception is thrown when this method is called on a non-closed encoder.