class MessageArchive implements AutoCloseable {

	void save(byte[] message, long timestamp) throws Exception {
		if (indexFile == null)
			openFiles(timestamp);
		
		if ((message.length + dataFile.length()) >= (MAXIMUM_ARCHIVE_SIZE_MB * 1_000_000)) {
			close();
			openFiles(timestamp);
		}
		indexFile.seek(indexFile.length());
		dataFile.seek(dataFile.length());
		long dataPos = dataFile.getFilePointer();
		try {
			indexFile.write(message, 0, HEADER_SIZE);
			indexFile.writeLong(dataPos);
			dataFile.write(message, HEADER_SIZE, message.length - HEADER_SIZE);
		} catch(Exception e) {
			LoggingService.logError(MODULE_NAME, "Error saving archive",
					new AgentSystemException(e.getMessage(), e));
		}
	}

	public  MessageArchive(String name);

}