Enum Class RpcPerforceFileType
- All Implemented Interfaces:
Serializable,Comparable<RpcPerforceFileType>,Constable
Perforce defines a surprising variety of basic file types and associated modifiers that determine things like how to send and receive file contents between the client and the server (UTF-8 vs UTF-16, compressed binary vs. uncompressed binary, plain old "text", etc.) and how to interpret file metadata. These types and the associated panoply of methods, etc., are mostly used in the clientCheckFile, clientOpen, clientClose, clientWrite, etc. methods on the various client function classes.
A file's type is stored in the server for all known files, (see e.g. "p4 help typemap" and "p4 help filetypes"), and in most cases we simply accept what we're given if we can cope with that type (there are some types we don't process at all here -- see below). What sort of file types a server (as opposed to the client) knows about and can process depends on the server's xlevel protocol variable:
- xfiles unset: return text, binary.
- xfiles >= 0: also return xtext, xbinary.
- xfiles >= 1: also return symlink.
- xfiles >= 2; also return resource (mac resource file).
- xfiles >= 3; also return ubinary
- xfiles >= 4; also return apple
In general, the client has to honour the server's xlevel
capabilities, so the client may have to do a bit of work
to get things right here.
Unfortunately, in some cases it's very difficult to know what Perforce type a file should be, and there's a bunch of digging around that must be done to intuit the proper type for files the server doesn't (yet) know about.
Also somewhat unfortunately, the file type is encoded quite differently depending on whether it's coming from the server (usually encoded as a string representation of hex numbers) or going to the server (where it's usually done as plain old "text" or "ubinary", etc.).
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescription -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic RpcPerforceFileTypeDecode the file type from the string sent by the server.static byte[][]getServerFileTypeString(String clientPath, boolean overSize, RpcPerforceFileType fileType, String forceType, int xlevel) Given a Perforce file type and the Perforce server's xfiles level (from the protocol parameters), determine what server file type to send to the server to represent the passed-in file type as a string, and / or what error or info message to send to the user.static RpcPerforceFileTypeinferFileType(File file, int scanSize, boolean isUnicodeServer, Charset clientCharset) Infer (or even intuit) the Perforce file type of the passed-in Perforce file.booleanChecking for compressed file types - excluding "forbidden" types.booleanChecking for executable file types - excluding "forbidden" types.static booleanisKnownCBinary(byte[] bytes, int bytesRead) Return true iff the file appears to start with some known magic numbers that we interpret to mean the file is pre-compressed binary (FST_CBINARY).static booleanisProbablySymLink(File file) Return true if there's some reason to believe this file is a Unix or Linux symbolic link.static RpcPerforceFileTypeReturns the enum constant of this class with the specified name.static RpcPerforceFileType[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
FST_TEXT
-
FST_BINARY
-
FST_GZIP
-
FST_DIRECTORY
-
FST_SYMLINK
-
FST_RESOURCE
-
FST_SPECIAL
-
FST_MISSING
-
FST_CANTTELL
-
FST_EMPTY
-
FST_UNICODE
-
FST_GUNZIP
-
FST_UTF8
-
FST_UTF16
-
FST_TEXT_GUNZIP
-
FST_BINARY_GUNZIP
-
FST_XTEXT_GUNZIP
-
FST_XBINARY_GUNZIP
-
FST_SYMLINK_GUNZIP
-
FST_RESOURCE_GUNZIP
-
FST_XSYMLINK_GUNZIP
-
FST_XRESOURCE_GUNZIP
-
FST_UNICODE_GUNZIP
-
FST_RTEXT_GUNZIP
-
FST_XUNICODE_GUNZIP
-
FST_XRTEXT_GUNZIP
-
FST_APPLETEXT_GUNZIP
-
FST_APPLEFILE_GUNZIP
-
FST_XAPPLETEXT_GUNZIP
-
FST_XAPPLEFILE_GUNZIP
-
FST_UTF8_GUNZIP
-
FST_XUTF8_GUNZIP
-
FST_UTF16_GUNZIP
-
FST_XUTF16_GUNZIP
-
FST_ATEXT
-
FST_XTEXT
-
FST_RTEXT
-
FST_RXTEXT
-
FST_CBINARY
-
FST_XBINARY
-
FST_XSYMLINK
-
FST_XRESOURCE
-
FST_APPLETEXT
-
FST_APPLEFILE
-
FST_XAPPLEFILE
-
FST_XAPPLETEXT
-
FST_XUNICODE
-
FST_XRTEXT
-
FST_XUTF8
-
FST_XUTF16
-
FST_XGUNZIP
-
FST_RCS
-
-
Field Details
-
TRACE_PREFIX
- See Also:
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
decodeFromServerString
Decode the file type from the string sent by the server. This is (usually) a three-character hex encoding, e.g. "101" or "01D".- Parameters:
str- string- Returns:
- type
-
isExecutable
public boolean isExecutable()Checking for executable file types - excluding "forbidden" types.- Returns:
- true, if known type
-
isCompressed
public boolean isCompressed()Checking for compressed file types - excluding "forbidden" types.- Returns:
- true, if known type
-
inferFileType
public static RpcPerforceFileType inferFileType(File file, int scanSize, boolean isUnicodeServer, Charset clientCharset) Infer (or even intuit) the Perforce file type of the passed-in Perforce file. This is an arbitrarily complex operation, and may involve reading in the first few bytes of a file to see what the contents say about the type.Note that Java does not allow us to directly access most file metadata. This probably doesn't matter in most cases, but we do need to keep an eye on this -- HR.
- Parameters:
file- filescanSize- scanSizeisUnicodeServer- isUnicodeServerclientCharset- clientCharset- Returns:
- type
-
getServerFileTypeString
public static RpcPerforceFileType.RpcServerTypeStringSpec getServerFileTypeString(String clientPath, boolean overSize, RpcPerforceFileType fileType, String forceType, int xlevel) Given a Perforce file type and the Perforce server's xfiles level (from the protocol parameters), determine what server file type to send to the server to represent the passed-in file type as a string, and / or what error or info message to send to the user.- Parameters:
clientPath- clientPathoverSize- overSizefileType- fileTypeforceType- forceTypexlevel- xlevel- Returns:
- RpcServerTypeStringSpec spec
-
isProbablySymLink
Return true if there's some reason to believe this file is a Unix or Linux symbolic link. This is just a hack that's here until I can do something better with native code...- Parameters:
file- file- Returns:
- true, if symlink
-
isKnownCBinary
public static boolean isKnownCBinary(byte[] bytes, int bytesRead) Return true iff the file appears to start with some known magic numbers that we interpret to mean the file is pre-compressed binary (FST_CBINARY). Typically things like JPEGs and GIFs, etc.- Parameters:
bytes- bytesbytesRead- bytesRead- Returns:
- if known
-
getBinaryMagicNumberTable
public static byte[][] getBinaryMagicNumberTable()
-