01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.oscache.plugins.diskpersistence;
06:
07: /**
08: * Persist the cache data to disk.
09: *
10: * The code in this class is totally not thread safe it is the resonsibility
11: * of the cache using this persistence listener to handle the concurrency.
12: *
13: * @version $Revision: 254 $
14: * @author <a href="mailto:fbeauregard@pyxis-tech.com">Francois Beauregard</a>
15: * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
16: * @author <a href="mailto:chris@swebtec.com">Chris Miller</a>
17: */
18: public class DiskPersistenceListener extends
19: AbstractDiskPersistenceListener {
20: private static final String CHARS_TO_CONVERT = "./\\ :;\"\'_?";
21:
22: /**
23: * Build cache file name for the specified cache entry key.
24: *
25: * @param key Cache Entry Key.
26: * @return char[] file name.
27: */
28: protected char[] getCacheFileName(String key) {
29: if ((key == null) || (key.length() == 0)) {
30: throw new IllegalArgumentException("Invalid key '" + key
31: + "' specified to getCacheFile.");
32: }
33:
34: char[] chars = key.toCharArray();
35:
36: StringBuffer sb = new StringBuffer(chars.length + 8);
37:
38: for (int i = 0; i < chars.length; i++) {
39: char c = chars[i];
40: int pos = CHARS_TO_CONVERT.indexOf(c);
41:
42: if (pos >= 0) {
43: sb.append('_');
44: sb.append(i);
45: } else {
46: sb.append(c);
47: }
48: }
49:
50: char[] fileChars = new char[sb.length()];
51: sb.getChars(0, fileChars.length, fileChars, 0);
52: return fileChars;
53: }
54: }
|