001/*
002 *  Copyright (c) 2012, 2013, Credit Suisse (Anatole Tresch), Werner Keil.
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.javamoney.moneta.loader.internal;
017
018import java.io.IOException;
019
020/**
021 * Abstraction of a {@link ResourceCache}. By default a file cache is used:
022 * {@link DefaultResourceCache}.
023 * 
024 * @author Anatole Tresch
025 */
026public interface ResourceCache {
027        /**
028         * Write the given byte array to the internal store and register it on the
029         * given resource ID.
030         * 
031         * @param resourceId
032         *            the resource id, never {@code null}.
033         * @param data
034         *            the data
035         * @throws IOException
036         *             when an IO error occurs.
037         */
038        public void write(String resourceId, byte[] data) throws IOException;
039
040        /**
041         * Allows to query if a resource with the given id is present within the
042         * local cache.
043         * 
044         * @param resourceId
045         *            The resourceId
046         * @return true, if the resource was found in the local cache.
047         */
048        public boolean isCached(String resourceId);
049
050        /**
051         * Reads the given resource, identified by the resourceId, from the cache.
052         * 
053         * @param resourceId
054         *            the resource id.
055         * @return the data of the resource.
056         * @throws IllegalArgumentException
057         *             if no such resource is existing.
058         */
059        public byte[] read(String resourceId);
060
061}