Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.concurrent.ConcurrentLinkedQueue; public class Main { private static byte[] mergeBytes(byte[] in, ConcurrentLinkedQueue<byte[]> decompressUnfinishedDataQueue) { if (!decompressUnfinishedDataQueue.isEmpty()) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { while (!decompressUnfinishedDataQueue.isEmpty()) { out.write(decompressUnfinishedDataQueue.poll()); } out.write(in); in = out.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } finally { try { out.close(); } catch (IOException e) { } } } return in; } }