Java examples for java.lang:byte Array Compress
uncompress unzip byte array
/**************************************************************************** * Copyright (c) 2007 Composent, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w ww .j ava2 s . co m*/ * Composent, Inc. - initial API and implementation *****************************************************************************/ //package com.java2s; import java.io.*; import java.util.zip.*; public class Main { public static void main(String[] argv) throws Exception { byte[] source = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(java.util.Arrays.toString(uncompress(source))); } public static byte[] uncompress(byte[] source) { final ZipInputStream ins = new ZipInputStream( new ByteArrayInputStream(source)); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); int read = 0; final byte[] buf = new byte[16192]; try { ins.getNextEntry(); while ((read = ins.read(buf)) > 0) { bos.write(buf, 0, read); } bos.flush(); ins.close(); } catch (final IOException e) { // Should not happen } return bos.toByteArray(); } }