CompressionUtil { public static int isCompressible(@NotNull Artifact artifact) { if (SerializationType.GENERIC == artifact.getSerializationType()) { String contentType = artifact.getContentType(); if (contentType != null) { contentType = contentType.toLowerCase(); if (isCompressibleContentType(contentType)) { return 1; } if (isIncompressibleContentType(contentType)) { return -1; } } long contentLength = artifact.getContentLength(); if (contentLength > MIN_AUTO_DETECTION_LENGTH) { return seemsCompressible(artifact); } } return 0; }  static int isCompressible(@NotNull Artifact artifact); static final boolean ENV_SUPPORTS_COMPRESSION_LEVEL_CHANGE; }
@Test @Ignore("Because it does not always succeed due to usage of random bytes") public void testCompressibility() throws IOException, RepositoryException { byte[] comp256KB = compressibleData(256*1024); byte[] incomp256KB = incompressibleData(256*1024); assertTrue(isCompressible(newArtifact(comp256KB, COMPRESSIBLE_MIME_TYPE)) > 0); assertTrue(isCompressible(newArtifact(comp256KB, UNKNOWN_MIME_TYPE)) > 0); assertTrue(isCompressible(newArtifact(comp256KB, null)) > 0); assertTrue(isCompressible(newArtifact(new byte[10], null)) == 0); assertTrue(isCompressible(newArtifact(incomp256KB, UNKNOWN_MIME_TYPE)) < 0); assertTrue(isCompressible(newArtifact(incomp256KB, INCOMPRESSIBLE_MIME_TYPE)) < 0); }