/** * @see org.dihedron.patterns.cache.Storage#clear() */ @Override public void clear() { logger.debug("clearing storage"); for(String resource : contents.keySet()) { Streams.safelyClose(contents.get(resource)); } contents.clear(); } }
/** * @see org.dihedron.patterns.cache.Storage#delete(org.dihedron.core.regex.Regex) */ @Override public void delete(Regex regex) { Set<String> resources = new HashSet<String>(contents.keySet()); for (String resource : resources) { if(regex.matches(resource)){ logger.debug("removing resource '{}'", resource); Streams.safelyClose(contents.get(resource)); contents.remove(resource); } } }
/** * @see org.dihedron.patterns.cache.Storage#delete(java.lang.String, boolean) */ @Override public void delete(String resource, boolean caseSensitive) { Set<String> resources = new HashSet<String>(contents.keySet()); for (String string : resources) { if(caseSensitive && string.equals(resource)) { logger.debug("removing resource '{}'", resource); Streams.safelyClose(contents.get(resource)); contents.remove(resource); } else if(!caseSensitive && string.equalsIgnoreCase(resource)){ logger.debug("removing resource '{}'", resource); Streams.safelyClose(contents.get(resource)); contents.remove(resource); } else { logger.trace("keeping resource '{}'", resource); } } }
/** * @see org.dihedron.patterns.cache.Storage#store(java.lang.String, java.io.InputStream) */ @Override public OutputStream store(String resource) throws CacheException { if(Strings.isValid(resource)) { Streams.safelyClose(contents.get(resource)); logger.debug("storing resource '{}'", resource); CacheOutputStream<ByteArrayOutputStream> stream = new CacheOutputStream<ByteArrayOutputStream>(new ByteArrayOutputStream()); contents.put(resource, stream); return stream; } return null; }
throw new CacheException("error copying data from cache to byte array", e); } finally { Streams.safelyClose(input); Streams.safelyClose(output);
throw new CacheException("error copying data from byte array to cache", e); } finally { Streams.safelyClose(input); Streams.safelyClose(output);