com.pega.pegarules.pub.util
Class PRFileUtil

java.lang.Object
  extended by com.pega.pegarules.pub.util.PRFileUtil

public class PRFileUtil
extends java.lang.Object

PRFileUtil is a utility to handle file encoding formats.

Version:
$Revision: 4116 $
Author:
dassu

Field Summary
static java.lang.String COPYRIGHT
           
static java.lang.String ENCODING_DOWNLOAD
          encoding to use when downloading files
static java.lang.String ENCODING_EXTRACT
          encoding to use when extracting static content
static java.lang.String ENCODING_ISO
          use ISO-8859-1 encoding
static java.lang.String ENCODING_JAVA
          encoding to use with Java files
static java.lang.String ENCODING_PLATFORM
          platform's default encoding
static java.lang.String ENCODING_UPLOAD
          encoding to use when uploading files (ex: Attach)
static java.lang.String ENCODING_XML
          encoding to use with XML files
static java.lang.String JAVA_ENCODING_EBCDIC
          Java encoding name for EBCDIC
static java.lang.String JAVA_ENCODING_ISO
          Java encoding name for ISO
static java.lang.String JAVA_ENCODING_UTF16BE
          Java encoding name for UTF-16 Big Endian
static java.lang.String JAVA_ENCODING_UTF16LE
          Java encoding name for UTF-16 Little Endian
static java.lang.String JAVA_ENCODING_UTF8
          Java encoding name for UTF-8
static byte[] UTF8_BOM
          The UTF-8 byte order mark
static java.lang.String VERSION
           
 
Constructor Summary
PRFileUtil()
           
 
Method Summary
static byte[] getBytes(java.io.InputStream aStream, int aBufferSize)
          Reads aBufferSize number of bytes from the specified InputStream.
static java.lang.String getJavaEncoding(java.lang.String aEncodingType)
          Returns the java encoding for the specified encoding type.
static java.lang.String guessEncoding(byte[] aBuffer, java.lang.String aEncodingType)
          Applies heuristics to detect the encoding of the specified byte buffer.
static java.lang.String guessRuleFileType(java.lang.String aFileName)
          Get the class name based on file extension.
static java.lang.String guessRuleFileType(java.lang.String aFileName, java.lang.String aFileExtension)
          Get the class name based on file extension.
static boolean hasUTF16BEByteOrderMark(byte[] aBytes)
          Indicates that the specified byte array is tagged with a UTF16BE byte order mark.
static boolean hasUTF16LEByteOrderMark(byte[] aBytes)
          Indicates that the specified byte array is tagged with a UTF16LE byte order mark.
static boolean hasUTF8ByteOrderMark(byte[] aBytes)
          Indicates that the specified byte array is tagged with a UTF8 byte order mark.
static java.lang.String mapVariantsToJava(java.lang.String aVariant)
          Map one of the UTF-8 or ISO-8859-1 variants to the java encoding name - ISO8859_1 or UTF8
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION

ENCODING_JAVA

public static final java.lang.String ENCODING_JAVA
encoding to use with Java files

See Also:
Constant Field Values

ENCODING_UPLOAD

public static final java.lang.String ENCODING_UPLOAD
encoding to use when uploading files (ex: Attach)

See Also:
Constant Field Values

ENCODING_DOWNLOAD

public static final java.lang.String ENCODING_DOWNLOAD
encoding to use when downloading files

See Also:
Constant Field Values

ENCODING_EXTRACT

public static final java.lang.String ENCODING_EXTRACT
encoding to use when extracting static content

See Also:
Constant Field Values

ENCODING_PLATFORM

public static final java.lang.String ENCODING_PLATFORM
platform's default encoding

See Also:
Constant Field Values

ENCODING_ISO

public static final java.lang.String ENCODING_ISO
use ISO-8859-1 encoding

See Also:
Constant Field Values

ENCODING_XML

public static final java.lang.String ENCODING_XML
encoding to use with XML files

See Also:
Constant Field Values

JAVA_ENCODING_ISO

public static final java.lang.String JAVA_ENCODING_ISO
Java encoding name for ISO

See Also:
Constant Field Values

JAVA_ENCODING_EBCDIC

public static final java.lang.String JAVA_ENCODING_EBCDIC
Java encoding name for EBCDIC

See Also:
Constant Field Values

JAVA_ENCODING_UTF8

public static final java.lang.String JAVA_ENCODING_UTF8
Java encoding name for UTF-8

See Also:
Constant Field Values

JAVA_ENCODING_UTF16LE

public static final java.lang.String JAVA_ENCODING_UTF16LE
Java encoding name for UTF-16 Little Endian

See Also:
Constant Field Values

JAVA_ENCODING_UTF16BE

public static final java.lang.String JAVA_ENCODING_UTF16BE
Java encoding name for UTF-16 Big Endian

See Also:
Constant Field Values

UTF8_BOM

public static final byte[] UTF8_BOM
The UTF-8 byte order mark

Constructor Detail

PRFileUtil

public PRFileUtil()
Method Detail

getJavaEncoding

public static java.lang.String getJavaEncoding(java.lang.String aEncodingType)
Returns the java encoding for the specified encoding type. Recognized encoding types are PRFileUtil.ENCODING_* values. Defaults to UTF-8 encoding is no encoding type is specified.

Parameters:
aEncodingType - the encoding type
Returns:
The Java encoding for the specified encoding type

hasUTF8ByteOrderMark

public static boolean hasUTF8ByteOrderMark(byte[] aBytes)
Indicates that the specified byte array is tagged with a UTF8 byte order mark. The three byte BOM for UTF-8 is EF BB BF

Parameters:
aBytes - a byte buffer
Returns:
true if the specified byte array has a UTF8 byte order mark

hasUTF16LEByteOrderMark

public static boolean hasUTF16LEByteOrderMark(byte[] aBytes)
Indicates that the specified byte array is tagged with a UTF16LE byte order mark. The two byte BOM for UTF-16LE is FF FE

Parameters:
aBytes - a byte buffer
Returns:
true if the specified byte array has a UTF16LE byte order mark

hasUTF16BEByteOrderMark

public static boolean hasUTF16BEByteOrderMark(byte[] aBytes)
Indicates that the specified byte array is tagged with a UTF16BE byte order mark. The two byte BOM for UTF-16BE is FE FF

Parameters:
aBytes - a byte buffer
Returns:
true if the specified byte array has a UTF16BE byte order mark

guessEncoding

public static java.lang.String guessEncoding(byte[] aBuffer,
                                             java.lang.String aEncodingType)
                                      throws java.io.IOException
Applies heuristics to detect the encoding of the specified byte buffer.

Parameters:
aBuffer - a byte buffer
aEncodingType -
Returns:
true if the specified byte array has a UTF16BE byte order mark
Throws:
java.io.IOException

getBytes

public static byte[] getBytes(java.io.InputStream aStream,
                              int aBufferSize)
                       throws java.io.IOException
Reads aBufferSize number of bytes from the specified InputStream.

Parameters:
aStream - The stream from which to read the bytes
aBufferSize - The number of bytes to read from the stream. If not specified, aStream.available() bytes are read.
Returns:
the byte buffer read from the InputStream
Throws:
java.io.IOException

mapVariantsToJava

public static java.lang.String mapVariantsToJava(java.lang.String aVariant)
Map one of the UTF-8 or ISO-8859-1 variants to the java encoding name - ISO8859_1 or UTF8

Parameters:
aVariant -
Returns:
encoding name

guessRuleFileType

public static java.lang.String guessRuleFileType(java.lang.String aFileName,
                                                 java.lang.String aFileExtension)
Get the class name based on file extension.

Parameters:
aFileExtension - extension of the file to be sent to the browser.
aFileName - name of the file without the extension part
Returns:
class type of the static resource if type is known else returns Rule-File-Binary.

guessRuleFileType

public static java.lang.String guessRuleFileType(java.lang.String aFileName)
Get the class name based on file extension.

Parameters:
aFileName - name of the file without the extension part
Returns:
class type of the static resource if type is known else returns Rule-File-Binary.


Copyright © 2012 Pegasystems Inc. All Rights Reserved.