@@ -0,0 +1,1643 @@
+package br.ufrj.cos.redes.fileAccess;%0A%0Aimport java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Apublic class RandomFileChunkRetrieverExample %7B%0A%09public static void main(String%5B%5D args) throws IOException %7B%0A%09%09String readFilePath            = %22C:%5C%5CUsers%5C%5CJoao&Duda%5C%5CDesktop%5C%5CJP%5C%5C2015-1%5C%5Credes%5C%5Cmac.pdf%22;%0A%09%09String randomWriteFilePath     = %22C:%5C%5CUsers%5C%5CJoao&Duda%5C%5CDesktop%5C%5CJP%5C%5C2015-1%5C%5Credes%5C%5Cmac2.pdf%22;%0A%09%09String sequencialWriteFilePath = %22C:%5C%5CUsers%5C%5CJoao&Duda%5C%5CDesktop%5C%5CJP%5C%5C2015-1%5C%5Credes%5C%5Cmac3.pdf%22;%0A%09%09%0A%09%09FileOutputStream rostream = new FileOutputStream(randomWriteFilePath);%0A%09%09FileOutputStream sostream = new FileOutputStream(sequencialWriteFilePath);%0A%09%09%0A%09%09long chunkLength = 160;%0A%09%09FileChunkRetriever chunkReceiver = new RandomFileChunkRetriever(new File(readFilePath), chunkLength);%0A%09%09List%3CChunk%3E chunks = new ArrayList%3CChunk%3E();%0A%09%09%0A%09%09while (chunkReceiver.hasNext()) %7B%0A%09%09%09Chunk chunk = new Chunk((int)chunkLength);%0A%09%09%09if (chunkReceiver.getNextChunk(chunk)) %7B%0A%09%09%09%09if (chunk.getActualChunkLength() == chunk.getBytes().length) %7B%0A%09%09%09%09%09rostream.write(chunk.getBytes());%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09rostream.write(chunk.getBytes(), 0, chunk.getActualChunkLength());%0A%09%09%09%09%7D%0A%09%09%09%09%0A%09%09%09%09chunks.add(chunk);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09Collections.sort(chunks);%0A%09%09for (Chunk chunk : chunks) %7B%0A%09%09%09if (chunk.getActualChunkLength() == chunk.getBytes().length) %7B%0A%09%09%09%09sostream.write(chunk.getBytes());%0A%09%09%09%7D else %7B%0A%09%09%09%09sostream.write(chunk.getBytes(), 0, chunk.getActualChunkLength());%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09rostream.flush();%0A%09%09rostream.close();%0A%09%09sostream.flush();%0A%09%09sostream.close();%0A%09%7D%0A%7D%0A

add RandomFileChunkRetrieverExample class