/** * reads the content of an existing file using the current domain * * @param domain The namespace used to identify the application domain (1st level directory) to * use * @param path The path relative to the domain for the file * @param block The sequential block number for the data to be read starting with 1 * @param len The length of the block in bytes * @return The contents of the file */ public byte[] readFromFile(String path, int block, int len) { byte[] buffer = null; try { if (_isLocal) { File tmpFile = new File(_rootFile.getCanonicalPath() + File.separatorChar + path); if (tmpFile.isFile()) { RandomAccessFile in = new RandomAccessFile(tmpFile, "r"); in.seek((block - 1) * len); int result = -1; buffer = new byte[len]; if (in.getFilePointer() < in.length()) { result = in.read(buffer); ByteArrayOutputStream out = new ByteArrayOutputStream(result); out.write(buffer, 0, result); in.close(); return out.toByteArray(); } else { in.close(); } } } else { buffer = _remote.readFromFile(_domain, path, block, len); } } catch (Exception ex) { ex.printStackTrace(); } return buffer; }