/** * reads the content of a group of existing files in a zipped block * * @param domain The namespace used to identify the application domain (1st level directory) to * use * @param paths The paths relative to the domain for the files to be read * @param offset The offset in the file to start reading from * @param len The length of the block in bytes in zipped form * @return The contents of the file in zipped form together with the description of the files */ public MultiFileBlock readFromStreamZipped(String[] paths, long offset, int len) { MultiFileBlock block = null; try { if (_isLocal) { int startFileIndex = Util.getStartFileIndex( _rootFile.getCanonicalPath() + File.separatorChar, paths, offset); long startFileOffset = Util.getStartFileOffset( _rootFile.getCanonicalPath() + File.separatorChar, paths, offset); int i = startFileIndex; long j = startFileOffset; // int bufSize=0; int totalBufSize = 0; int readResult = 0; ByteArrayOutputStream bOut = new ByteArrayOutputStream(len); GZIPOutputStream zOut = new GZIPOutputStream(bOut, len); block = new MultiFileBlock(); while (totalBufSize < len && i < paths.length) { File tmpFile = new File(_rootFile.getCanonicalPath() + File.separatorChar + paths[i]); if (tmpFile.isFile() && tmpFile.exists()) { RandomAccessFile in = new RandomAccessFile(tmpFile, "r"); byte[] tmpBuf = new byte[len - totalBufSize]; in.seek(j); while (totalBufSize < len && in.getFilePointer() < in.length()) { readResult = in.read(tmpBuf); if (readResult != -1) { zOut.write(tmpBuf, 0, readResult); // bufSize = bOut.size(); totalBufSize += readResult; } else { break; } } BlockFileDescriptor des = new BlockFileDescriptor(_domain, paths[i], in.length()); block.addBlockFileDescriptor(des); in.close(); i++; j = 0; } else { return null; } } zOut.close(); block.setBlockData(bOut.toByteArray()); } else { block = _remote.readFromStreamZipped(_domain, paths, offset, len); } } catch (Exception ex) { ex.printStackTrace(); } return block; }