NetCode Component

Properties   Methods   Events   Config Settings   Errors  

The NetCode component can be used to encode or decode files or strings using a variety of popular encoding formats, such as Base64, UUencode, and URL. UUEncode , MIME's Base64 Quoted-Printable , and URL encoding formats, as well as secure hash functions such as MD5 and SHA1, are currently supported.

Syntax

IPWorks.Netcode

Remarks

The encoding format is specified by the Format property. The binary data, or the name of the file containing binary data, is specified by the DecodedData property and the encoded data or filename is specified by the EncodedData property. The FileName property may be used to override the default file names or to specify a directory during uuencoding. After uudecoding, the FileName property contains the fully specified file name of the decoded file.

Understanding Encoding/Decoding

Most mail systems use only 7 bits to transmit messages. A binary file, such as an archive or a non-plaintext-formatted file produced from a text processor should be first encoded in 7-bit code before email transfer.

Decoding is the inverse process (i.e., creation of the original file from the encoded data). Encoded data are often split over several files because of the size limit placed on the email message. Each message is preceded by information about this splitting, as well as the mail header. NetCode supports this case in both directions:

- During encoding, setting the MaxFileSize configuration setting to the maximum size of a message body instructs NetCode to split the encoded data over several files. Multiple filenames can be specified by using question marks "?" (see the EncodedData property for more information).

- During decoding, the body messages can be saved in separate files named namexxx.ext, where xxx is a numeral starting at 000 and ext is ".uue", ".b16", or ".q_p" according to Format. These multiple filenames should be given to EncodedData.

Property List


The following is the full list of the properties of the component with short descriptions. Click on the links for further details.

DecodedDataThis property includes the decoded data.
DecodedFileThis property includes the filename of the decoded data.
EncodedDataThis property includes the encoded data.
EncodedFileThis property includes the filename of the encoded data.
FileCntThis property shows the number of encoded files the component has read from or written into.
FileNameThis property includes the destination filename for the encoded data.
FormatThis property includes the type of encoding to be used.
ModeThis property includes the UNIX-style filemode when uuencoding and uudecoding.
OverwriteThis property controls whether created file(s) should overwrite already existing file(s).
ProgressStepThis property controls the granularity at which the Progress event is fired. Values are 0-100.

Method List


The following is the full list of the methods of the component with short descriptions. Click on the links for further details.

configSets or retrieves a configuration setting.
decodeThis method decodes a string.
encodeThis method encodes the data.
resetReset the component.
resetDataThis method resets the values of all data and stream properties.
setInputStreamThis method sets the input stream of data.
setOutputStreamThis method sets the output stream of data.

Event List


The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.

ErrorInformation about errors during data delivery.
ProgressThis event occurs when PercentDone of the input is read.

Config Settings


The following is a list of config settings for the component with short descriptions. Click on the links for further details.

Base64LineBreakTells the component whether to include line breaks in Base64 encoded content or not.
EncodeHashWhether the hash value is hex encoded.
HMACAlgorithmThe hash algorithm to use when generating a Hash-based Message Authentication Code (HMAC).
HMACKeyA key to use when generating a Hash-based Message Authentication Code (HMAC).
MaxFileSizeWhen encoding, controls whether encoded data should be split into several files and gives the maximum allowed size for these files.
UseExtendedHexBase32Specifies whether or not the Extended Hex alphabet is used.
UseModifiedUTF7Specifies whether or not a modified form of UTF-7 for IMAP mailbox naming is used.
BuildInfoInformation about the product's build.
GUIAvailableTells the component whether or not a message loop is available for processing events.
LicenseInfoInformation about the current license.
MaskSensitiveWhether sensitive data is masked in log messages.
UseDaemonThreadsWhether threads created by the component are daemon threads.
UseInternalSecurityAPITells the component whether or not to use the system security libraries or an internal implementation.

DecodedData Property (NetCode Component)

This property includes the decoded data.

Syntax


public byte[] getDecodedData();


public void setDecodedData(byte[] decodedData);

Default Value

""

Remarks

This property contains the decoded data. When uuencoding, the value of FileName is the filename that will be written in EncodedData. If FileName is empty, an error will be returned.

This property is not available at design time.

DecodedFile Property (NetCode Component)

This property includes the filename of the decoded data.

Syntax


public String getDecodedFile();


public void setDecodedFile(String decodedFile);

Default Value

""

Remarks

This property contains the filename of the decoded data. When uuencoding, the value of FileName is the filename that will be written in EncodedData. If FileName is empty, the value of the DecodedFile property is taken, if a valid file has been specified. It is recommended that EncodedData contains the full path and that FileName contains only the filename so that no problems occur while uudecoding in a foreign system.

When decoding, the component tries to generate the name for the created file in the following order: DecodedFile, FileName, or when the format is UUEncode, the specified filename in the uuencoded data. If DecodedFile or FileName end with a backslash "\" they are interpreted as directories, and the component will try to create the given filename in this directory. If this is the case, FileName shows the name of the file that was created.

EncodedData Property (NetCode Component)

This property includes the encoded data.

Syntax


public byte[] getEncodedData();


public void setEncodedData(byte[] encodedData);

Default Value

""

Remarks

This property contains the data that either have been encoded or are set to be decoded.

This property is not available at design time.

EncodedFile Property (NetCode Component)

This property includes the filename of the encoded data.

Syntax


public String getEncodedFile();


public void setEncodedFile(String encodedFile);

Default Value

""

Remarks

This property contains the filename of the encoded data. If the encoded data are spread over several files, the filenames are passed to EncodedFile in the form name?. Question marks "?" are expanded to numerals starting with 0. The filenames should exist as path\file000.ext and are passed to EncodedFile in the form name???. Question marks "?" are expanded to numerals starting with 000 (the number of zeros "0" equals that of question marks "?").

The component appends the extension ".uue", ".b16", or ".q_p" depending on Format immediately after the generated numbers. FileCnt contains the number of encoded files.

See also the Format property, and the MaxFileSize configuration setting when working with multiple files.

FileCnt Property (NetCode Component)

This property shows the number of encoded files the component has read from or written into.

Syntax


public int getFileCnt();


Default Value

0

Remarks

This property shows the number of encoded files the component has read from or written into. If the user specifies one or more questions marks "?" in EncodedFile, they will be expanded from 000 to FileCnt - 1 (the number of question marks "?" specifies the number of figures).

Please refer to EncodedFile for filename conventions.

This property is read-only.

FileName Property (NetCode Component)

This property includes the destination filename for the encoded data.

Syntax


public String getFileName();


public void setFileName(String fileName);

Default Value

""

Remarks

This property contains the destination filename for the encoded data. When uuencoding, this property contains the filename that is specified in the uuencoded data.

When decoding, if the value of the property is not empty, it shows the component where to write the decoded data. It can be either the filename or the directory where the file should be written. If is should be written to a directory, it should end with a backslash "\".

After a decode operation, this property contains the filename for the created file. If the file couldn't be created because of an illegal filename, examining this property might provide a hint about the reason of the failure.

This property must be set to "" (empty string) after each decode operation because it contains the full specification of the file.

An error occurs if a uuencoding operation is initiated with an empty FileName.

If you want to first check the uuencoded filename before creating it on disk, you may assign an illegal directory name to this property (always use a closing backslash "\" to denote it as a directory), then trap the error and check the filename appended to this property.

Format Property (NetCode Component)

This property includes the type of encoding to be used.

Syntax


public int getFormat();


public void setFormat(int format);

Enumerated values:
  public final static int fmtUUEncode = 0;

  public final static int fmtBase64 = 1;

  public final static int fmtQP = 2;

  public final static int fmtURL = 3;

  public final static int fmtJIS = 4;

  public final static int fmtYEncode = 5;

  public final static int fmtMD5Hash = 6;

  public final static int fmtSHA1Hash = 7;

  public final static int fmtHex = 8;

  public final static int fmtHTML = 9;

  public final static int fmtHMAC = 10;

  public final static int fmtUTF8 = 11;

  public final static int fmtUTF7 = 12;

  public final static int fmtBase32 = 13;

  public final static int fmtBase64URL = 14;

  public final static int fmtSHA256Hash = 15;

  public final static int fmtPunycode = 16;

Default Value

0

Remarks

This property contains the type of encoding to be used. The following are the possible values for this property, and the corresponding descriptions:

fmtUUEncode (0)3 Bytes are encoded into 4 readable characters. If multiple filenames are specified, then the extension ".uue" is used/expected.
fmtBase64 (1)Encoding format of MIME. This is much like UUEncode but another subset of printable characters is used. If multiple filenames are specified, then the extension ".b64" is used/expected.
fmtQP (2)Quoted-Printable is another MIME format coding only special characters. It is mostly used if the text contains special accented characters. If multiple filenames are specified, then the extension ".q_p" is used/expected.
fmtURL (3)Encoding of nonprintable, 8-bit or unsafe characters as defined in RFC 1738. (No multiple filenames can be specified with this encoding.)
fmtJIS (4)Japanese Industrial Standards encoding of Japanese character sets.
fmtYEncode (5)Similar to Base64, but uses 8-bit encoding to reduce the amount of data being sent and received. Designed for binaries on the Usenet or Email.
fmtMD5Hash (6)The Message Digest 5 hashing algorithm produces a 128-bit hash output.
fmtSHA1Hash (7)The Secure Hash Algorithm produces a 128-bit hash output.
fmtHex (8)Creates a hexadecimal string representation of the decoded data.
fmtHTML (9)Creates an HTML-encoded string. Supports decimal, hex, and named HTML character representations.
fmtHMAC (10)Creates a Hash-based Message Authentication Code for the given data. To set the key, use HMACKey. To set the hash algorithm to use to create the MAC, use HMACAlgorithm.
fmtUTF8 (11)Converts strings to/from UTF-8 to the current code page (Windows only).
fmtUTF7 (12)Converts strings to/from UTF-7 to the current code page (Windows only).
fmtBase32 (13)Similar to Base64, but uses 32 printable characters. If multiple filenames are specified, then the extension ".b32" is used/expected.
fmtBase64URL (14)Base64 encoding for use within URLs. The "+" character is replaced with "-". The "/" character is replaced with "_". The padding character "=" is omitted.
fmtSHA256 (15)The Secure Hash Algorithm 2 produces a 256-bit hash output.
fmtPunycode (16)Converts string to/from Punycode. The configuration setting must be set to a value capable of interpreting the non-ASCII character data being encoded/decoded. For instance .

Mode Property (NetCode Component)

This property includes the UNIX-style filemode when uuencoding and uudecoding.

Syntax


public String getMode();


public void setMode(String mode);

Default Value

"0755"

Remarks

This property contains the UNIX-style filemode when uuencoding and uudecoding. The filemode is usually an octal number, such as 755 or 600, which gives the protections of that file. If the file to uudecode is correctly read, then this property contains the protection string given in the uuencoded data.

This is given for compatibility with other systems and is used only when Format is fmtUUE.

Overwrite Property (NetCode Component)

This property controls whether created file(s) should overwrite already existing file(s).

Syntax


public boolean isOverwrite();


public void setOverwrite(boolean overwrite);

Default Value

False

Remarks

This property controls whether created file(s) should overwrite already existing file(s).

Note: More than one file may be created during uuencoding.

ProgressStep Property (NetCode Component)

This property controls the granularity at which the Progress event is fired. Values are 0-100.

Syntax


public int getProgressStep();


public void setProgressStep(int progressStep);

Default Value

1

Remarks

This property controls the granularity at which the Progress event is fired. Values are 0-100. If this property is not 0, the Progress event will be fired when 0%, n* ProgressStep and 100% of input data are read.

If this property is 0, the Progress event is disabled.

Config Method (Netcode Component)

Sets or retrieves a configuration setting.

Syntax

public String config(String configurationString);

Remarks

Config is a generic method available in every component. It is used to set and retrieve configuration settings for the component.

These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).

To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.

Decode Method (Netcode Component)

This method decodes a string.

Syntax

public void decode();

Remarks

This method decodes according to the Format type. The component will decode the data in the input stream if SetInputStream has been set to a valid stream. If this stream is null, the component will then try to read the data from the file set by the EncodedFile property. If no valid file has been specified, the component will use the EncodedData property.

The resulting decoded data are written to the output stream if one has been set. If not, the component will attempt to write the decoded data to the DecodedFile. If no file was specified, the decoded data may be retrieved through the DecodedData property.

When UUDecoding the created filename will by default be the one specified in the uuencoded data. The FileName property will contain this value. DecodedFile or, if DecodedFile is empty, FileName can be used to override this value.

When YDecoding, the source path and filename is specified in EncodedFile and the destination path and filename in DecodedFile. If the encoded data indicate the name of the original file before decoding, this value will be stored in the FileName property. To decode a multipart message, all parts must be concatenated in order in the source file.

Encode Method (Netcode Component)

This method encodes the data.

Syntax

public void encode();

Remarks

This method encodes the data according to the Format type. The component will encode the data in the input stream if SetInputStream has been set to a valid stream. If this stream is null, the component will then try to read the data from the file set by the DecodedFile property. If no valid file has been specified, the component will use the DecodedData property.

The resulting encoded data are written to the output stream if one has been set. If not, the component will attempt to write the encoded data to the EncodedFile. If no file was specified, the encoded data may be retrieved through the EncodedData property.

The data are considered binary while uuencoding and Base64 Formats, and text during QuotedPrintable ones.

When uuencoding or yencoding, the filename encoded into the data is taken from the FileName property.

The current version of NetCode does not create message headers. If a MIME standard encoding is used, such as Base64 Encoding or Quoted Printable Encoding, the user should fill the header values appropriately.

If EncodedFile and MaxFileSize is set and the encoded data take more space than MaxFileSize, the data are split over several files. In this case, the user can specify more than one filename by passing them to EncodedFile in the form name?. The filenames should exist as path\file0.ext, path\file1.ext ... Question marks "?" are expanded to numerals starting with 0. NetCode appends the extension ".uue", ".b16", or ".q_p" (depending on the value of Format) to the filename.

Reset Method (Netcode Component)

Reset the component.

Syntax

public void reset();

Remarks

This method will reset the component's properties to their default values.

ResetData Method (Netcode Component)

This method resets the values of all data and stream properties.

Syntax

public void resetData();

Remarks

This method resets the values of all data and stream properties. It is an easy way to reset the component's properties before another call to Encode or Decode. The input and output streams and the data and file properties will all be reset.

SetInputStream Method (Netcode Component)

This method sets the input stream of data.

Syntax

public void setInputStream(java.io.InputStream inputStream);

Remarks

Use this method to set the input stream of data for the component to read from. If Encode or Decode is called, and this is not null, the data will be read from this stream when the specified action occurs. You may reset this by calling ResetData.

SetOutputStream Method (Netcode Component)

This method sets the output stream of data.

Syntax

public void setOutputStream(java.io.OutputStream outputStream);

Remarks

Use this method to set the output stream of data for the component to write. If Encode or Decode is called, and this is not null, the data will be written to this stream when the specified action occurs. You may reset this by calling ResetData.

Error Event (Netcode Component)

Information about errors during data delivery.

Syntax

public class DefaultNetcodeEventListener implements NetcodeEventListener {
  ...
  public void error(NetcodeErrorEvent e) {}
  ...
}

public class NetcodeErrorEvent {
  public int errorCode;

  public String description;

}

Remarks

The Error event is fired in case of exceptional conditions during message processing. Normally the component throws an exception.

ErrorCode contains an error code and Description contains a textual description of the error. For a list of valid error codes and their descriptions, please refer to the Error Codes section.

Progress Event (Netcode Component)

This event occurs when PercentDone of the input is read.

Syntax

public class DefaultNetcodeEventListener implements NetcodeEventListener {
  ...
  public void progress(NetcodeProgressEvent e) {}
  ...
}

public class NetcodeProgressEvent {
  public int percentDone;

}

Remarks

The ProgressStep property determines how often the event is fired.

Config Settings (Netcode Component)

The component accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.

NetCode Config Settings

Base64LineBreak:   Tells the component whether to include line breaks in Base64 encoded content or not.

By default, when encoding to Base64 format, the component will insert line breaks every 76 characters. Setting the Base64LineBreak configuration setting to False will cause these line breaks to be omitted from the Base64 encoded content. The default value is True.

EncodeHash:   Whether the hash value is hex encoded.

This setting determines whether the MD5, SHA1, or SHA256 hash value is hex encoded. When calling Encode, if this setting is True (default), the hash value created will be hex encoded. When set to False, the output will not be hex encoded and will be binary. This is applicable only to the following formats:

  • MD5
  • SHA1
  • SHA256

HMACAlgorithm:   The hash algorithm to use when generating a Hash-based Message Authentication Code (HMAC).

HMACAlgorithm is used to tell the component which hashing algorithm to use to generate the Hash-based Message Authentication Code (HMAC). HMACAlgorithm can be "SHA1" (Secure Hash Algorithm 1), "MD5" (Message Digest 5), or one of the SHA-2 algorithms mentioned next. You may truncate the hash output by specifying the desired number of bits. For instance, "SHA1-96" and "MD5-96" are acceptable.

The component is capable of utilizing the set of HMAC SHA-2 algorithms ("SHA-224", "SHA-256", "SHA-384", and "SHA-512").

The component also supports "RIPEMD160" as an HMAC algorithm.

HMACKey:   A key to use when generating a Hash-based Message Authentication Code (HMAC).

When using the Format fmtHMAC, it may be necessary to supply the component with a key to use when generating the Hash-based Message Authentication Code (HMAC). This key is incorporated into the hashing process to add entropy to the resulting hash code, making the plaintext harder to guess and increasing the message security. You may also set this to a hex value. For instance, 0xAAAAAA is acceptable.

MaxFileSize:   When encoding, controls whether encoded data should be split into several files and gives the maximum allowed size for these files.

Some mailing systems require that the message size should not exceed a certain size. Assigning a nonzero value to MaxFileSize makes the component split the encoded data into several files. FileCnt will contain the number of files created. Please refer to EncodedFile for filename conventions.

The default value for this setting is 0 (no limit).

Note: If a non-zero value is assigned to MaxFileSize, then a multiple filename should also be assigned to EncodedFile (end with question marks "?") so that the component can expand the filenames.

Please refer to the Error Codes section for a complete list of possible errors.

UseExtendedHexBase32:   Specifies whether or not the Extended Hex alphabet is used.

When Format is set to fmtBase32, UseExtendedHexBase32 is used to tell the component whether or not to use the extended hex alphabet. The default value is False.

UseModifiedUTF7:   Specifies whether or not a modified form of UTF-7 for IMAP mailbox naming is used.

When Format is set to fmtUTF7, UseModifiedUTF7 is used to tell the component whether or not to use a modified version of UTF-7 for IMAP mailbox naming. The default value is False.

Base Config Settings

BuildInfo:   Information about the product's build.

When queried, this setting will return a string containing information about the product's build.

GUIAvailable:   Tells the component whether or not a message loop is available for processing events.

In a GUI-based application, long-running blocking operations may cause the application to stop responding to input until the operation returns. The component will attempt to discover whether or not the application has a message loop and, if one is discovered, it will process events in that message loop during any such blocking operation.

In some non-GUI applications, an invalid message loop may be discovered that will result in errant behavior. In these cases, setting GUIAvailable to false will ensure that the component does not attempt to process external events.

LicenseInfo:   Information about the current license.

When queried, this setting will return a string containing information about the license this instance of a component is using. It will return the following information:

  • Product: The product the license is for.
  • Product Key: The key the license was generated from.
  • License Source: Where the license was found (e.g., RuntimeLicense, License File).
  • License Type: The type of license installed (e.g., Royalty Free, Single Server).
  • Last Valid Build: The last valid build number for which the license will work.
MaskSensitive:   Whether sensitive data is masked in log messages.

In certain circumstances it may be beneficial to mask sensitive data, like passwords, in log messages. Set this to true to mask sensitive data. The default is true.

This setting only works on these components: AS3Receiver, AS3Sender, Atom, Client(3DS), FTP, FTPServer, IMAP, OFTPClient, SSHClient, SCP, Server(3DS), Sexec, SFTP, SFTPServer, SSHServer, TCPClient, TCPServer.

UseDaemonThreads:   Whether threads created by the component are daemon threads.

If set to True (default), when the component creates a thread, the thread's Daemon property will be explicitly set to True. When set to False, the component will not set the Daemon property on the created thread. The default value is True.

UseInternalSecurityAPI:   Tells the component whether or not to use the system security libraries or an internal implementation.

When set to false, the component will use the system security libraries by default to perform cryptographic functions where applicable.

Setting this setting to true tells the component to use the internal implementation instead of using the system security libraries.

This setting is set to false by default on all platforms.

Trappable Errors (Netcode Component)

NetCode Errors

1   Short uuencoded file.
2   The closing 'end' was not found (uudecoded file may be too short).
3   Cannot create the file for write (illegal name or disk is write-protected).
4   Cannot open the file for read (does not exist?).
5   Cannot read from file.
6   Cannot write to file (disk full?).
7   Please supply a filename for uuencoded data.
8   File exists and Overwrite was set to False.
9   Space is not sufficient in the output string.
10   The given filenames are insufficient to split all the encoded data.
11   Please supply a filename for the encoded data.
12   Encoded data cannot be written in more than 100 files.
13   Could not write to file. Permission denied.
14   Could not write to file. Disk full.
15   Too many open files. No more file handles are available, so no more files can be opened.
16   The given filename does not exist.
17   There are no more files to read from or write to.
18   The starting 'begin' was not found. Is it uuencoded data?
19   The current format is not supported.
20   The specified stream does not support Available().
21   Format error when YDecoding.
22   No '=yend' found when YDecoding.
23   Escape character found at end of line when YDecoding.
24   CRC check failed when YDecoding (Corrupt data).
25   Output buffer length was not calculated.
26   Invalid character in Base64 data.