/** * 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 offset the offset from the beginning of the file. * @param len The length of the block in bytes * @return The contents of the file */ public byte[] readByteFromFile(String path, long offset, int len) throws EOFException, FileAccessException { try { if (_isLocal) { File tmpFile = new File(_rootFile.getCanonicalPath() + File.separatorChar + path); if (tmpFile.isFile()) { RandomAccessFile raf = new RandomAccessFile(tmpFile, "r"); byte[] buffer = new byte[len]; raf.seek(offset); int totalByteRead = 0; ByteArrayOutputStream out = new ByteArrayOutputStream(); int result = 0; while (totalByteRead < len && raf.getFilePointer() < raf.length()) { result = raf.read(buffer, 0, (len - totalByteRead)); if (result != -1) { out.write(buffer, 0, result); totalByteRead += result; } else if (totalByteRead == 0) throw new EOFException("End of file reached!"); else break; } raf.close(); out.flush(); out.close(); return out.toByteArray(); } else throw new FileAccessException("Path is not a file"); } else return _remote.readByteFromFile(_domain, path, offset, len); } catch (EOFException eofe) { throw eofe; } catch (FileAccessException fae) { throw fae; } catch (Exception e) { throw new FileAccessException(e); } }