class CompressionUtil {

    public static int isCompressible(@NotNull Artifact artifact) {

        if (SerializationType.GENERIC == artifact.getSerializationType()) {

            /*
             * Test for known content types
             */
            String contentType = artifact.getContentType();
            if (contentType != null) {
                contentType = contentType.toLowerCase();
                if (isCompressibleContentType(contentType)) {
                    return 1;
                }
                if (isIncompressibleContentType(contentType)) {
                    return -1;
                }
            }

            /*
             * Apply compressibility prediction heuristic on a sample of the artifact
             *
             * The heuristic is tested only if the expected cost of running the heuristic
             * is smaller than 3% of the expected cost of compressing the artifact, such
             * that the extra cost is reasonable in the worst case.
             *
             *
             * The compression throughput is assumed to be 80 MB/s or less.
             * The cost of peeking a sample and running the heuristic is expected to be 150μs or less.
             *
             * The artifact size threshold is thus set to 115KB.
             *
             * A better improved implementation may measure those values and self tune for a
             * specific runtime.
             */
            long contentLength = artifact.getContentLength();
            if (contentLength > MIN_AUTO_DETECTION_LENGTH) {
                return seemsCompressible(artifact);
            }
        }
        return 0;
    }

}