Java tutorial
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.io.InputStream; public class Main { private static final int PART_SIZE = 20 * 1024; private static byte[] readBiggerStream(final InputStream in, final long streamlength) throws IOException { byte[] bytes = new byte[PART_SIZE * 3]; int readed = -1; int patchsize = -1; long skiped = -1; long patchskip = -1; long pointpos = 0; readed = in.read(bytes, 0, PART_SIZE); patchsize = readed; while (patchsize > 0 && readed != PART_SIZE) { patchsize = in.read(bytes, readed, PART_SIZE - readed); if (patchsize > 0) { readed += patchsize; } } pointpos = streamlength / 3 - PART_SIZE; skiped = in.skip(pointpos); patchskip = skiped; while (patchskip > 0 && skiped != pointpos) { patchskip = in.skip(pointpos - skiped); if (patchskip > 0) { skiped += patchskip; } } readed = in.read(bytes, PART_SIZE, PART_SIZE); patchsize = readed; while (patchsize > 0 && readed != PART_SIZE) { patchsize = in.read(bytes, PART_SIZE + readed, PART_SIZE - readed); if (patchsize > 0) { readed += patchsize; } } pointpos = streamlength - streamlength / 3 - PART_SIZE * 2; skiped = in.skip(pointpos); patchskip = skiped; while (patchskip > 0 && skiped != pointpos) { patchskip = in.skip(pointpos - skiped); if (patchskip > 0) { skiped += patchskip; } } readed = in.read(bytes, PART_SIZE * 2, PART_SIZE); patchsize = readed; while (patchsize > 0 && readed != PART_SIZE) { patchsize = in.read(bytes, PART_SIZE * 2 + readed, PART_SIZE - readed); if (patchsize > 0) { readed += patchsize; } } return bytes; } }