Raph Levien | dcecdd8 | 2012-03-23 11:21:16 -0700 | [diff] [blame^] | 1 | // Copyright 2011 Google Inc. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | package com.google.typography.font.compression; |
| 6 | |
| 7 | import java.io.ByteArrayOutputStream; |
| 8 | import java.io.IOException; |
| 9 | import java.util.zip.Deflater; |
| 10 | import java.util.zip.DeflaterOutputStream; |
| 11 | |
| 12 | /** |
| 13 | * Simple utility for GZIP compression |
| 14 | */ |
| 15 | public class GzipUtil { |
| 16 | public static byte[] deflate(byte[] bytes) { |
| 17 | try { |
| 18 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 19 | DeflaterOutputStream dos = new DeflaterOutputStream(baos, new Deflater()); |
| 20 | dos.write(bytes, 0, bytes.length); |
| 21 | dos.close(); |
| 22 | return baos.toByteArray(); |
| 23 | } catch (IOException e) { |
| 24 | throw new RuntimeException(e); |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |