forked from apache/commons-jxpath
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Story #196234] [XPath] Export method for cache entries
- Loading branch information
Showing
4 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/org/apache/commons/jxpath/util/CacheExportUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.apache.commons.jxpath.util; | ||
|
||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
import java.util.logging.Logger; | ||
|
||
import org.apache.commons.jxpath.ri.compiler.Expression; | ||
|
||
|
||
/** | ||
* Utility class for exporting cache contents to a file. | ||
* | ||
*/ | ||
public class CacheExportUtil | ||
{ | ||
private static final Logger LOGGER = Logger.getLogger(CacheExportUtil.class.getName()); | ||
|
||
private static final String FILE_NAME = "xpath-cache-keys."; | ||
private static final String TEMP_DIR = System.getProperty("bisas.temp", "."); | ||
|
||
|
||
private CacheExportUtil() | ||
{ | ||
// utility class | ||
} | ||
|
||
|
||
public static void exportCacheKeys(Map<String, Expression> cache) | ||
{ | ||
if (cache == null) { | ||
return; | ||
} | ||
|
||
File file = new File(TEMP_DIR, FILE_NAME + System.currentTimeMillis()); | ||
|
||
try (PrintWriter out = new PrintWriter(new FileWriter(file))) { | ||
List<String> keysSnapshot = new CopyOnWriteArrayList<>(cache.keySet()); | ||
keysSnapshot.forEach(out::println); | ||
out.println("Size: " + keysSnapshot.size()); | ||
LOGGER.info("Exported cache keys to " + file.getAbsolutePath()); | ||
} | ||
catch (IOException ex) { | ||
throw new RuntimeException("Failed to export cache keys", ex); | ||
} | ||
} | ||
|
||
} |