com.microsoft.tfs.core.util
Class FileEncoding

java.lang.Object
  extended by com.microsoft.tfs.core.util.FileEncoding

public final class FileEncoding
extends java.lang.Object

Represents a text file encoding as expected to be used by TFS, which can be represented solely by a "code page" integer (normal code page numbers with a few TFS-specific numbers reserved for binary files, etc.). These instances are light-weight.

A FileEncoding is equal to (equals(Object)) another FileEncoding if and only if its code page number matches.

Since:
TEE-SDK-10.1
Thread-safety:
immutable

Field Summary
protected static int AUTO_DETECT_SPECIAL_VALUE
           
static FileEncoding AUTOMATICALLY_DETECT
          The file described by this encoding object should have its encoding detected some time in the future and thereafter this value be ignored.
static FileEncoding BINARY
          This will be treated as a byte stream, and not interpreted as text.
static FileEncoding DEFAULT_TEXT
          The file described by this encoding object should have its encoding detected to be the default text encoding for this platform some time in the future and thereafter this value be ignored.
static java.lang.String ENCODING_ERROR_MESSAGE_FORMAT
           
protected static int TEXT_SPECIAL_VALUE
           
static FileEncoding UTF_16
          UTF-16, little-endian (the Windows convention for non-endian-explicit names, which is the opposite of Java; see the note in CodePageMapping).
static FileEncoding UTF_16BE
          UTF-16, big-endian.
static FileEncoding UTF_32
          UTF-32, little-endian (the Windows convention for non-endian-explicit names, which is the opposite of Java; see the note in CodePageMapping).
static FileEncoding UTF_32BE
          UTF-32, big-endian.
static FileEncoding UTF_8
          UTF-8.
 
Constructor Summary
FileEncoding(int codePage)
          Construct a file encoding that represents the given code page.
 
Method Summary
 boolean equals(java.lang.Object obj)
          
 int getCodePage()
          Gets the code page number that corresponds to this FileEncoding instance.
static FileEncoding getDefaultTextEncoding()
          Gets the default text encoding for this platform, usually so we can assume newly found files are this encoding if they're not marked by BOM.
 java.lang.String getName()
          Gets a pretty name to display to the user for this encoding.
 java.lang.String getName(java.util.Locale locale)
          Gets a pretty name to display to the user for this encoding.
 int hashCode()
          
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

AUTO_DETECT_SPECIAL_VALUE

protected static final int AUTO_DETECT_SPECIAL_VALUE
Constant Field Value:
-9999
See Also:
Constant Field Values

TEXT_SPECIAL_VALUE

protected static final int TEXT_SPECIAL_VALUE
Constant Field Value:
-9998
See Also:
Constant Field Values

ENCODING_ERROR_MESSAGE_FORMAT

public static final java.lang.String ENCODING_ERROR_MESSAGE_FORMAT

BINARY

public static final FileEncoding BINARY
This will be treated as a byte stream, and not interpreted as text.


AUTOMATICALLY_DETECT

public static final FileEncoding AUTOMATICALLY_DETECT
The file described by this encoding object should have its encoding detected some time in the future and thereafter this value be ignored. getCodePage() is not valid for this type.


DEFAULT_TEXT

public static final FileEncoding DEFAULT_TEXT
The file described by this encoding object should have its encoding detected to be the default text encoding for this platform some time in the future and thereafter this value be ignored. getCodePage() is not valid for this type.


UTF_8

public static final FileEncoding UTF_8
UTF-8.


UTF_16

public static final FileEncoding UTF_16
UTF-16, little-endian (the Windows convention for non-endian-explicit names, which is the opposite of Java; see the note in CodePageMapping).


UTF_16BE

public static final FileEncoding UTF_16BE
UTF-16, big-endian.


UTF_32

public static final FileEncoding UTF_32
UTF-32, little-endian (the Windows convention for non-endian-explicit names, which is the opposite of Java; see the note in CodePageMapping).


UTF_32BE

public static final FileEncoding UTF_32BE
UTF-32, big-endian.

Constructor Detail

FileEncoding

public FileEncoding(int codePage)
Construct a file encoding that represents the given code page.

Parameters:
codePage - the code page this encoding represents.
Method Detail

getDefaultTextEncoding

public static FileEncoding getDefaultTextEncoding()
Gets the default text encoding for this platform, usually so we can assume newly found files are this encoding if they're not marked by BOM.

Returns:
the default text encoding for this platform.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getCodePage

public int getCodePage()
Gets the code page number that corresponds to this FileEncoding instance. The code page returned will be a valid code page OR one of the special numbers reserved for the TFS protocol for binary, unchanged, auto, etc. files.

Returns:
the code page number that matches this class's encoding, or one of the TFS special code page numbers.

getName

public java.lang.String getName()
Gets a pretty name to display to the user for this encoding. If no name for the encoding can be found, the encoding's code page will simply be returned as a string.

Returns:
the fancy string name of the given encoding (e.g. "utf-8"), or simply the code page number formatted as string if the name was not found (e.g. "1253").

getName

public java.lang.String getName(java.util.Locale locale)
Gets a pretty name to display to the user for this encoding. If no name for the encoding can be found, the encoding's code page will simply be returned as a string.

Parameters:
locale - the locale to use when finding localized encoding names (not null).
Returns:
the fancy string name of the given encoding (e.g. "utf-8"), or simply the code page number formatted as string if the name was not found (e.g. "1253").

equals

public boolean equals(java.lang.Object obj)

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object


© 2015 Microsoft. All rights reserved.