|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DiskPersistenceListener.java | 83.3% | 92.9% | 100% | 90.5% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Copyright (c) 2002-2003 by OpenSymphony
|
|
| 3 |
* All rights reserved.
|
|
| 4 |
*/
|
|
| 5 |
package com.opensymphony.oscache.plugins.diskpersistence;
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
/**
|
|
| 9 |
* Persist the cache data to disk.
|
|
| 10 |
*
|
|
| 11 |
* The code in this class is totally not thread safe it is the resonsibility
|
|
| 12 |
* of the cache using this persistence listener to handle the concurrency.
|
|
| 13 |
*
|
|
| 14 |
* @version $Revision: 1.5.2.2 $
|
|
| 15 |
* @author <a href="mailto:fbeauregard@pyxis-tech.com">Francois Beauregard</a>
|
|
| 16 |
* @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
|
|
| 17 |
* @author <a href="mailto:chris@swebtec.com">Chris Miller</a>
|
|
| 18 |
*/
|
|
| 19 |
public class DiskPersistenceListener extends 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 | 651 |
protected char[] getCacheFileName(String key) { |
| 29 | 650 |
if ((key == null) || (key.length() == 0)) { |
| 30 | 0 |
throw new IllegalArgumentException("Invalid key '" + key + "' specified to getCacheFile."); |
| 31 |
} |
|
| 32 |
|
|
| 33 | 650 |
char[] chars = key.toCharArray();
|
| 34 |
|
|
| 35 | 646 |
StringBuffer sb = new StringBuffer(chars.length + 8);
|
| 36 |
|
|
| 37 | 646 |
for (int i = 0; i < chars.length; i++) { |
| 38 | 9556 |
char c = chars[i];
|
| 39 | 9565 |
int pos = CHARS_TO_CONVERT.indexOf(c);
|
| 40 |
|
|
| 41 | 9561 |
if (pos >= 0) {
|
| 42 | 1140 |
sb.append('_');
|
| 43 | 1140 |
sb.append(i); |
| 44 |
} else {
|
|
| 45 | 8414 |
sb.append(c); |
| 46 |
} |
|
| 47 |
} |
|
| 48 |
|
|
| 49 | 653 |
char[] fileChars = new char[sb.length()]; |
| 50 | 653 |
sb.getChars(0, fileChars.length, fileChars, 0); |
| 51 | 653 |
return fileChars;
|
| 52 |
} |
|
| 53 |
} |
|
| 54 |
|
|
||||||||||