Enum RpcPerforceFileType

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<RpcPerforceFileType>

    public enum RpcPerforceFileType
    extends java.lang.Enum<RpcPerforceFileType>
    Definitions for Perforce client and server file types.

    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.).

    • Method Detail

      • values

        public static RpcPerforceFileType[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (RpcPerforceFileType c : RpcPerforceFileType.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static RpcPerforceFileType valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • decodeFromServerString

        public static RpcPerforceFileType decodeFromServerString​(java.lang.String str)
        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​(java.io.File file,
                                                        int scanSize,
                                                        boolean isUnicodeServer,
                                                        java.nio.charset.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 - file
        scanSize - scanSize
        isUnicodeServer - isUnicodeServer
        clientCharset - clientCharset
        Returns:
        type
      • getServerFileTypeString

        public static RpcPerforceFileType.RpcServerTypeStringSpec getServerFileTypeString​(java.lang.String clientPath,
                                                                                          boolean overSize,
                                                                                          RpcPerforceFileType fileType,
                                                                                          java.lang.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 - clientPath
        overSize - overSize
        fileType - fileType
        forceType - forceType
        xlevel - xlevel
        Returns:
        RpcServerTypeStringSpec spec
      • isProbablySymLink

        public static boolean isProbablySymLink​(java.io.File file)
        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 - bytes
        bytesRead - bytesRead
        Returns:
        if known
      • getBinaryMagicNumberTable

        public static byte[][] getBinaryMagicNumberTable()