Java Code Examples for java.util.zip.Deflater#NO_COMPRESSION
The following examples show how to use
java.util.zip.Deflater#NO_COMPRESSION .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WriteFxImageBenchmark.java From chart-fx with Apache License 2.0 | 6 votes |
public static void testCompressionPerformance(final Image image, final String description) { LOGGER.atInfo().addArgument(description).log("Test compression level performance with image with {}"); // precompute typical palette final PaletteQuantizer userPaletteRGBA = WriteFxImage.estimatePalette(image, true, DEFAULT_PALETTE_COLOR_COUNT); final PaletteQuantizer userPaletteRGB = WriteFxImage.estimatePalette(image, false, DEFAULT_PALETTE_COLOR_COUNT); for (final boolean alpha : new boolean[] { true, false }) { LOGGER.atInfo().addArgument(alpha ? "with" : "without").log("{} alpha channel"); for (int compressionLevel = Deflater.NO_COMPRESSION; compressionLevel <= Deflater.BEST_COMPRESSION; compressionLevel++) { writeFxImage(image, alpha, true, compressionLevel, OLDREF); writeFxImage(image, alpha, true, compressionLevel, NEWREF); // compute palette on-the-fly writeFxImage(image, alpha, true, compressionLevel, PALETTE); // use pre-computed palette writeFxImage(image, alpha, true, compressionLevel, PALETTE, alpha ? userPaletteRGBA : userPaletteRGB); LOGGER.atInfo().log(" "); // deliberatly empty line for better readability } } }
Example 2
Source File: PressUtility.java From jstarcraft-core with Apache License 2.0 | 6 votes |
/** * 按照指定的级别压缩指定的数据 * * @param datas * @param level * @return */ public static byte[] zip(byte[] datas, int level) { if (level < Deflater.NO_COMPRESSION || level > Deflater.BEST_COMPRESSION) { String message = StringUtility.format("非法的压缩等级[{}]", level); LOGGER.error(message); throw new IllegalArgumentException(message); } Deflater deflater = new Deflater(level); deflater.setInput(datas); deflater.finish(); try (ByteArrayOutputStream stream = new ByteArrayOutputStream(BUFFER_SIZE)) { byte[] bytes = new byte[BUFFER_SIZE]; while (!deflater.finished()) { int count = deflater.deflate(bytes); stream.write(bytes, 0, count); } deflater.end(); return stream.toByteArray(); } catch (IOException exception) { throw new IllegalStateException("压缩异常", exception); } }
Example 3
Source File: WriteFxImageTests.java From chart-fx with Apache License 2.0 | 5 votes |
private static Stream<Arguments> testWritingImageByteBufferProvider() { // NOPMD -- is used in annotation /not detected by PMD List<Arguments> argumentList = new ArrayList<>(); // N.B. limit to some selected sub-cases and not test all (full parameter space takes too much time for regular CI/CD checks for (int testImageID : new int[] { 0, 1, 2 }) { for (boolean encodeRGBA : new boolean[] { true, false }) { argumentList.add(Arguments.arguments(testImageID, true, encodeRGBA, Deflater.NO_COMPRESSION, FilterType.FILTER_NONE)); } for (boolean allocateNewBuffer : new boolean[] { true, false }) { argumentList.add(Arguments.arguments(testImageID, allocateNewBuffer, true, Deflater.NO_COMPRESSION, FilterType.FILTER_NONE)); } // loop through compression levels for (int compressionLevel : new int[] { Deflater.NO_COMPRESSION, Deflater.BEST_SPEED, Deflater.BEST_COMPRESSION }) { argumentList.add(Arguments.arguments(testImageID, true, true, compressionLevel, FilterType.FILTER_NONE)); } // loop through PNG line filter settings for (FilterType filterType : new FilterType[] { FilterType.FILTER_NONE, FilterType.FILTER_PAETH }) { if (!FilterType.isValidStandard(filterType)) { continue; } argumentList.add(Arguments.arguments(testImageID, true, true, Deflater.NO_COMPRESSION, filterType)); } } //return Stream.of("apple", "banana"); return Stream.of(argumentList.toArray(new Arguments[0])); }
Example 4
Source File: ZipFileObject.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
private int getZipCompressionLevel(FuzzyCompressionLevel compressionLevel) { switch (compressionLevel) { case BEST: return Deflater.BEST_COMPRESSION; case FASTEST: return Deflater.BEST_SPEED; case NONE: return Deflater.NO_COMPRESSION; case DEFAULT: default: return Deflater.DEFAULT_COMPRESSION; } }
Example 5
Source File: ZipEntryOutputStream.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 4 votes |
public void close() throws IOException { if ( closed ) { // A duplicate close is just a NO-OP as with all other output streams. return; } deflaterOutputStream.close(); deflater.finish(); deflater.end(); final byte[] data = outputStream.toByteArray(); final ByteArrayInputStream bin = new ByteArrayInputStream( data ); final InflaterInputStream infi = new InflaterInputStream( bin ); final ZipRepository repository = (ZipRepository) item.getRepository(); final String contentId = (String) item.getContentId(); final ZipEntry zipEntry = new ZipEntry( contentId ); final Object comment = item.getAttribute( LibRepositoryBoot.ZIP_DOMAIN, LibRepositoryBoot.ZIP_COMMENT_ATTRIBUTE ); if ( comment != null ) { zipEntry.setComment( String.valueOf( comment ) ); } final Object version = item.getAttribute( LibRepositoryBoot.REPOSITORY_DOMAIN, LibRepositoryBoot.VERSION_ATTRIBUTE ); if ( version instanceof Date ) { final Date date = (Date) version; zipEntry.setTime( date.getTime() ); } final int zipMethod = RepositoryUtilities.getZipMethod( item ); zipEntry.setCrc( crc32.getValue() ); if ( zipMethod == Deflater.NO_COMPRESSION ) { zipEntry.setCompressedSize( size ); zipEntry.setSize( size ); } else { zipEntry.setSize( size ); } repository.writeContent( zipEntry, infi, zipMethod, RepositoryUtilities.getZipLevel( item ) ); infi.close(); closed = true; outputStream = null; deflaterOutputStream = null; }